cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 in firmware cannot assign values to an array

Logann123321
Associate III

Hi I am trying to assign values to an array to send for an spi transaction, I declared the variable and assigned each index of the array in a loop, but when I am debugging it the array is constantly 0 for each of its elements unless I defined it as a const, does anyone know why that is the case?

Thanks!

8 REPLIES 8
Ozone
Lead II

It would probably be very helpful to post some relvant parts of your code.

Logann123321
Associate III

I literally just have uint8_t aTxBuffer[1024] = {0}; and then a loop: for (i = 0; i < 1024; i++){

aTxBuffer[i] = 10;

}

I do also HAL_Init(); and CPU_CACHE_Enable(); I tried invalidate the buffer using SCB_InvalidateDCache_by_Addr ((uint32_t *)aTxBuffer, BUFFERSIZE); but that didn't work either

Logann123321
Associate III

Also it seems that if I assign values before I call CPU_CACHE_Enable it gets assigned, so I think it is problem with the CPU_CACHE_Enable, but I have no idea how to solve this since I used SCB_InvalidateDCache_by_Addr  and it didn't work

Ozone
Lead II

Example code for the F7 used to call CPU_CACHE_Enable() as well as very first thing in main, which translates to calls of SCB_EnableICache() and SCB_EnableDCache().

I have no experinece with the H7 devices.

Logann123321
Associate III

So for F7 how if you want to assign values to an array after you called CPU_CACHE_Enable what would you do?

Not much different from what you described.

Where do you declare the buffer, and how (auto, static, volatile, ...) ?

Have you tried a debugger to see what happens ?

Perhaps on instruction (assembly) level ?

What does the map file say about your array ?

I hardly use newer STM32 variants which have only Cube/HAL support.

Pavel A.
Evangelist III

When you write to memory from the MCU side, you need to flush (a.k.a. clean) the cache, not invalidate.

Invalidation discards updates from the MCU side.

SCB_InvalidateDCache_by_Addr() doesn't like do what you think it does, most likely you'll crash the system using this.

What tools are you using?

Is this a custom board?

Is there a project someone could actually rebuild/replicate the scenario?

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