Hi,
I added a function to set bits per frame like below and I had an issue the base->TCR value wasn't updated to tempTCR variable value. It didn't happen when program running on NOR flash, but happened only when program running on SDRAM. This issue also seems related to the cache (ICache or DCache). If the cache is disabled then base->TCR is always updated to the tempTCR value. Other workaround was to put __NOP() opcode like code below. Does someone have any idea about this issue?
By the way, LPSPI1_BASE seems address of external memory and I think it should have been declared with volatile, not only the macro but also parameter of the LPSPI functions from SPI driver. Is that okay?
// MIMXRT1062.h
#define LPSPI1_BASE (0x40394000u)
#define LPSPI1 ((LPSPI_Type *)LPSPI1_BASE)
// freertos_lpspi_b2b_master.c
#define EXAMPLE_LPSPI_MASTER_BASEADDR (LPSPI1)
static void LPSPI_MasterSetBitsPerFrame(LPSPI_Type *base, uint32_t bitsPerFrame)
{
/* Set Transmit Command Register*/
uint32_t tempTCR = (base->TCR & (~LPSPI_TCR_FRAMESZ_MASK)) | LPSPI_TCR_FRAMESZ(bitsPerFrame - 1);
base->TCR = tempTCR;
/*TODO: Uncomment __NOP() to workaround an issue that base->TCR isn't updated to tempTCP*/
//__NOP();
if (base->TCR != tempTCR)
{
PRINTF("Error occurred in LPSPI set bit per frame. TCR=%x, Temp=%x, BitsPerFrame=%x\r\n",
base->TCR, tempTCR, LPSPI_TCR_FRAMESZ(bitsPerFrame - 1));
}
else
{
PRINTF("Succeeded to set bit per frame for LPSPI. TCR=%x, Temp=%x, BitsPerFrame=%x\r\n",
base->TCR, tempTCR, LPSPI_TCR_FRAMESZ(bitsPerFrame - 1));
}
}
Information:
- Board: MIMXRT1060-EVK
- SDK: 2.6.2
- Example Project (from SDK): evkmimxrt1060_freertos_lpspi_b2b_master