Skip to main content
Visitor II
December 5, 2019
Question

STM32H7 in firmware cannot assign values to an array

  • December 5, 2019
  • 6 replies
  • 2041 views

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!

    This topic has been closed for replies.

    6 replies

    Explorer
    December 5, 2019

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

    Visitor II
    December 5, 2019

    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

    Visitor II
    December 5, 2019

    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

    Graduate II
    December 5, 2019

    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?

    Explorer
    December 5, 2019

    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.

    Visitor II
    December 5, 2019

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

    Explorer
    December 5, 2019

    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.

    Super User
    December 5, 2019

    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.