2017-05-02 12:16 AM
Hi,
I use the HAL Library for a STM32L4 MCU clocked at 80MHz. The time between two Bytes are 3us. This is to slow for my Application, but I can not transfer more bytes or use a DMA, because I must react on a Signal from a pin.
for (int i = 2; i < 8; i++)
{ HAL_SPI_TransmitReceive(&hspi1, (uint8_t *)&awTxBuffer[i], (uint8_t *)&awRxBuffer[i], 1, 0x00); while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);// while (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5));}Is there a way to speed up my Application?
Thanks for hints,
Philipp
2017-05-02 01:35 AM
The last Parameter is a timeout, but it seems to be a frame timing parameter. So when I set the SPI clock from 8 to 4 MHz, the GAP between the bytes is 1.67us. At 8 MHz the bytes are faster on the bus, but the GAP is 3us.
2017-05-02 08:48 AM
>>Is there a way to speed up my Application?
Not use HAL, and review the use of the registers more directly.
At the very least inspect the current library source code to understand what it is doing, and where the time might be going.
2017-05-02 09:11 AM
Consider use of Low Level functions, for example:
static uint8_t SPI2_ReadByte (void)
{ uint32_t start_time_r; uint32_t this_time_r;while (LL_SPI_IsActiveFlag_RXNE(SPI2))
{ (void)LL_SPI_ReceiveData8(SPI2); // flush any FIFO content }while (!LL_SPI_IsActiveFlag_TXE(SPI2))
{ ; }start_time_r = HAL_GetTick();
LL_SPI_TransmitData8(SPI2, 0xFF); // send dummy byte while (!LL_SPI_IsActiveFlag_RXNE(SPI2)) { this_time_r = HAL_GetTick() - start_time_r; if (this_time_r > SPI2_READ_TIMEOUT) { // timeout error! break; } }return(LL_SPI_ReceiveData8(SPI2));
}2017-05-09 05:21 AM
Thank you, this was very helpful. It runs 5 times faster.
2017-07-27 11:30 PM
When getting more familiar with the hw peripherals, max average speed can be further improved. Search for Interrupt based state machine, where pseudo program is clocked by interrupt events such as dma or exti.