You are here

How to use CY_NOINIT? | Cypress Semiconductor

How to use CY_NOINIT?

Summary: 8 Replies, Latest post by necdetalpmen_1437776 on 13 Nov 2016 08:28 PM PST
Verified Answers: 1
Last post
Log in to post new comments.
necdetalpmen_1437776's picture
User
15 posts

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(;;)
    {
 
    }
}
user_1377889's picture
User
9583 posts

Put away the "static".

 

Bob

 

user_365962704's picture
User
163 posts

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

user_1377889's picture
User
9583 posts

 

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

 

Bob

user_365962704's picture
User
163 posts

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-c...

* 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?

necdetalpmen_1437776's picture
User
15 posts

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

 

necdetalpmen_1437776's picture
User
15 posts

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.

user_1377889's picture
User
9583 posts

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

necdetalpmen_1437776's picture
User
15 posts

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.

Log in to post new comments.