Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

Anonymous
Not applicable

Hi,

   

I am trying to use CY_NOINIT to not initialize a variable after soft reset conditions. I keep getting "reset = 0" message from UART. Am I missing something?

   
#include <project.h> static uint8 is_soft_reset CY_NOINIT; void app_init(void) {     UART_1_Start();    if(!is_soft_reset) {         UART_1_PutString("reset = 0\n");         CyDelay(1000);         is_soft_reset = 1;         CySoftwareReset();     }     UART_1_PutString("reset = 1\n"); } int main(void) {     app_init();     for(;;)     {       }}
0 Likes
8 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Put away the "static".

   

 

   

Bob

0 Likes
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

I remember that global variables are always initialized to 0, even when the programmer does not initialize it explicitly.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Carlos, there is a .NOINIT area which is explicitly used for variables that are not initialized to zero at reset.

   

 

   

Bob

0 Likes

My fault, didn't knew about that section ;(, just search about it and found a couple of interesting pages describing it:

   

* http://stackoverflow.com/questions/11180892/force-gcc-to-forgo-zeroing-certain-globals

   

* http://www.nongnu.org/avr-libc/user-manual/mem_sections.html

   

Second link point out that it is possible to tell the linker explicitly where to place the .noinit section with some commands, maybe that's missing.

   

Are all the memory sections listed on the map file?

0 Likes
Anonymous
Not applicable

Nope, still not working. Can it be caused by some compiler or linker flag that I use?

0 Likes
Anonymous
Not applicable

I found the problem. I disabled bootloadable from schematic and it seems to work but it doesn't reset the variable if device is coming from power down. Is this an expected behavior?

   

Also I need my project to be bootloadable.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your .noinit area is never initialized. The trick is to put a "magic number" into .noinit to see if the data is valid and / or check the reset cause (look into System Reference Guide) for a software reset.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

When I disabled bootloader from the project it was working. I didn't want to deal with sharing a variable between bootloader and bootloadable application on RAM. So, I decided to use internal EEPROM.

0 Likes