@@ -502,69 +502,68 @@ void spi_deinit(spi_t *obj)
502
502
* @param obj : pointer to spi_t structure
503
503
* @param buffer : tx data to send before reception
504
504
* @param len : length in byte of the data to send and receive
505
- * @param Timeout: Timeout duration in tick
506
505
* @param skipReceive: skip receiving data after transmit or not
507
506
* @retval status of the send operation (0) in case of error
508
507
*/
509
- spi_status_e spi_transfer (spi_t * obj , uint8_t * buffer , uint16_t len ,
510
- uint32_t Timeout , bool skipReceive )
508
+ spi_status_e spi_transfer (spi_t * obj , uint8_t * buffer , uint16_t len , bool skipReceive )
511
509
{
512
510
spi_status_e ret = SPI_OK ;
513
511
uint32_t tickstart , size = len ;
514
512
SPI_TypeDef * _SPI = obj -> handle .Instance ;
515
513
uint8_t * tx_buffer = buffer ;
516
514
517
- if (( len == 0 ) || ( Timeout == 0U ) ) {
518
- return Timeout > 0U ? SPI_ERROR : SPI_TIMEOUT ;
519
- }
520
- tickstart = HAL_GetTick ();
515
+ if (len == 0 ) {
516
+ ret = SPI_ERROR ;
517
+ } else {
518
+ tickstart = HAL_GetTick ();
521
519
522
520
#if defined(SPI_CR2_TSIZE )
523
- /* Start transfer */
524
- LL_SPI_SetTransferSize (_SPI , size );
525
- LL_SPI_Enable (_SPI );
526
- LL_SPI_StartMasterTransfer (_SPI );
521
+ /* Start transfer */
522
+ LL_SPI_SetTransferSize (_SPI , size );
523
+ LL_SPI_Enable (_SPI );
524
+ LL_SPI_StartMasterTransfer (_SPI );
527
525
#endif
528
526
529
- while (size -- ) {
527
+ while (size -- ) {
530
528
#if defined(SPI_SR_TXP )
531
- while (!LL_SPI_IsActiveFlag_TXP (_SPI ));
529
+ while (!LL_SPI_IsActiveFlag_TXP (_SPI ));
532
530
#else
533
- while (!LL_SPI_IsActiveFlag_TXE (_SPI ));
531
+ while (!LL_SPI_IsActiveFlag_TXE (_SPI ));
534
532
#endif
535
- LL_SPI_TransmitData8 (_SPI , * tx_buffer ++ );
533
+ LL_SPI_TransmitData8 (_SPI , * tx_buffer ++ );
536
534
537
- if (!skipReceive ) {
535
+ if (!skipReceive ) {
538
536
#if defined(SPI_SR_RXP )
539
- while (!LL_SPI_IsActiveFlag_RXP (_SPI ));
537
+ while (!LL_SPI_IsActiveFlag_RXP (_SPI ));
540
538
#else
541
- while (!LL_SPI_IsActiveFlag_RXNE (_SPI ));
539
+ while (!LL_SPI_IsActiveFlag_RXNE (_SPI ));
542
540
#endif
543
- * buffer ++ = LL_SPI_ReceiveData8 (_SPI );
544
- }
545
- if ((Timeout != HAL_MAX_DELAY ) && (HAL_GetTick () - tickstart >= Timeout )) {
546
- ret = SPI_TIMEOUT ;
547
- break ;
541
+ * buffer ++ = LL_SPI_ReceiveData8 (_SPI );
542
+ }
543
+ if ((SPI_TRANSFER_TIMEOUT != HAL_MAX_DELAY ) &&
544
+ (HAL_GetTick () - tickstart >= SPI_TRANSFER_TIMEOUT )) {
545
+ ret = SPI_TIMEOUT ;
546
+ break ;
547
+ }
548
548
}
549
- }
550
549
551
550
#if defined(SPI_IFCR_EOTC )
552
- // Add a delay before disabling SPI otherwise last-bit/last-clock may be truncated
553
- // See https://github.com/stm32duino/Arduino_Core_STM32/issues/1294
554
- // Computed delay is half SPI clock
555
- delayMicroseconds (obj -> disable_delay );
556
-
557
- /* Close transfer */
558
- /* Clear flags */
559
- LL_SPI_ClearFlag_EOT (_SPI );
560
- LL_SPI_ClearFlag_TXTF (_SPI );
561
- /* Disable SPI peripheral */
562
- LL_SPI_Disable (_SPI );
551
+ // Add a delay before disabling SPI otherwise last-bit/last-clock may be truncated
552
+ // See https://github.com/stm32duino/Arduino_Core_STM32/issues/1294
553
+ // Computed delay is half SPI clock
554
+ delayMicroseconds (obj -> disable_delay );
555
+
556
+ /* Close transfer */
557
+ /* Clear flags */
558
+ LL_SPI_ClearFlag_EOT (_SPI );
559
+ LL_SPI_ClearFlag_TXTF (_SPI );
560
+ /* Disable SPI peripheral */
561
+ LL_SPI_Disable (_SPI );
563
562
#else
564
- /* Wait for end of transfer */
565
- while (LL_SPI_IsActiveFlag_BSY (_SPI ));
563
+ /* Wait for end of transfer */
564
+ while (LL_SPI_IsActiveFlag_BSY (_SPI ));
566
565
#endif
567
-
566
+ }
568
567
return ret ;
569
568
}
570
569
0 commit comments