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...
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)
AREA is a directive for the assembler. It doesn't mean anything for the processor.
The processor - the physical hardware - can not have any magic that makes RAM initialized with content when the processor wakes from a reset. It is 100% up to the program that starts running to give content to RAM.
That is one of many things that the CRTL startup code performs. If you don't use C then it's something you must do.
The linker can produce a shadow-copy of initial RAM data in flash - but the linker runs on your PC. It's still the program that gets downloaded into the microcontroller that must contain code to take the contents of that shadow-copy and place in RAM.
It is only when you do debugging and run programs in RAM, that you can have the download code place not just code but also variable data into the RAM. No such thing can happen when you run a processor stand-alone, so it just starts up from a reset and goes hunting for a program in the flash.
1) I'm using the debugger, this program never runs on the uc standalone.
2) Why does it work on the 8051 or the c167 (with Keil)?
3) What is the difference between DCD and SPACE?
I guess i solved my initial problem...
What am i missing?
Answer: Constants go into "READONLY"
AREA myVars, DATA, READONLY op1_table DCW 0x0001, 0x0017, 0xffff, 0x73a4, 0x43cc, 0xe372, 0xdd22, 0x7fff op2_table DCW 0xffff, 0x0004, 0xffff, 0x4c28, 0xc3bf, 0x0234, 0xbcde, 0x7fff
Thanks Per after all you pointed me in the right direction. I probably should have posted the original code and not this (hideous) example trying to write to a constant...