This is supposed to receive one byte in SPI bidirectional mode ([STM32Cube_FW_L4_V1.5.0]\Drivers\BSP\STM32L476G-Discovery\stm32l476g_discovery.c):
* @brief Receives a Byte from the SPI bus.
* @retval The received byte value
static uint8_t SPIx_Read(void)
while((SpiHandle.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE);
/* read the received data */
receivedbyte = *(__IO uint8_t *)&SpiHandle.Instance->DR;
/* Wait for the BSY flag reset */
while((SpiHandle.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY);
Can ST please comment on:
- Why the #pragma? What in this code is supposed to be not-optimized-out? Would ICC optimize out the repeated __DSB()s (sounds not very plausible but one never knows, I don't have ICC)? How about other compilers?
- Why the 8 __DSB()? Is this supposed to be a time waste? Is there something wrong with __NOP()?
- The check for RXNE and BUSY after __HAL_SPI_DISABLE() indicates that the __DSB()s are intended to provide a way to "start issuing clocks" but disable SPI soon enough so that clocks only for one frame are issued. Correct?
- If above point is true, what if an interrupt happens in middle of the __DSB()s?
- Is the number of __DSB()s dependent on SPI baudrate?
- Where is all this documented in the RM, exactly?