We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to use MICROLIB as (from my initial measurements) it appears to offer space savings of around 1.4KB.
However, I am having problems getting it to work with an initialised STACK. I want to initialise the stacks to known values (e.g. "STAC") for debugging and stack sizing purposes and have modified "startup.s" accordingly. This worked fine without MICROLIB, but using MICROLIB causes a crash. What appears to happen is as follows :-
1) At the start of _main, library code is called to perform initialisation (R/W and ZI). 2) LR (and R4) are pushed on the stack. 3) The stack contents are then initialised to the specified value, overwriting the saved LR (and R4). 4) The LR (and R4) are popped of the stack and the code attempts to branch to the value stored in LR (now "STAC").
I have tried adding an uninitialised ("NOINIT") 8 bytes at the end of the initialised stack, and can configure it so that this area is used for the two register pushes, but these 8 bytes are still being zero-initialised - I don't know why.
The stack declaration looks like this :-
GBLA count AREA STACK, READWRITE, ALIGN=3 Stack_Mem count SETA 0 WHILE count < (Stack_Size / 4) count SETA (count + 1) DCD STACK_INIT_VAL WEND AREA STACK, NOINIT, READWRITE, ALIGN=3 SPACE 8 __initial_sp Stack_Top EQU (Stack_Mem + Stack_Size + 8)
Any ideas how I can either actually prevent the initialisation of a "NOINIT" section, or get around this in another way ?
Also, is there any easier way to initialise a block of data than the above, which seems overly complex compared to other assemblers I have used. I would expect some sort of declaration that allowed me to specify the size, number of items and initial value. I'm sure I'm missing something obvious but can't find it in the online help.
Thanks,
David.
Declaring an area in the assembler as NOINIT is the first step but it must be put also in a linker region which is not initialized (otherwise the linker region settings will override area settings).
This can be achieved quickly by redefining the memory layout under the Option for Target - Target. Split the defined RAM and define a separate region with NoInit flag. Then assign your stack to this region (you can simply assign the ZI data of the complete startup file to this region - right mouse click on startup file in the Project Workspace).
The whole process is a little bit complex but your request is also not ordinary and you must keep in mind that stack is already used by _main which also does among others the RW & ZI initialization.
Thanks Robert,
Using the Target dialog would force me to define absolute addresses for the uninitialised data. This may not be a bad thing, but is very inflexible during development. It also kind of defeats the original objective which is to have an initialised stack.
I found a reference in the online manual which states :-
Only the attributes of the first AREA directive of a particular name are applied.
This explains why, in my original second STACK AREA declaration, the NOINIT attribute is ignored.
I think I have managed to achieve what I wanted by using the GROUP attribute to specify two AREA declarations as part of a single STACK GROUP. The manual states :-
Sections within a group are kept or discovered together.
I'm not sure exactly what that's supposed to mean, but it seems to do the job.
I changed my declaration to :-
AREA STACKINIT, READWRITE, ALIGN=2, GROUP=STACK Stack_Mem count SETA 0 WHILE count < (Stack_Size / 4) count SETA (count + 1) DCD STACK_INIT_VAL WEND Stack_Top EQU (Stack_Mem + Stack_Size) AREA STACKNOINIT, NOINIT, READWRITE, ALIGN=2, GROUP=STACK SPACE 8 __initial_sp
This appears to work but still needs more testing and tuning.
Any comments on the other question in my original post regarding better ways to define blocks of data containing a single initialisation value ?
Thanks again, David.
I spoke too soon.
Using the above GROUP, the code works, but the STACK is NOT initialised with the specified value, and I have no idea why not.