2022-04-17 11:21 AM
To overcome this problem I modified the start up assembly file by enabling the clock (AHB1ENR bit 20) at the very beginning. The program which was freezing before enabling the clock started working but stops/freezes after executing a few C statements. I can declare global variables in CCMRAM by providing attribute, but this is resulting in a large chunk (if I use a buffer of say 32K in CCMRAM) FLASH or program memory of 32k is getting filled with 00s (I think to copy initialized variables at start up). What is the workaround please? Thank you for your time.
2022-04-17 11:39 AM
Do you mean STM32F407? In that, CCMRAM *is* enabled after reset:
so if you have problems with it, the source of those problems is something else (that's why adding initialization did not solve the problem).
"Stops/freezes" is not a helpful information. Debug as usually, start by observing in debugger, where is the program counter.
Placing variables/heap/stack to CCMRAM is toolchain-specific, so you should tell us what toolchain do you use and in that, what exactly did you do, what is content of linker script etc. If you use the GNU linker (used usually with gcc), in linker script you can prevent storing initialization data using the (NOLOAD) directive for output sections, but then you have to treat variables allocated there accordingly.
JW
2022-04-17 11:47 AM
One could easily enough change the Initial SP in the vector table to something like 0x20002000, and then immediately in the code of Reset_Handler enable the CCMRAM clock, and change the SP to the desired space, perhaps 0x10010000, and the base of the heap / end-of-statics into 0x10000000
Check also the _sbrk allocator, to see if that's a problem.
2022-04-18 05:40 AM
Hi waclawek.jan,
Thanks for the reply. I am using GCC (CubeIDE). My program prints a lot of messages after testing some portions of HW before going into an infinite loop to execute series of functions. As suggested by you, I will debug the code and see where the problem is. However I would like to mention here that the program works without any problem as long as the stack is set to RAM (original linker file). CCMRAM clock is not enabled at reset. It needs to be enabled in the code. Since I set the stack pointer to CCMRAM, I modified the assembly start up file to add the following before a call is executed. The code started working after I enabled the clock. Also in the diagram you have posted, there seem to be some confusion. as per the binary value shown there the bit to enable CCMRAM clock is BIT 5 but it is actually bit 20 in the register. Here is the code I wrote
ldr r0, =0x40023830
ldr r2, [r0]
orr r2, (1 << 20) //0x100000 // set bit 20.
str r2, [r0] // 1 0 0 0 0 0
/* Call the clock system intitialization function.*/
bl SystemInit // this is the first call.
In linker script file my script is as follows
/* Highest address of the user mode stack */
_estack = 0x10010000; /* end of CCMRAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
ldr sp, =_estack /* set stack pointer. This is the first statement in the start up file. SP is getting initialised to end of CCMRAM
Any suggestions please? After debugging I will share my observations. Thanks once again.
I missed NOLOAD directive. I can manually clear global variable in the code.
Regards
NPS
2022-04-18 05:43 AM
Hi Tesla DeLorean,
Thanks for the reply. Kindly see my reply to waclawek.jan. I have modified the linker script and added assembly code to enable CCMRAM clock. But the controller stops after executing a few C statements. I have posted my linker and assembly snippets in the reply. Thank you.
Regards
NPS
2022-04-18 08:59 AM
Not clear to me how it stops/fails. Does it end up in the Hard Fault handler, or some place else? You'll need to understand what specifically is failing here. The part is capable of using CCMRAM for heap/stack, done so with Keil.
Using with RTOS?
Have you reviewed/debugged _sbrk allocator (syscalls.c) ?
CCMRAM will not be usable for DMA operations.
2022-04-18 11:26 PM
Hi Tesla DeLorean,
Yes, I am aware that CCMRAM can not be used for code execution, DMA operations. I am not using DMA. Can you elaborate on _sbrk allocator? I am of the opinion that heap will be assigned from CCMRAM for this. If DMA is used (which I doubt) in _sbrk, then iit is possible that I may be getting into trouble. I am using strtok_r function to get tokens, but it is somewhere deep down in the code and control is not reaching that part. I await your reply Thank you.
NPS