2017-03-12 04:37 PM
Posted on March 13, 2017 at 00:37
This is supposed to receive one byte in SPI bidirectional mode ([STM32Cube_FW_L4_V1.5.0]\Drivers\BSP\STM32L476G-Discovery\stm32l476g_discovery.c):
&sharpif defined(__ICCARM__)
&sharppragma optimize=none
&sharpendif
/**
* @brief Receives a Byte from the SPI bus.
* @retval The received byte value
*/
static uint8_t SPIx_Read(void)
{
uint8_t receivedbyte;
__HAL_SPI_ENABLE(&SpiHandle);
__DSB();
__DSB();
__DSB();
__DSB();
__DSB();
__DSB();
__DSB();
__DSB();
__HAL_SPI_DISABLE(&SpiHandle);
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);
return receivedbyte;
}
Can ST please comment on:
And while at commenting on STM32 SPI issues, can ST please comment also on
https://community.st.com/message/139780-re-stm32f072-spi-bidirectional-mode-strange-behavior?commentID=139780&et=watches.email.thread&sharpcomment-139780 [linkfix Feb.2019 https://community.st.com/s/question/0D50X00009XkZNhSAN/stm32f072-spi-bidirectional-mode-strange-behavior ]
and
https://community.st.com/0D50X00009XkW6HSAV
and
https://community.st.com/0D50X00009XkaArSAJ
threads?
Thanks,
Jan Waclawek
null
Solved! Go to Solution.
2017-03-23 02:41 AM
Hi
Waclawek.Jan
The pragma has been used to avoid any code optimization, other compilers are missing,this issue has been reported to our team to be considered in next releases.
The use of DSB is recommeded but is the same goal as the NOP.
In this very specific cases SPI is used as master with only one line for TX/RX data, so the reception function want generate only one data clock means partners is able to send only one data a
nd we will a new data clock to send the next data.
Right this is missing ,we maybe must disable IRQ depending application,
this issue has been reported
to our team for checking .
Yes, the number of DSB is SPI baud-rate dependent and the baudrate itself is CLK dependent so the number of DSB is system dependent.
(The sequence provided is really specific to this mode (where we are transferring the data one by one)
-Nesrine-
2017-03-13 03:37 AM
Hi
Waclawek.Jan
,Thank you very much for your contribution to the enhancement of our STM32 related solutions.
I am checking your questions and comments. Please be patient,I will come back to you.
-Nesrine-
2017-03-23 02:41 AM
Hi
Waclawek.Jan
The pragma has been used to avoid any code optimization, other compilers are missing,this issue has been reported to our team to be considered in next releases.
The use of DSB is recommeded but is the same goal as the NOP.
In this very specific cases SPI is used as master with only one line for TX/RX data, so the reception function want generate only one data clock means partners is able to send only one data a
nd we will a new data clock to send the next data.
Right this is missing ,we maybe must disable IRQ depending application,
this issue has been reported
to our team for checking .
Yes, the number of DSB is SPI baud-rate dependent and the baudrate itself is CLK dependent so the number of DSB is system dependent.
(The sequence provided is really specific to this mode (where we are transferring the data one by one)
-Nesrine-
2017-03-23 02:21 PM
Nesrine,
Thanks for the detailed answer.
While I understand the reason, I am not happy with a software delay which is aimed not only at providing a minimal delay, but to fit into a timing window. This could be concocted into a more controlled sequence with a timer-triggered DMA ... I'll try and report if time permits.
we maybe must disable IRQ depending application,
While I agree that the particular requirements on this delay depend on the application, this code is supposed to be one of the few examples (if not the only one) demonstrating bidirectional transfer on SPI. I'd recommend to add a comment, both explaining the reason for the delay, the calculation of its duration, and the need for disabling/reenabling IRQ where appropriate.
My 2c... :)
Thanks again,
Jan