MIMXRT1021 - DTCRAM allocation

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

MIMXRT1021 - DTCRAM allocation

Jump to solution
2,489 Views
riccardo_carlot
Contributor II

 Hi, I'm pleased to have the opportunity to enlarge my knowledge through this community!

I'm working with a MIMXRT1021. I'm trying to manage the RAM for my application. I read the AN12077 in order to understand the RAM organization and how to handle it.

I would have a way to control the entire 256Kb of RAM (DTCM + ITCM + OCRAM). 

A new project based on the SDK configures the the RAM in this way:

riccardo_carlot_0-1694603333490.png

And the linker:

riccardo_carlot_1-1694603434865.png

 

Where "Default" means SRAM_DTC. With this setup my stack, heap, .bss and my .data sections will be placed in the DTC_RAM partition.
In addition the default size of each partition, set by fuses, is
- DTCM 64Kb
- ITCM 64Kb
- OCRAM 128Kb

As a consequence, with the default configuration, the real RAM size my application can use is 64Kb of DTCM. 

I know I could manage the RAM dinamically, or burning the fuses in according with the AN12077, but I would take it as last chance.

 

My idea is to use the OCRAM to place my .stack, .heap, .bss and .data (128KB), to use ITCRAM for the code i want to execut in RAM, such access flash functions, and last to use DTCRAM for some my data allocation structures. In addition I would to use DTCRAM to allocate the ucHeap of freeRTOS.

So, first of all I changeg the default settings in the linker setting as follow

riccardo_carlot_2-1694604633293.png

It works, now my .stack, .heap, .bss and .data are located in the OCRAM.

 

My problem starts when i try to locate my data in DTCRAM. I'm using the definitions in cr_section_macros.h to place element in SRAM_DTC (RAM). Despite all the attempts, looking at the Image Info, my example vector (vet[]) still remains in the OCRAM. These some of my attempts:

__BSS(RAM) uint8_t vet[255];

__BSS(SRAM_DTC) uint8_t vet[255];

__DATA(RAM) uint8_t vet[255];

__DATA(RAM_DTC) uint8_t vet[255];

__SECTION(data,RAM) uint8_t vet[255];

__SECTION(dummySectionName1,RAM) uint8_t vet[255];

The last refers to "dummySectionName1" that has been declared as .data type section in the linker settings as follow:

riccardo_carlot_4-1694606844932.png

 

Hence, my first question is how can I locate correctly my data in the DTC_RAM?

My second question, how then can I locate the ucHeap of freeRTOS In the DTC_RAM?

  

Labels (1)
0 Kudos
Reply
1 Solution
1,897 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

   Thanks for your updated information.

   Do you test my yesterday's project?

  In fact, that project already help you resolved your 2 issues:

1. RAM array, just use the above reply method.

 2. the while file put to the RAM, still use the linkscript folder, that will help you to modify the ld file automatically, just as I told you in the IDE user manual pdf. I this this way is more better than self modify the linker file.

  Please check my yesterday's reply project. You don't need to delete the linkscript.

Even delete the linkscript meet the ram array issues, still use my above method, in fact, define the user arry in the linker file manually, then use attribute to define to your own RAM area for your RAM data array.

You can refer to this document:

https://community.nxp.com/docs/DOC-335283

  If you still have issues about it, please kindly let me know.

Best Regards,

Kerry

View solution in original post

0 Kudos
Reply
16 Replies
2,434 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

   Thank you for your interest in the NXP MIMXRT product, I would like to provide service for you.

   When you want to put all the heap and stack in the DTCM, you need to make sure your DTCM is enough to use, as you said, RT1020 default flexRAM situation is:

 OCRAM:128k, ITCM/DTCM:64k.

  Then, to the memory put, it is easy, change the heap and stack to DTCM:

kerryzhou_0-1694670193893.png

About other code put to the related area, you can refer refer to this post:

https://community.nxp.com/docs/DOC-335283

If you need to reallocate the flexRAM, please don't burn the fuse at first, you can use the register to control it, you can refer to this post:

https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Reallocating-the-FlexRAM/ta-p/1117649

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

 

0 Kudos
Reply
2,394 Views
riccardo_carlot
Contributor II

Hi @kerryzhou , thank you for the interest in my problem.

Basically now I have two open topics.

1 - First Topic: how to reallocate data in DTCM, ITCM ot OCRAM.
I read the thread Relocating Code and Data Using the MCUXpresso IDE , I imported the three examples in my workspace and this demonstrate that I still have a problem. The reallocation of code in RAM and code in FLASH work properly, whatever RAM or Flash alias I use.
On the contrary, the reallocation of data in RAM doesn't work.
If I set the OCRAM to be used for heap, stack and global placement (c/c++ Build > Settings > MCU Linker > Managed Linker Script) the example vector vet[] will be always put in the OCRAM, despite the alias I indicate in the __DATA() directive.
If I set the DTCRAM to be used for heap, stack and global placement (c/c++ Build > Settings > MCU Linker > Managed Linker Script) the example vector vet[] will be always put in the DTCRAM, despite the alias I indicate in the __DATA() directive.

riccardo_carlot_0-1695139456791.png

I tried to use the __BSS() reallocation, just to be sure, the behavior is the same, the reallocation doesn't work.

 

2 - Second Topic: how to reallocate FlexRAM
I follwed the Reallocating the FlexRAM procedure after reading the AN12077. My target is to allocate all the RAM space (256KB) to the OCRAM. I'm stucked on these points:

  • The procedure uses assembler to set the IOMUXC_GPR_GPR16 and IOMUX_GPR_GPR17 registers. Why should not I use the easiest assigment for reference like this? 
    riccardo_carlot_1-1695140471953.png

  • I don't have the bits to disable SRAM_DTC and SRAM_ITC in the IOMUXC_GPR_GPR16, does this means I can't set to 0KB ITC and DTC or easily is not necessary to move these bits for XRT1021 device?
    riccardo_carlot_2-1695140911297.png
  • The code attached to the procedure, but the procedure too, refers to setting the IOMUX_GPR_GPR14 (the 16 MSb) register. I think this register is different in my 1021, since these bits are indicated as reseved. So, does this means is not mandatory for my device or do I have something different to do?
    riccardo_carlot_3-1695141223168.png

     

  • The last step changes the image entry address to the ResetISR() address:
     
    riccardo_carlot_5-1695141502728.png

    My project is set as follow:

    riccardo_carlot_7-1695141932310.png

    Why should I replace the reset vector address with the ResetISR() function address?

I'm sorry for the large amount of questions. 

Regards

0 Kudos
Reply
2,352 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

   It's my honor to discuss questions to you. Feel free to write the question, your question summary is very very good, really!

   Answer your questions:

1. About the OCRAM, DTCM reallocate, please upload your project, let me check the details, thanks.

 You can delete all the other important code to you, just leave the code which can reproduce the issues.

 

2. About the post and RM difference, if the RM don't have the related bit anymore, you don't need to control that register, as that is not needed, I have checked it internally previously, thanks.

About Why should I replace the reset vector address with the ResetISR() function address?

I also have the question, why you replace the vector address? You don't need it, just need to add the flexRAM remap register control in the reset handler code.

 

Wish it helps you!

Best Regards,

Kerry

0 Kudos
Reply
2,342 Views
riccardo_carlot
Contributor II

HI @kerryzhou , I'm back with some news.

  1. I found the origin of the reallocation issue. But I dont't know how to solve it. Please refer to the attached project.
    The reallocation failure comes when I copy the folder "linkrscripts" inside my project. I took this folder from the example project "evkmimxrt1020_flash_component_nor", otherwise the functions used to manage reading and write flash memory accesses were not located in RAM (they remain in flash, with consequent hard fault error during the operations). 
    So, If you remove the linkscripts folder from the project the RAM reallocation works properly bot in DTC and ITC and OCRAM.
    I could delete the linkscripts folder and move manually every flash access function, but I don't think it is the smartest way.

  2. I'm going to test the relocation of FlaxRam, I'll keep you update.

Thank you for your time

Regards

0 Kudos
Reply
2,262 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

  Sorry for my later reply.

   I checked your project, where you do the reallocate? 

kerryzhou_0-1695720683751.png

 

You didn't add the flexRAM reallocate code.

Why do you need to copy the folder "linkrscripts" inside your project? Your ld file already define the linker file.

 

Best Regards,

Kerry

 

0 Kudos
Reply
2,241 Views
riccardo_carlot
Contributor II

Hi @kerryzhou ,

don't worry.

The reallocation you have to test is just before the main function.

riccardo_carlot_0-1695741358582.png

Please, try to reallocate vet[] as shown above, you will note that despite the RAMx you provide in __DATA() argument, vet[] will stay always in the same RAM section. 

Then, if try to you remove the "linkscript" folder (please clean the project before the re-building), the __DATA() directive will start to work properly and vet[] will be allocated in accord with the RAMx specified in the argument.

Why do you need to copy the folder "linkrscripts" inside your project? 
This is another good question, I hope you can help me to aswer it. 
In my application I have to manage some pages of the external flash memory, I mean I have to read, write and erase data to/from it.
As you know, you have to locate in RAM the functions that execute the erasing and writing in flash, otherwise a system bus error occurs during the operations.
These functions are implemented in flexspi_nor_flash_ops.c and fsl_flexspi.c files, and, in order to move all these functions in RAM, I copied the linkscript folder.
Keep in mind that this procedure comes from the evkmimxrt1020_flexspi_nor_polling_transfer SDK example, and I spend a lot of time before understanding that the linkscript folder is mandatory to make the code work.

In my opinion, the best solution should have been to declare every function as  __RAMFUNC(RAMx), but here, in this SDK, someone decided to use the linkscript files insted.
I don't want to dispute this decision, that maybe is the most agile, but the linkscript folder in some ways is blocking my __DATA(RAMx) allocation. 

Thank you, regards.

 

0 Kudos
Reply
2,195 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

  I checked your project again.

I think the linkrscripts add is the root isues.

As I compare the mapfile and the generated ld file, a lot of difference.

1. issue with linkerscripts:

kerryzhou_0-1695898579970.png

 

2. no issue without linkerscript

kerryzhou_1-1695898608990.png

 

 

3. ld compare result

Left is OK, right is the issue one

kerryzhou_2-1695898623947.png

I think it is related to the ld file relatedship with the linkerscript file

I think, you can don't use the auto generated ld, you can modify the ld file, add the related file.o to the desired memory, then use the ld file directly like this:

kerryzhou_3-1695898859598.png

Then, it will jump out of the ld file auto generation, and will make your RAM works.

You can try it.

If you still have issues about it, please kindly let me know.

For the linker auto generation, I will also check it in the IDE.

Any updated information, I will let you know.

Best Regards,

Kerry

 

 

 

0 Kudos
Reply
2,169 Views
riccardo_carlot
Contributor II

Hi @kerryzhou ,

 

thank you for your efforts. 
OK I can use a the linker file that comes from a working project.
But If I move on this direction, how can I allocate all the flash functions  present in the in flexspi_nor_flash_ops.c and fsl_flexspi.c files inside the RAM? Have I to declare them __RAMFUNC() manually, one by one?

 

Regars

0 Kudos
Reply
2,117 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

  Thanks for your updated information.

  No, you don't need to add  __RAMFUNC() manually,.

 You can refer the ld file directly, add the flexspi_nor_flash_ops.c and fsl_flexspi.c files .o to the RAM, just like this:

kerryzhou_0-1696063542837.png

You can try it on your side.

If you meet any issues, just kindly let me know.

Best Regards,

Kerry

 

0 Kudos
Reply
2,087 Views
riccardo_carlot
Contributor II

Hi @kerryzhou ,

 

Did you try it with your project copy? By my side, depite my manual allocation, ITC_RAM results empty, the flexspi_nor_flash_ops.c and fsl_flexspi.c are only in flash. (I cleaned the project before building)

 

riccardo_carlot_1-1696229546084.png

 

Regards

 

 

0 Kudos
Reply
2,048 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

   Share your test project to me which still in the flash again.

  I will help you to test it when I back to the office, sorry, these days we are in the China National day vocation, so, I can't test it on my vocation, we will back to work from 10.8, then I will help you to test it on my side after I back to work.

  You can refer to the SDK, for the flexspi_nor_flash_ops.c and fsl_flexspi.c, add the related modificaton in the ld file, 

  Anyway, I will test it on my side after I back to work, thanks a lot for your understanding.

 

Best Regards,

Kerry

0 Kudos
Reply
2,045 Views
riccardo_carlot
Contributor II

HI @kerryzhou ,

 

No problem, take your time. 

Attached the project. You will find the .Id file already modified. Try to build it and check the SRAM_ITC, it will be empty, despite of the .Id.

 

Thank you a lot.

Regards

0 Kudos
Reply
1,926 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

   Thanks so much for your understanding.

   I already back to work and test your project.

  Let's still based on your first linkscrpt method.

  I do it like this, then the data is in the related area:

kerryzhou_0-1696840773610.pngkerryzhou_1-1696840779411.png

kerryzhou_2-1696840788179.png

 

You can see, from the map file, my defined vet2 array is located in the SRAM_OC area, it is located from 0X20200000.

I also attach my modified project.

You can delete the vet, vet1 method.

BTW, about the ldt situation, you can refer to the document:

C:\nxp\MCUXpressoIDE_11.8.0_1165\MCUXpresso_IDE_User_Guide.pdf

chapter 19. Memory Configuration and Linker Scripts

chapter 19.14.2 Reference

Wish it helps you!

If you still have question about it, please kindly let me know.

Best Regards,

Kerry

 

 

 

0 Kudos
Reply
1,917 Views
riccardo_carlot
Contributor II

Hi @kerryzhou ,

 

thank so much for your support but I think we are aiming two different problems.

 

My problem, now, is: How can I allocate all the function in the flexspi_nor_flash_ops.c and fsl_flexspi.c  files in ram without manually declare them, one by one, as __RAMFUNC()?

 

In the project you just sent me, the linkscript folder is still present.
From this, please, remove the linkscript folder, clean and built it again. Now you shoud see the ITC_RAM empty. Isn't?

You will observe also that .id file will be overwritten every time you compile, despite everything I write (it's correct, MCUXpresso is set ot manage it).
Now, from this starting point, how can I allocate flexspi_nor_flash_ops.c and fsl_flexspi.c  in ram?

Thank you 

0 Kudos
Reply
1,898 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @riccardo_carlot ,

   Thanks for your updated information.

   Do you test my yesterday's project?

  In fact, that project already help you resolved your 2 issues:

1. RAM array, just use the above reply method.

 2. the while file put to the RAM, still use the linkscript folder, that will help you to modify the ld file automatically, just as I told you in the IDE user manual pdf. I this this way is more better than self modify the linker file.

  Please check my yesterday's reply project. You don't need to delete the linkscript.

Even delete the linkscript meet the ram array issues, still use my above method, in fact, define the user arry in the linker file manually, then use attribute to define to your own RAM area for your RAM data array.

You can refer to this document:

https://community.nxp.com/docs/DOC-335283

  If you still have issues about it, please kindly let me know.

Best Regards,

Kerry

0 Kudos
Reply
1,889 Views
riccardo_carlot
Contributor II

Hello @kerryzhou,

 

Now is clear, my misunderstanding was related to the fact that I thought we was looking for an alternative way to put the flash functions in ram instead of use the linkscript folder that creates problem with__DATA() allocation function.

Btw I think this is also a compromise, I sign it as solution, thank you a lot for your time.

Regards