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

ソリューションへジャンプ
911件の閲覧回数
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 解決策
858件の閲覧回数
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 返答(返信)
859件の閲覧回数
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 件の賞賛
返信
813件の閲覧回数
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%3ERT1021%E3%81%AE%E3%83%95%E3%83%A9%E3%83%83%E3%82%B7%E3%83%A5%E3%81%A7const%E5%A4%89%E6%95%B0%E3%82%92%E3%81%A9%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E4%BF%9D%E5%AD%98%E3%81%97%E3%81%A6%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2029221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EQSPI%20FLASH%E3%81%AE%E4%B8%80%E9%83%A8%E3%82%92%E8%AA%AD%E3%81%BF%E5%8F%96%E3%82%8A%E5%B0%82%E7%94%A8%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%82%B9%E3%83%88%E3%83%AC%E3%83%BC%E3%82%B8%E3%81%AB%E5%88%86%E5%89%B2%E3%81%97%E3%81%9F%E3%81%84%E5%A0%B4%E5%90%88%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%E3%80%81%E3%81%BE%E3%81%9F%E3%80%81%E3%81%9D%E3%81%AE%E5%AE%9A%E6%95%B0%E5%A4%89%E6%95%B0%E3%82%92%E3%82%BD%E3%83%BC%E3%82%B9%E3%82%B3%E3%83%BC%E3%83%89%E3%81%A7%E3%81%A9%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E5%AE%A3%E8%A8%80%E3%81%97%E3%81%A6%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%3F%3C%2FP%3E%3CP%3EMCUxpresso%E3%81%A8RT1021%E3%83%97%E3%83%AD%E3%82%BB%E3%83%83%E3%82%B5%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%E3%81%93%E3%82%8C%E3%82%92%E8%A1%8C%E3%81%86%E3%81%AB%E3%81%AF%E3%80%81IDE%E3%81%A7%E4%BD%95%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%E5%BF%85%E8%A6%81%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%81%8B%3F%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%E3%82%88%E3%82%8D%E3%81%97%E3%81%8F%E3%81%8A%E9%A1%98%E3%81%84%E3%81%84%E3%81%9F%E3%81%97%E3%81%BE%E3%81%99%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%3ERe%3ART1021%E3%81%AE%E3%83%95%E3%83%A9%E3%83%83%E3%82%B7%E3%83%A5%E3%81%A7const%E5%A4%89%E6%95%B0%E3%82%92%E3%81%A9%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E4%BF%9D%E5%AD%98%E3%81%97%E3%81%A6%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2034012%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%81%94%E3%81%96%E3%81%84%E3%81%BE%E3%81%99%EF%BC%81%E3%81%93%E3%82%8C%E3%81%A7%E3%81%86%E3%81%BE%E3%81%8F%E3%81%84%E3%81%8D%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E