2022-02-12 11:44 AM
In the flash.ld file:
/* Memories definition */
MEMORY
{
...
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
}
SECTIONS
{
.......
.itcm :
{
. = ALIGN(4);
*(.itcmram) /* .section_name section */
. = ALIGN(4);
} >ITCM_RAM AT> FLASH
the function:
int __attribute__((section(".itcmram")))NullJump(int j)
{
return j+1;
}
The function works when called before freertos starts,
but jumps to :
HardFault_Handler(void)
on return from function when the OS is running.
Errors are:
bus memory management or useage fault(forced)
and:
imprecise data access violation
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K - should this be (xrw)?
Any clues please? I am using cubeide and v1.9 of the h7 libraries.
2022-02-12 05:06 PM
Maybe something overwrote the function in the ram?
2022-02-13 03:54 AM
Thanks Pavel, I found this :
which sort of answers my question, one has to copy the code to its destination using a modified startup *.s file. It appears the code to go into ITCM has to be in its own *.o file so that the startup routine knows what to copy , otherwise other code gets copied too, and then everything is messed up. the cited post also uses 8 byte alignment, not the 4 that I had used. The memory viewer showed the code as being properly located with veneers etc, but it was not. I dont understand why it worked at all, even before the OS started up.
The stmcubeideworkshop2019 has a github entry 07_isr_in_ictm - but that is for the f7 core.
Its a bit beyond my code monkey skills.
2022-02-13 04:22 AM
Look at a disassembly of the offending code section, especially code that's writing to memory immediately prior to the faulting PC
Look at MAP file to understand what is placed where.
Code doesn't need to be in its own object file, but does need to be in its own staging location in flash via the linker script, establishing starting and ending points, with copy in startup.s to move it to its final destination.
Arduino use a table driven method to make this simpler, similar to the Keil implementation.
2022-02-13 06:51 AM
Thanks Tesla, I think I've got it now.
To make a particular function in a .c file run in ITCM write:
int __attribute__((section(".itcmram"),optimize("O0")))NullJump(int j) (optimisation disabled for debugging)
otherwise, to put all of the functions from an entire c file "itcmtest.c" into itcm include "itcmtest.o" in the ld file
... and modify the startup assembler to load the things into the right place.
For reference I attach my startup_stm32h745zitx.s and STM32H745ZITX_FLASH.ld files as they may help others, on the other hand they may have undiscovered errors/be plain wrong, as I am blindly following recipes.
Please note that there is other stuff going on in the .ld file for ethernet and dma buffer use - ignore it.
It gives me a funny feeling calling a function at the null pointer.