ARM: GNU assembler error

Hello

I've written a simple assembler macro and use it as follows:

#include

.macro WRITE_REG addr, val, reg0, reg1 ldr \reg0, =\addr /* store the address */ ldr \reg1, =\val /* store value */ str \reg1, [\reg0] /* write the value */ .endm .... WRITE_REG (MM3001_SMC_BASE + MM3001_SMC_SMBWST1R7), 0x0000001F, r0, r1 ... where MM3001_SMC_BASE and MM3001_SMC_SMBWST1R7 are defined in my_defs.h

My toolchain is ELDK-4.1 taken from

formatting link
based on gcc-4.0.0, options I used to build this seem to be normal and sane:

-fno-strict-aliasing -fno-common -ffixed-r8 -msoft-float -fno-builtin

-ffreestanding -nostdinc -pipe -mabi=apcs-gnu -march=armv5te -O0 -mbig-endian -ggdb

-mtune=arm926ej-s

Unluckily, it results in error:

Error: constant expression expected -- `ldr r0,=(MM3001_SMC_BASE+MM3001_SMC_SMBWST1R7)'

What might be the problem with the macro? Thanks.

-- Mark

Reply to
Mark
Loading thread data ...

I don't know much about GNU assembler syntax, but why not using C for writing registers? Usually you have different hardware blocks, which can be described in a structure. A simplified example for an UART:

typedef volatile unsigned long vu32;

typedef struct { vu32 dataOut; vu32 dataIn; vu32 baudRate; vu32 status; } UartType;

Now we can define two UART blocks just like this:

#define PERIPH_BASE ((u32)0x40000000) #define UART0_BASE (PERIPH_BASE + 0x1200) #define UART1_BASE (PERIPH_BASE + 0x1300)

#define UART0 ((UartType *) UART0_BASE) #define UART1 ((UartType *) UART1_BASE)

In your code you can now use it like this:

UART0->baudRate = 115200; while (1) { while ((UART0->status & INCOMING_BYTE) == 0); printf("%c", UART0->dataIn); }

I've seen this idea in sample code from Atmel, first, but in sample code for the STM32 series it is used, too, and avoids errors.

Of course, you can write it like, this, too:

*(vu32*) 0x40001200 = 115200;

This should be translated to the same code like you are trying to use in your macro (but the structure idea should translate to this code, too).

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

-ffreestanding

-mtune=arm926ej-s

I don't know the ARM assembly syntax, but it looks a little odd with the "=" sign - are you sure that's needed?

Are you trying to write your application in assembly? If so, why?

mvh.,

David

Reply to
David Brown

*/

reestanding

an -ggdb -mtune=3Darm926ej-s

Try looking here,

formatting link
for an explaination on how to use the ldr instruction properly.

Reply to
cbarn24050

-ffreestanding

-mtune=arm926ej-s

Did you remember to name the file extension a capital S?

To have the headers pre-processed, the file must be named as mysource.S and the translation done with the gcc front- end (not directly arm-as).

If you did that, please post the definitions of MM3001_SMC_BASE and MM3001_SMC_SMBWST1R7.

--

Tauno Voipio
tauno voipio (at) iki fi
Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.