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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
908 次查看
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 项奖励
回复
1 解答
855 次查看
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 项奖励
回复
2 回复数
856 次查看
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 项奖励
回复
810 次查看
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%3E%E5%A6%82%E4%BD%95%E5%9C%A8%20RT1021%20%E4%B8%AD%E7%9A%84%E9%97%AA%E5%AD%98%E4%B8%AD%E5%AD%98%E5%82%A8%E5%92%8C%E4%BD%BF%E7%94%A8%20const%20%E5%8F%98%E9%87%8F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2029221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E5%A6%82%E6%9E%9C%E6%82%A8%E6%83%B3%E5%88%86%E7%A6%BB%E5%87%BA%20QSPI%20FLASH%20%E7%9A%84%E4%B8%80%E9%83%A8%E5%88%86%E7%94%A8%E4%BA%8E%E5%8F%AA%E8%AF%BB%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%EF%BC%8C%E6%82%A8%E9%9C%80%E8%A6%81%E5%81%9A%E4%BB%80%E4%B9%88%E4%BB%A5%E5%8F%8A%E5%A6%82%E4%BD%95%E5%9C%A8%E6%BA%90%E4%BB%A3%E7%A0%81%E4%B8%AD%E5%A3%B0%E6%98%8E%E5%92%8C%E4%BD%BF%E7%94%A8%E8%AF%A5%E5%B8%B8%E9%87%8F%E5%8F%98%E9%87%8F%EF%BC%9F%3C%2FP%3E%3CP%3E%E6%88%91%E6%AD%A3%E5%9C%A8%E4%BD%BF%E7%94%A8%20MCUxpresso%20%E5%92%8C%20RT1021%20%E5%A4%84%E7%90%86%E5%99%A8%E3%80%82%E6%82%A8%E5%BF%85%E9%A1%BB%E5%9C%A8%20IDE%20%E4%B8%AD%E8%AE%BE%E7%BD%AE%E4%BB%80%E4%B9%88%E6%89%8D%E8%83%BD%E5%81%9A%E5%88%B0%E8%BF%99%E4%B8%80%E7%82%B9%EF%BC%9F%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%E6%8F%90%E5%89%8D%E6%84%9F%E8%B0%A2%E6%82%A8%EF%BC%81%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2034012%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9C%A8%20RT1021%20%E4%B8%AD%E7%9A%84%E9%97%AA%E5%AD%98%E4%B8%AD%E5%AD%98%E5%82%A8%E5%92%8C%E4%BD%BF%E7%94%A8%20const%20%E5%8F%98%E9%87%8F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2034012%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E8%B0%A2%E8%B0%A2%E4%BD%A0%EF%BC%81%E8%BF%99%E6%8B%9B%E5%A5%8F%E6%95%88%E4%BA%86%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E