2024-06-20 02:01 AM
I'm using a STM32H753 with external RAM. We were using it for LCD framebuffer. Now we are trying to migrate the stack and heap to the external RAM, when we run the code, getting hardfault on lines where std::array is declared. Any idea on how to debug further?
2024-06-20 02:15 AM
Don't put the stack in external RAM, it will make everything slower.
If you get a Hard Fault it's because you're using memory before the peripheral and interface is up and running.
For the compiler run time to initialize you want.to be initializing external memories early, in SystemInit() along with your clocks.
2024-06-20 02:47 AM
Hello,
As @Tesla DeLorean the memory interface (FMC) is not prepared/initialized before the main() so you need to initialize it in SystemInit(). See also this thread.
Meanwhile, what is the reason to move the Stack and heap to the external memory? is there a size lack of the internal one?
I agree with @Tesla DeLorean the execution will be slower but the cache could compensate that at a certain level. The best location to locate the stack/heap is the DTCM for execution determinism. You can refer to the AN4891 "STM32H72x, STM32H73x, and single-core STM32H74x/75x system architecture and performance" / Section 5.1 Software memory partitioning :
2024-06-20 03:52 AM
That already taken care of, we followed the example given in the cubemx, initialized the FMC in the systeminit. We are using freertos all the tasks are up, what is strange is the hardfault occurs on the std:array declaration line in one of the task.
2024-06-20 03:53 AM
Initially we were using Internal RAM only for the stack and heap, but features kept on added and we ran out of internal memory, hence we are trying to move to external ram.
2024-06-20 04:09 AM
We were using it for LCD framebuffer. Now we are trying to migrate the stack and heap to the external RAM, when we run the code, getting hardfault on lines where std::array is declared.
It could be your stack is overwritten / or overlapped with your frame buffer. Not easy to tell you why the HF happens .. Need to debug that ..
2024-06-20 04:45 AM
2024-06-20 05:12 AM
So C++, does it fault whilst initializing the constructors?
/* Call static constructors */
bl __libc_init_array
What's the fault reporting, exactly?
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c
2024-06-20 09:04 AM
bl __libc_init_array executes without any issues and enters main() too.
if we have the following code,
2024-06-20 09:51 AM
Ok, but what address is the allocator furnishing here?
Can you instrument __sbrk ? Or whatever is serving up space?
Sounds like something is walking into the end-of-memory. The FMC setting will scope the address decode space of the SDRAM
What are the instructions/registers for the MCU at the point of failure?
How large is the SDRAM? Show initialization code for it