Hello Amey,
Amey wrote:
I tried with the allocations mentioned in prm file which i have posted here. It works fine sometime if i only try to capture the waveform. But in my application after capturing a waveform i write it to the flash memory. This flash writing routine needs about 37 bytes of RAM. It writes data to the flash correctly but after that code misbehaves.
I assume your RAM based function is located on the stack, i.e. doonstack. If so, the additional stack requirements are probably over-writing your static variables in the RAM segment, and perhaps even into Z_RAM.
If you search this forum, you should find an alternative method of writing to flash memory that uses a fixed location within RAM, and requires only about 10 bytes. Since the code would be loaded to RAM just prior to the erase/write process, it does not matter if this is eventually over-written by the stack. The location I might choose would be just above the static variables in RAM, or at the bottom of the stack segment (assuming a realistic stack segment size).
Always check the map file for the project, to determine where the variables and the stack are actually being placed by the linker.
You said i should declare my variables to page zero. Shall i declare my local variables to page zero as well? Will this help more?
By definition, local variables are placed on the stack. For a variable to be located at a fixed location it would need to be defined as static, but this is generally not a good idea unless the variable value needs to be retained once the function exits. Within your local variables, do you have any large array variables? These may greatly expand the stack requirements when the function is executed.
Local variables defined within main() will need special consideration. Since this function does not exit, the stack space occupied by these variables will never be recovered, and will increase the overall stack size requirements. If these are significant, it may be better to define them as static, to avoid complicating the stack size issue.
Regards,
Mac