How do you store and use a const variable in flash in RT1021

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do you store and use a const variable in flash in RT1021

Jump to solution
897 Views
DaveG1
Contributor II

What do you have to do if you want to split off part of the QSPI FLASH to be for read only data storage and how do you declare and use that constant variable in your source code?

I am using MCUxpresso and a RT1021 processor.  What do you have to set in the IDE to do this?

 

Thanks in advance !

0 Kudos
Reply
1 Solution
844 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hello @DaveG1 

Let me show the steps that I tipically do. This is my way to purposely place variables on a desired section of the flash.

1 Split the flash. You can modify the size and adress to your desired preference, I only made a simple spit.

diego_charles_1-1737410622848.png

 

2 Provide a meaningfull name to the flash area, I used DATA_FLASH.

3 Create an extra linker section. I created CustomSection in the DATA_FLASH area I created earlier. The type is rodata, as I will place a constant array there. 

diego_charles_2-1737410698451.png

 

4 Use a macro to place this variable. 

__attribute__((section("CustomSection")))  uint8_t array_4_davie[1024] ={1,2,3,4,5,6 };

5 Re-compile and verify that the macro does works.

diego_charles_0-1737410590057.png

As you can see in the debug output the array_4_davie is placed in Custom section, which belongs to DATA_FLASH section. 

The IDE does this whevener you want to place a variable in NON_CACHE area.

AT_NONCACHEABLE_SECTION_ALIGN(static USHORT frame_buffer[2][FRAME_BUFFER_PIXELS], FRAME_BUFFER_ALIGN);

But there are more methods, like using cr section macros library ( we have some posts for this already in the NXP community )

Diego. 

 

View solution in original post

0 Kudos
Reply
2 Replies
845 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hello @DaveG1 

Let me show the steps that I tipically do. This is my way to purposely place variables on a desired section of the flash.

1 Split the flash. You can modify the size and adress to your desired preference, I only made a simple spit.

diego_charles_1-1737410622848.png

 

2 Provide a meaningfull name to the flash area, I used DATA_FLASH.

3 Create an extra linker section. I created CustomSection in the DATA_FLASH area I created earlier. The type is rodata, as I will place a constant array there. 

diego_charles_2-1737410698451.png

 

4 Use a macro to place this variable. 

__attribute__((section("CustomSection")))  uint8_t array_4_davie[1024] ={1,2,3,4,5,6 };

5 Re-compile and verify that the macro does works.

diego_charles_0-1737410590057.png

As you can see in the debug output the array_4_davie is placed in Custom section, which belongs to DATA_FLASH section. 

The IDE does this whevener you want to place a variable in NON_CACHE area.

AT_NONCACHEABLE_SECTION_ALIGN(static USHORT frame_buffer[2][FRAME_BUFFER_PIXELS], FRAME_BUFFER_ALIGN);

But there are more methods, like using cr section macros library ( we have some posts for this already in the NXP community )

Diego. 

 

0 Kudos
Reply
799 Views
DaveG1
Contributor II

Thank you!  That did the trick.

%3CLINGO-SUB%20id%3D%22lingo-sub-2029221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20do%20you%20store%20and%20use%20a%20const%20variable%20in%20flash%20in%20RT1021%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2029221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EWhat%20do%20you%20have%20to%20do%20if%20you%20want%20to%20split%20off%20part%20of%20the%20QSPI%20FLASH%20to%20be%20for%20read%20only%20data%20storage%20and%20how%20do%20you%20declare%20and%20use%20that%20constant%20variable%20in%20your%20source%20code%3F%3C%2FP%3E%3CP%3EI%20am%20using%20MCUxpresso%20and%20a%20RT1021%20processor.%26nbsp%3B%20What%20do%20you%20have%20to%20set%20in%20the%20IDE%20to%20do%20this%3F%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThanks%20in%20advance%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2034012%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20How%20do%20you%20store%20and%20use%20a%20const%20variable%20in%20flash%20in%20RT1021%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2034012%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThank%20you!%26nbsp%3B%20That%20did%20the%20trick.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2030888%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20How%20do%20you%20store%20and%20use%20a%20const%20variable%20in%20flash%20in%20RT1021%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2030888%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F235474%22%20target%3D%22_blank%22%3E%40DaveG1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%20me%20show%20the%20steps%20that%20I%20tipically%20do.%20This%20is%20my%20way%20to%20purposely%20place%20variables%20on%20a%20desired%20section%20of%20the%20flash.%3C%2FP%3E%0A%3CP%3E1%20Split%20the%20flash.%20You%20can%20modify%20the%20size%20and%20adress%20to%20your%20desired%20preference%2C%20I%20only%20made%20a%20simple%20spit.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22diego_charles_1-1737410622848.png%22%20style%3D%22width%3A%20739px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22diego_charles_1-1737410622848.png%22%20style%3D%22width%3A%20739px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F320425i4AEDB006E62A9FF6%2Fimage-dimensions%2F739x660%3Fv%3Dv2%22%20width%3D%22739%22%20height%3D%22660%22%20role%3D%22button%22%20title%3D%22diego_charles_1-1737410622848.png%22%20alt%3D%22diego_charles_1-1737410622848.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E2%20Provide%20a%20meaningfull%20name%20to%20the%20flash%20area%2C%20I%20used%20DATA_FLASH.%3C%2FP%3E%0A%3CP%3E3%20Create%20an%20extra%20linker%20section.%20I%20created%20CustomSection%20in%20the%20DATA_FLASH%20area%20I%20created%20earlier.%20The%20type%20is%20rodata%2C%20as%20I%20will%20place%20a%20constant%20array%20there.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22diego_charles_2-1737410698451.png%22%20style%3D%22width%3A%20684px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22diego_charles_2-1737410698451.png%22%20style%3D%22width%3A%20684px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F320426i1DF538FEFC680D39%2Fimage-dimensions%2F684x726%3Fv%3Dv2%22%20width%3D%22684%22%20height%3D%22726%22%20role%3D%22button%22%20title%3D%22diego_charles_2-1737410698451.png%22%20alt%3D%22diego_charles_2-1737410698451.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E4%20Use%20a%20macro%20to%20place%20this%20variable.%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E__attribute__((section(%22CustomSection%22)))%20%20uint8_t%20array_4_davie%5B1024%5D%20%3D%7B1%2C2%2C3%2C4%2C5%2C6%20%7D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E5%20Re-compile%20and%20verify%20that%20the%20macro%20does%20works.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22diego_charles_0-1737410590057.png%22%20style%3D%22width%3A%20714px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22diego_charles_0-1737410590057.png%22%20style%3D%22width%3A%20714px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F320424iCDA9B26FA011B20C%2Fimage-dimensions%2F714x639%3Fv%3Dv2%22%20width%3D%22714%22%20height%3D%22639%22%20role%3D%22button%22%20title%3D%22diego_charles_0-1737410590057.png%22%20alt%3D%22diego_charles_0-1737410590057.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EAs%20you%20can%20see%20in%20the%20debug%20output%20the%20array_4_davie%20is%20placed%20in%20Custom%20section%2C%20which%20belongs%20to%20DATA_FLASH%20section.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20IDE%20does%20this%20whevener%20you%20want%20to%20place%20a%20variable%20in%20NON_CACHE%20area.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3EAT_NONCACHEABLE_SECTION_ALIGN(static%20USHORT%20frame_buffer%5B2%5D%5BFRAME_BUFFER_PIXELS%5D%2C%20FRAME_BUFFER_ALIGN)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EBut%20there%20are%20more%20methods%2C%20like%20using%20cr%20section%20macros%20library%20(%20we%20have%20some%20posts%20for%20this%20already%20in%20the%20NXP%20community%20)%3C%2FP%3E%0A%3CP%3EDiego.%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E