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:
And the linker:
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
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:
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?
Solved! Go to Solution.
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
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:
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
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.
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:
My project is set as follow:
Why should I replace the reset vector address with the ResetISR() function address?
I'm sorry for the large amount of questions.
Regards
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
HI @kerryzhou , I'm back with some news.
Thank you for your time
Regards
Hi @riccardo_carlot ,
Sorry for my later reply.
I checked your project, where you do the reallocate?
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
Hi @kerryzhou ,
don't worry.
The reallocation you have to test is just before the main function.
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.
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:
2. no issue without linkerscript
3. ld compare result
Left is OK, right is the issue one
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:
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
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
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:
You can try it on your side.
If you meet any issues, just kindly let me know.
Best Regards,
Kerry
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)
Regards
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
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
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:
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
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
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
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