STM32H743 variable not updating in interrupt handler
Hello,
i have a strange situation happening and I really can't catch the reasons; in my project I set up an SPI transfer and set a global volatile variable that keeps trace of status state:
//Transmit Data
if(spi == AMPLI_SPI4) SPI4_TransferState = TRANSFER_ONGOING;
ret = HAL_SPI_Transmit_IT(&SpiHandle[spi], pData, Size);Then in my interrupt handler I want to reset SPI4_TransferState:
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{
if (hspi->Instance == SPI4)
{
SPI4_TransferState = READY_FOR_TRANSFER;
SPI_ReleaseCSPin(AMPLI_SPI4);
}
}TRANSFER_ONGOING and READY_FOR_TRANSFER are 2 defines that stands for 1 and 0.
If i debug the code I can see that the interrupt is fired and that the instruction
SPI4_TransferState = READY_FOR_TRANSFER;
is executed; anyway the value of SPI4_TransferState does not change from 1 to 0, as if the instruction is doing nothing.
I have done some tests if, anyway, I change the interrupt handler like this:
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{
if (hspi->Instance == SPI4)
{
SPI_Test = TRANSFER_ONGOING;
SPI4_TransferState = READY_FOR_TRANSFER;
SPI_Test = READY_FOR_TRANSFER;
SPI_ReleaseCSPin(AMPLI_SPI4);
}
}where SPI_Test is a variable declared exactly like SPI4_TransferState, both SPI_Test and SPI_TransferState are updated correctly, but obviously this is an unreliable solution which doesn't make much sense.
To give a complete picture:
- All variables are mapped in DTCM RAM, by linker script
- Interrupt handler is in a file called interrupts.c which is mapped in ITCM RAM by linker script
- function to transmit SPI data (HAL_SPI_Transmit_IT) is in a file called SPI.c that executes from FLASH
- My project uses FreeRTOS, but the problem arises in early stage of application when tasks are not even created yet and scheduler hasn't started
MIght it be a cache-coherency problem? I am really clueless, can somebody please help ?
Thanks in advance
