Hi
Im using a STM32F429ZI and have the folowing problem:
In my assembler program i initialize the following variables:
AREA myVars, DATA, READWRITE op1_table DCW 0x0001, 0x0017, 0xffff, 0x73a4, 0x43cc, 0xe372, 0xdd22, 0x7fff op2_table DCW 0xffff, 0x0004, 0xffff, 0x4c28, 0xc3bf, 0x0234, 0xbcde, 0x7fff
Then i want to acces them:
AREA myCode, CODE, READONLY THUMB main PROC EXPORT main LDR R0, =op1_table LDR R1, =0xff LDRH R2, [R0, #0] ; After this R2 contains 0xbe (should be 0x1) STRH R1, [R0, #0] LDRH R2, [R0, #0] ; After this R2 contains 0xff (as it should)
I can write and read from the variable, but they're not initialized as the suposed to be (with the DCW directive).
What am i missing? I wrote a c example with global variables and couldn't find a difference...
Note that the C example makes use of a function within the C runtime library that will copy initial values from flash into RAM, and zero-initialize the rest of the RAM before main() gets called.
But that doesn't fix my problem. I mean i could just use the SPACE directive and initialize the memory with LDR/STR, but then: whats the point about the DCx directives?
How do you think that data moves from flash to RAM when the processor starts running a program? Can there be any possible way for the data to jump into RAM unless the program contains some code that performs that task?
Note that the directives don't care about the persistance of the memory region - so constants in flash can store data without need for any runtime help. Initialized variables in RAM requires runtime help to get their values - either explicit assigns or code that copies the values from flash into RAM.
1) Thats what the DCx directive is for (at least in my mind). It works exactly this way on the 8051, the C167 or the 186.
2) Doesn't the AREA myVars, DATA, READWRITE section copy the variables i defined into the RAM? -> Again if not, whats the point of the DCx?
The DCW directive allocates one or more halfwords of memory, aligned on two-byte boundaries, and defines the initial runtime contents of the memory. DCWU is the same, except that the memory alignment is arbitrary.
from armasm User Guide (version 5.04)
View all questions in Keil forum