cancel
Showing results for 
Search instead for 
Did you mean: 

stm32h745 calls to itcm code crash when called from freertos task.

Ihawk.1
Associate II

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

0693W00000JPaOyQAL.png ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K - should this be (xrw)?

Any clues please? I am using cubeide and v1.9 of the h7 libraries.

4 REPLIES 4
Pavel A.
Evangelist III

Maybe something overwrote the function in the ram?

Ihawk.1
Associate II

Thanks Pavel, I found this :

https://community.st.com/s/question/0D50X0000BJ25scSQB/how-to-place-some-part-of-code-in-itcm-and-dtcm-in-stm32h745-

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.

Look at a disassembly of the offending code section, especially code that's writing to memory immediately prior to the faulting PC

L​ook at MAP file to understand what is placed where.

C​ode 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.

A​rduino use a table driven method to make this simpler, similar to the Keil implementation.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ihawk.1
Associate II

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.