Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 6 | ||
|---|---|---|---|
| Line 56... | Line 56... | ||
| 56 | bidirectional receive mode (MSTR=1, BIDIMODE=1, BIDIOE=0), to ensure that the SPI |
56 | bidirectional receive mode (MSTR=1, BIDIMODE=1, BIDIOE=0), to ensure that the SPI |
| 57 | does not initiate a new transfer the following procedure has to be respected: |
57 | does not initiate a new transfer the following procedure has to be respected: |
| 58 | (##) HAL_SPI_DeInit() |
58 | (##) HAL_SPI_DeInit() |
| 59 | (##) HAL_SPI_Init() |
59 | (##) HAL_SPI_Init() |
| 60 | [..] |
60 | [..] |
| 61 | Data buffer address alignment restriction: |
- | |
| 62 | (#) In case more than 1 byte is requested to be transferred, the HAL SPI uses 16-bit access for data buffer. |
- | |
| 63 | But there is no support for unaligned accesses on the Cortex-M0 processor. |
- | |
| 64 | So, if the user wants to transfer more than 1 byte, it shall ensure that 16-bit aligned address is used for: |
- | |
| 65 | (##) pData parameter in HAL_SPI_Transmit(), HAL_SPI_Transmit_IT(), HAL_SPI_Receive() and HAL_SPI_Receive_IT() |
- | |
| 66 | (##) pTxData and pRxData parameters in HAL_SPI_TransmitReceive() and HAL_SPI_TransmitReceive_IT() |
- | |
| 67 | (#) There is no such restriction when going through DMA by using HAL_SPI_Transmit_DMA(), HAL_SPI_Receive_DMA() |
- | |
| 68 | and HAL_SPI_TransmitReceive_DMA(). |
- | |
| 69 | [..] |
- | |
| 70 | Callback registration: |
61 | Callback registration: |
| 71 | 62 | ||
| 72 | (#) The compilation flag USE_HAL_SPI_REGISTER_CALLBACKS when set to 1U |
63 | (#) The compilation flag USE_HAL_SPI_REGISTER_CALLBACKS when set to 1U |
| 73 | allows the user to configure dynamically the driver callbacks. |
64 | allows the user to configure dynamically the driver callbacks. |
| 74 | Use Functions HAL_SPI_RegisterCallback() to register an interrupt callback. |
65 | Use Functions HAL_SPI_RegisterCallback() to register an interrupt callback. |
| Line 138... | Line 129... | ||
| 138 | Additional table : |
129 | Additional table : |
| 139 | 130 | ||
| 140 | DataSize = SPI_DATASIZE_8BIT: |
131 | DataSize = SPI_DATASIZE_8BIT: |
| 141 | +----------------------------------------------------------------------------------------------+ |
132 | +----------------------------------------------------------------------------------------------+ |
| 142 | | | | 2Lines Fullduplex | 2Lines RxOnly | 1Line | |
133 | | | | 2Lines Fullduplex | 2Lines RxOnly | 1Line | |
| 143 | | Process | Tranfert mode |---------------------|----------------------|----------------------| |
134 | | Process | Transfer mode |---------------------|----------------------|----------------------| |
| 144 | | | | Master | Slave | Master | Slave | Master | Slave | |
135 | | | | Master | Slave | Master | Slave | Master | Slave | |
| 145 | |==============================================================================================| |
136 | |==============================================================================================| |
| 146 | | T | Polling | Fpclk/4 | Fpclk/8 | NA | NA | NA | NA | |
137 | | T | Polling | Fpclk/4 | Fpclk/8 | NA | NA | NA | NA | |
| 147 | | X |----------------|----------|----------|-----------|----------|-----------|----------| |
138 | | X |----------------|----------|----------|-----------|----------|-----------|----------| |
| 148 | | / | Interrupt | Fpclk/4 | Fpclk/16 | NA | NA | NA | NA | |
139 | | / | Interrupt | Fpclk/4 | Fpclk/16 | NA | NA | NA | NA | |
| Line 163... | Line 154... | ||
| 163 | +----------------------------------------------------------------------------------------------+ |
154 | +----------------------------------------------------------------------------------------------+ |
| 164 | 155 | ||
| 165 | DataSize = SPI_DATASIZE_16BIT: |
156 | DataSize = SPI_DATASIZE_16BIT: |
| 166 | +----------------------------------------------------------------------------------------------+ |
157 | +----------------------------------------------------------------------------------------------+ |
| 167 | | | | 2Lines Fullduplex | 2Lines RxOnly | 1Line | |
158 | | | | 2Lines Fullduplex | 2Lines RxOnly | 1Line | |
| 168 | | Process | Tranfert mode |---------------------|----------------------|----------------------| |
159 | | Process | Transfer mode |---------------------|----------------------|----------------------| |
| 169 | | | | Master | Slave | Master | Slave | Master | Slave | |
160 | | | | Master | Slave | Master | Slave | Master | Slave | |
| 170 | |==============================================================================================| |
161 | |==============================================================================================| |
| 171 | | T | Polling | Fpclk/4 | Fpclk/8 | NA | NA | NA | NA | |
162 | | T | Polling | Fpclk/4 | Fpclk/8 | NA | NA | NA | NA | |
| 172 | | X |----------------|----------|----------|-----------|----------|-----------|----------| |
163 | | X |----------------|----------|----------|-----------|----------|-----------|----------| |
| 173 | | / | Interrupt | Fpclk/4 | Fpclk/16 | NA | NA | NA | NA | |
164 | | / | Interrupt | Fpclk/4 | Fpclk/16 | NA | NA | NA | NA | |
| Line 344... | Line 335... | ||
| 344 | assert_param(IS_SPI_TIMODE(hspi->Init.TIMode)); |
335 | assert_param(IS_SPI_TIMODE(hspi->Init.TIMode)); |
| 345 | if (hspi->Init.TIMode == SPI_TIMODE_DISABLE) |
336 | if (hspi->Init.TIMode == SPI_TIMODE_DISABLE) |
| 346 | { |
337 | { |
| 347 | assert_param(IS_SPI_CPOL(hspi->Init.CLKPolarity)); |
338 | assert_param(IS_SPI_CPOL(hspi->Init.CLKPolarity)); |
| 348 | assert_param(IS_SPI_CPHA(hspi->Init.CLKPhase)); |
339 | assert_param(IS_SPI_CPHA(hspi->Init.CLKPhase)); |
| - | 340 | ||
| - | 341 | if (hspi->Init.Mode == SPI_MODE_MASTER) |
|
| - | 342 | { |
|
| - | 343 | assert_param(IS_SPI_BAUDRATE_PRESCALER(hspi->Init.BaudRatePrescaler)); |
|
| - | 344 | } |
|
| - | 345 | else |
|
| - | 346 | { |
|
| - | 347 | /* Baudrate prescaler not use in Motoraola Slave mode. force to default value */ |
|
| - | 348 | hspi->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; |
|
| - | 349 | } |
|
| - | 350 | } |
|
| - | 351 | else |
|
| - | 352 | { |
|
| - | 353 | assert_param(IS_SPI_BAUDRATE_PRESCALER(hspi->Init.BaudRatePrescaler)); |
|
| - | 354 | ||
| - | 355 | /* Force polarity and phase to TI protocaol requirements */ |
|
| - | 356 | hspi->Init.CLKPolarity = SPI_POLARITY_LOW; |
|
| - | 357 | hspi->Init.CLKPhase = SPI_PHASE_1EDGE; |
|
| 349 | } |
358 | } |
| 350 | #if (USE_SPI_CRC != 0U) |
359 | #if (USE_SPI_CRC != 0U) |
| 351 | assert_param(IS_SPI_CRC_CALCULATION(hspi->Init.CRCCalculation)); |
360 | assert_param(IS_SPI_CRC_CALCULATION(hspi->Init.CRCCalculation)); |
| 352 | if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE) |
361 | if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE) |
| 353 | { |
362 | { |
| Line 407... | Line 416... | ||
| 407 | { |
416 | { |
| 408 | /* CRC must be disabled */ |
417 | /* CRC must be disabled */ |
| 409 | hspi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
418 | hspi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
| 410 | } |
419 | } |
| 411 | 420 | ||
| 412 | /* Align the CRC Length on the data size */ |
- | |
| 413 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_DATASIZE) |
- | |
| 414 | { |
- | |
| 415 | /* CRC Length aligned on the data size : value set by default */ |
- | |
| 416 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
- | |
| 417 | { |
- | |
| 418 | hspi->Init.CRCLength = SPI_CRC_LENGTH_16BIT; |
- | |
| 419 | } |
- | |
| 420 | else |
- | |
| 421 | { |
- | |
| 422 | hspi->Init.CRCLength = SPI_CRC_LENGTH_8BIT; |
- | |
| 423 | } |
- | |
| 424 | } |
- | |
| 425 | - | ||
| 426 | /*----------------------- SPIx CR1 & CR2 Configuration ---------------------*/ |
421 | /*----------------------- SPIx CR1 & CR2 Configuration ---------------------*/ |
| 427 | /* Configure : SPI Mode, Communication Mode, Clock polarity and phase, NSS management, |
422 | /* Configure : SPI Mode, Communication Mode, Clock polarity and phase, NSS management, |
| 428 | Communication speed, First bit and CRC calculation state */ |
423 | Communication speed, First bit and CRC calculation state */ |
| 429 | WRITE_REG(hspi->Instance->CR1, (hspi->Init.Mode | hspi->Init.Direction | |
424 | WRITE_REG(hspi->Instance->CR1, ((hspi->Init.Mode & (SPI_CR1_MSTR | SPI_CR1_SSI)) | |
| - | 425 | (hspi->Init.Direction & (SPI_CR1_RXONLY | SPI_CR1_BIDIMODE)) | |
|
| 430 | hspi->Init.CLKPolarity | hspi->Init.CLKPhase | (hspi->Init.NSS & SPI_CR1_SSM) | |
426 | (hspi->Init.CLKPolarity & SPI_CR1_CPOL) | |
| - | 427 | (hspi->Init.CLKPhase & SPI_CR1_CPHA) | |
|
| - | 428 | (hspi->Init.NSS & SPI_CR1_SSM) | |
|
| 431 | hspi->Init.BaudRatePrescaler | hspi->Init.FirstBit | hspi->Init.CRCCalculation)); |
429 | (hspi->Init.BaudRatePrescaler & SPI_CR1_BR_Msk) | |
| - | 430 | (hspi->Init.FirstBit & SPI_CR1_LSBFIRST) | |
|
| - | 431 | (hspi->Init.CRCCalculation & SPI_CR1_CRCEN))); |
|
| 432 | #if (USE_SPI_CRC != 0U) |
432 | #if (USE_SPI_CRC != 0U) |
| 433 | /* Configure : CRC Length */ |
433 | /*---------------------------- SPIx CRCL Configuration -------------------*/ |
| 434 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT) |
434 | if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE) |
| 435 | { |
435 | { |
| - | 436 | /* Align the CRC Length on the data size */ |
|
| - | 437 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_DATASIZE) |
|
| - | 438 | { |
|
| - | 439 | /* CRC Length aligned on the data size : value set by default */ |
|
| - | 440 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
|
| - | 441 | { |
|
| - | 442 | hspi->Init.CRCLength = SPI_CRC_LENGTH_16BIT; |
|
| - | 443 | } |
|
| - | 444 | else |
|
| - | 445 | { |
|
| - | 446 | hspi->Init.CRCLength = SPI_CRC_LENGTH_8BIT; |
|
| - | 447 | } |
|
| - | 448 | } |
|
| - | 449 | ||
| - | 450 | /* Configure : CRC Length */ |
|
| - | 451 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT) |
|
| - | 452 | { |
|
| 436 | hspi->Instance->CR1 |= SPI_CR1_CRCL; |
453 | SET_BIT(hspi->Instance->CR1, SPI_CR1_CRCL); |
| - | 454 | } |
|
| 437 | } |
455 | } |
| 438 | #endif /* USE_SPI_CRC */ |
456 | #endif /* USE_SPI_CRC */ |
| 439 | 457 | ||
| 440 | /* Configure : NSS management, TI Mode, NSS Pulse, Data size and Rx Fifo threshold */ |
458 | /* Configure : NSS management, TI Mode, NSS Pulse, Data size and Rx Fifo threshold */ |
| 441 | WRITE_REG(hspi->Instance->CR2, (((hspi->Init.NSS >> 16U) & SPI_CR2_SSOE) | hspi->Init.TIMode | |
459 | WRITE_REG(hspi->Instance->CR2, (((hspi->Init.NSS >> 16U) & SPI_CR2_SSOE) | |
| - | 460 | (hspi->Init.TIMode & SPI_CR2_FRF) | |
|
| 442 | hspi->Init.NSSPMode | hspi->Init.DataSize) | frxth); |
461 | (hspi->Init.NSSPMode & SPI_CR2_NSSP) | |
| - | 462 | (hspi->Init.DataSize & SPI_CR2_DS_Msk) | |
|
| - | 463 | (frxth & SPI_CR2_FRXTH))); |
|
| 443 | 464 | ||
| 444 | #if (USE_SPI_CRC != 0U) |
465 | #if (USE_SPI_CRC != 0U) |
| 445 | /*---------------------------- SPIx CRCPOLY Configuration ------------------*/ |
466 | /*---------------------------- SPIx CRCPOLY Configuration ------------------*/ |
| 446 | /* Configure : CRC Polynomial */ |
467 | /* Configure : CRC Polynomial */ |
| 447 | if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE) |
468 | if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE) |
| 448 | { |
469 | { |
| 449 | WRITE_REG(hspi->Instance->CRCPR, hspi->Init.CRCPolynomial); |
470 | WRITE_REG(hspi->Instance->CRCPR, (hspi->Init.CRCPolynomial & SPI_CRCPR_CRCPOLY_Msk)); |
| 450 | } |
471 | } |
| 451 | #endif /* USE_SPI_CRC */ |
472 | #endif /* USE_SPI_CRC */ |
| 452 | 473 | ||
| 453 | #if defined(SPI_I2SCFGR_I2SMOD) |
474 | #if defined(SPI_I2SCFGR_I2SMOD) |
| 454 | /* Activate the SPI mode (Make sure that I2SMOD bit in I2SCFGR register is reset) */ |
475 | /* Activate the SPI mode (Make sure that I2SMOD bit in I2SCFGR register is reset) */ |
| Line 803... | Line 824... | ||
| 803 | { |
824 | { |
| 804 | uint32_t tickstart; |
825 | uint32_t tickstart; |
| 805 | HAL_StatusTypeDef errorcode = HAL_OK; |
826 | HAL_StatusTypeDef errorcode = HAL_OK; |
| 806 | uint16_t initial_TxXferCount; |
827 | uint16_t initial_TxXferCount; |
| 807 | 828 | ||
| 808 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || ((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (Size > 1U))) |
- | |
| 809 | { |
- | |
| 810 | /* in this case, 16-bit access is performed on Data |
- | |
| 811 | So, check Data is 16-bit aligned address */ |
- | |
| 812 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pData)); |
- | |
| 813 | } |
- | |
| 814 | - | ||
| 815 | /* Check Direction parameter */ |
829 | /* Check Direction parameter */ |
| 816 | assert_param(IS_SPI_DIRECTION_2LINES_OR_1LINE(hspi->Init.Direction)); |
830 | assert_param(IS_SPI_DIRECTION_2LINES_OR_1LINE(hspi->Init.Direction)); |
| 817 | 831 | ||
| 818 | /* Process Locked */ |
832 | /* Process Locked */ |
| 819 | __HAL_LOCK(hspi); |
833 | __HAL_LOCK(hspi); |
| Line 849... | Line 863... | ||
| 849 | hspi->RxISR = NULL; |
863 | hspi->RxISR = NULL; |
| 850 | 864 | ||
| 851 | /* Configure communication direction : 1Line */ |
865 | /* Configure communication direction : 1Line */ |
| 852 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
866 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| 853 | { |
867 | { |
| - | 868 | /* Disable SPI Peripheral before set 1Line direction (BIDIOE bit) */ |
|
| - | 869 | __HAL_SPI_DISABLE(hspi); |
|
| 854 | SPI_1LINE_TX(hspi); |
870 | SPI_1LINE_TX(hspi); |
| 855 | } |
871 | } |
| 856 | 872 | ||
| 857 | #if (USE_SPI_CRC != 0U) |
873 | #if (USE_SPI_CRC != 0U) |
| 858 | /* Reset CRC Calculation */ |
874 | /* Reset CRC Calculation */ |
| Line 902... | Line 918... | ||
| 902 | /* Transmit data in 8 Bit mode */ |
918 | /* Transmit data in 8 Bit mode */ |
| 903 | else |
919 | else |
| 904 | { |
920 | { |
| 905 | if ((hspi->Init.Mode == SPI_MODE_SLAVE) || (initial_TxXferCount == 0x01U)) |
921 | if ((hspi->Init.Mode == SPI_MODE_SLAVE) || (initial_TxXferCount == 0x01U)) |
| 906 | { |
922 | { |
| 907 | if (hspi->TxXferCount > 1U) |
- | |
| 908 | { |
- | |
| 909 | /* write on the data register in packing mode */ |
- | |
| 910 | hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr); |
- | |
| 911 | hspi->pTxBuffPtr += sizeof(uint16_t); |
- | |
| 912 | hspi->TxXferCount -= 2U; |
- | |
| 913 | } |
- | |
| 914 | else |
- | |
| 915 | { |
- | |
| 916 | *((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr); |
923 | *((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr); |
| 917 | hspi->pTxBuffPtr ++; |
924 | hspi->pTxBuffPtr += sizeof(uint8_t); |
| 918 | hspi->TxXferCount--; |
925 | hspi->TxXferCount--; |
| 919 | } |
- | |
| 920 | } |
926 | } |
| 921 | while (hspi->TxXferCount > 0U) |
927 | while (hspi->TxXferCount > 0U) |
| 922 | { |
928 | { |
| 923 | /* Wait until TXE flag is set to send data */ |
929 | /* Wait until TXE flag is set to send data */ |
| 924 | if (__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_TXE)) |
930 | if (__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_TXE)) |
| 925 | { |
931 | { |
| 926 | if (hspi->TxXferCount > 1U) |
- | |
| 927 | { |
- | |
| 928 | /* write on the data register in packing mode */ |
- | |
| 929 | hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr); |
932 | *((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr); |
| 930 | hspi->pTxBuffPtr += sizeof(uint16_t); |
933 | hspi->pTxBuffPtr += sizeof(uint8_t); |
| 931 | hspi->TxXferCount -= 2U; |
- | |
| 932 | } |
- | |
| 933 | else |
- | |
| 934 | { |
- | |
| 935 | *((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr); |
- | |
| 936 | hspi->pTxBuffPtr++; |
- | |
| 937 | hspi->TxXferCount--; |
934 | hspi->TxXferCount--; |
| 938 | } |
- | |
| 939 | } |
935 | } |
| 940 | else |
936 | else |
| 941 | { |
937 | { |
| 942 | /* Timeout management */ |
938 | /* Timeout management */ |
| 943 | if ((((HAL_GetTick() - tickstart) >= Timeout) && (Timeout != HAL_MAX_DELAY)) || (Timeout == 0U)) |
939 | if ((((HAL_GetTick() - tickstart) >= Timeout) && (Timeout != HAL_MAX_DELAY)) || (Timeout == 0U)) |
| Line 989... | Line 985... | ||
| 989 | * @param Timeout Timeout duration |
985 | * @param Timeout Timeout duration |
| 990 | * @retval HAL status |
986 | * @retval HAL status |
| 991 | */ |
987 | */ |
| 992 | HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
988 | HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
| 993 | { |
989 | { |
| - | 990 | #if (USE_SPI_CRC != 0U) |
|
| - | 991 | __IO uint32_t tmpreg = 0U; |
|
| - | 992 | __IO uint8_t * ptmpreg8; |
|
| - | 993 | __IO uint8_t tmpreg8 = 0; |
|
| - | 994 | #endif /* USE_SPI_CRC */ |
|
| 994 | uint32_t tickstart; |
995 | uint32_t tickstart; |
| 995 | HAL_StatusTypeDef errorcode = HAL_OK; |
996 | HAL_StatusTypeDef errorcode = HAL_OK; |
| 996 | 997 | ||
| 997 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || ((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (Size > 1U))) |
- | |
| 998 | { |
- | |
| 999 | /* in this case, 16-bit access is performed on Data |
- | |
| 1000 | So, check Data is 16-bit aligned address */ |
- | |
| 1001 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pData)); |
- | |
| 1002 | } |
- | |
| 1003 | - | ||
| 1004 | if ((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES)) |
998 | if ((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES)) |
| 1005 | { |
999 | { |
| 1006 | hspi->State = HAL_SPI_STATE_BUSY_RX; |
1000 | hspi->State = HAL_SPI_STATE_BUSY_RX; |
| 1007 | /* Call transmit-receive function to send Dummy data on Tx line and generate clock on CLK line */ |
1001 | /* Call transmit-receive function to send Dummy data on Tx line and generate clock on CLK line */ |
| 1008 | return HAL_SPI_TransmitReceive(hspi, pData, pData, Size, Timeout); |
1002 | return HAL_SPI_TransmitReceive(hspi, pData, pData, Size, Timeout); |
| Line 1063... | Line 1057... | ||
| 1063 | } |
1057 | } |
| 1064 | 1058 | ||
| 1065 | /* Configure communication direction: 1Line */ |
1059 | /* Configure communication direction: 1Line */ |
| 1066 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
1060 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| 1067 | { |
1061 | { |
| - | 1062 | /* Disable SPI Peripheral before set 1Line direction (BIDIOE bit) */ |
|
| - | 1063 | __HAL_SPI_DISABLE(hspi); |
|
| 1068 | SPI_1LINE_RX(hspi); |
1064 | SPI_1LINE_RX(hspi); |
| 1069 | } |
1065 | } |
| 1070 | 1066 | ||
| 1071 | /* Check if the SPI is already enabled */ |
1067 | /* Check if the SPI is already enabled */ |
| 1072 | if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE) |
1068 | if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE) |
| Line 1160... | Line 1156... | ||
| 1160 | 1156 | ||
| 1161 | /* Read CRC to Flush DR and RXNE flag */ |
1157 | /* Read CRC to Flush DR and RXNE flag */ |
| 1162 | if (hspi->Init.DataSize == SPI_DATASIZE_16BIT) |
1158 | if (hspi->Init.DataSize == SPI_DATASIZE_16BIT) |
| 1163 | { |
1159 | { |
| 1164 | /* Read 16bit CRC */ |
1160 | /* Read 16bit CRC */ |
| 1165 | READ_REG(hspi->Instance->DR); |
1161 | tmpreg = READ_REG(hspi->Instance->DR); |
| - | 1162 | /* To avoid GCC warning */ |
|
| - | 1163 | UNUSED(tmpreg); |
|
| 1166 | } |
1164 | } |
| 1167 | else |
1165 | else |
| 1168 | { |
1166 | { |
| - | 1167 | /* Initialize the 8bit temporary pointer */ |
|
| - | 1168 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
|
| 1169 | /* Read 8bit CRC */ |
1169 | /* Read 8bit CRC */ |
| - | 1170 | tmpreg8 = *ptmpreg8; |
|
| 1170 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
1171 | /* To avoid GCC warning */ |
| - | 1172 | UNUSED(tmpreg8); |
|
| 1171 | 1173 | ||
| 1172 | if ((hspi->Init.DataSize == SPI_DATASIZE_8BIT) && (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT)) |
1174 | if ((hspi->Init.DataSize == SPI_DATASIZE_8BIT) && (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT)) |
| 1173 | { |
1175 | { |
| 1174 | if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SET, Timeout, tickstart) != HAL_OK) |
1176 | if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SET, Timeout, tickstart) != HAL_OK) |
| 1175 | { |
1177 | { |
| Line 1177... | Line 1179... | ||
| 1177 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
1179 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
| 1178 | errorcode = HAL_TIMEOUT; |
1180 | errorcode = HAL_TIMEOUT; |
| 1179 | goto error; |
1181 | goto error; |
| 1180 | } |
1182 | } |
| 1181 | /* Read 8bit CRC again in case of 16bit CRC in 8bit Data mode */ |
1183 | /* Read 8bit CRC again in case of 16bit CRC in 8bit Data mode */ |
| - | 1184 | tmpreg8 = *ptmpreg8; |
|
| 1182 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
1185 | /* To avoid GCC warning */ |
| - | 1186 | UNUSED(tmpreg8); |
|
| 1183 | } |
1187 | } |
| 1184 | } |
1188 | } |
| 1185 | } |
1189 | } |
| 1186 | #endif /* USE_SPI_CRC */ |
1190 | #endif /* USE_SPI_CRC */ |
| 1187 | 1191 | ||
| Line 1223... | Line 1227... | ||
| 1223 | */ |
1227 | */ |
| 1224 | HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, |
1228 | HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, |
| 1225 | uint32_t Timeout) |
1229 | uint32_t Timeout) |
| 1226 | { |
1230 | { |
| 1227 | uint16_t initial_TxXferCount; |
1231 | uint16_t initial_TxXferCount; |
| 1228 | uint16_t initial_RxXferCount; |
- | |
| 1229 | uint32_t tmp_mode; |
1232 | uint32_t tmp_mode; |
| 1230 | HAL_SPI_StateTypeDef tmp_state; |
1233 | HAL_SPI_StateTypeDef tmp_state; |
| 1231 | uint32_t tickstart; |
1234 | uint32_t tickstart; |
| 1232 | #if (USE_SPI_CRC != 0U) |
1235 | #if (USE_SPI_CRC != 0U) |
| - | 1236 | __IO uint32_t tmpreg = 0U; |
|
| 1233 | uint32_t spi_cr1; |
1237 | uint32_t spi_cr1; |
| 1234 | uint32_t spi_cr2; |
1238 | uint32_t spi_cr2; |
| - | 1239 | __IO uint8_t * ptmpreg8; |
|
| - | 1240 | __IO uint8_t tmpreg8 = 0; |
|
| 1235 | #endif /* USE_SPI_CRC */ |
1241 | #endif /* USE_SPI_CRC */ |
| 1236 | 1242 | ||
| 1237 | /* Variable used to alternate Rx and Tx during transfer */ |
1243 | /* Variable used to alternate Rx and Tx during transfer */ |
| 1238 | uint32_t txallowed = 1U; |
1244 | uint32_t txallowed = 1U; |
| 1239 | HAL_StatusTypeDef errorcode = HAL_OK; |
1245 | HAL_StatusTypeDef errorcode = HAL_OK; |
| 1240 | 1246 | ||
| 1241 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || ((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (Size > 1U))) |
- | |
| 1242 | { |
- | |
| 1243 | /* in this case, 16-bit access is performed on Data |
- | |
| 1244 | So, check Data is 16-bit aligned address */ |
- | |
| 1245 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pTxData)); |
- | |
| 1246 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pRxData)); |
- | |
| 1247 | } |
- | |
| 1248 | - | ||
| 1249 | /* Check Direction parameter */ |
1247 | /* Check Direction parameter */ |
| 1250 | assert_param(IS_SPI_DIRECTION_2LINES(hspi->Init.Direction)); |
1248 | assert_param(IS_SPI_DIRECTION_2LINES(hspi->Init.Direction)); |
| 1251 | 1249 | ||
| 1252 | /* Process Locked */ |
1250 | /* Process Locked */ |
| 1253 | __HAL_LOCK(hspi); |
1251 | __HAL_LOCK(hspi); |
| Line 1257... | Line 1255... | ||
| 1257 | 1255 | ||
| 1258 | /* Init temporary variables */ |
1256 | /* Init temporary variables */ |
| 1259 | tmp_state = hspi->State; |
1257 | tmp_state = hspi->State; |
| 1260 | tmp_mode = hspi->Init.Mode; |
1258 | tmp_mode = hspi->Init.Mode; |
| 1261 | initial_TxXferCount = Size; |
1259 | initial_TxXferCount = Size; |
| 1262 | initial_RxXferCount = Size; |
- | |
| 1263 | #if (USE_SPI_CRC != 0U) |
1260 | #if (USE_SPI_CRC != 0U) |
| 1264 | spi_cr1 = READ_REG(hspi->Instance->CR1); |
1261 | spi_cr1 = READ_REG(hspi->Instance->CR1); |
| 1265 | spi_cr2 = READ_REG(hspi->Instance->CR2); |
1262 | spi_cr2 = READ_REG(hspi->Instance->CR2); |
| 1266 | #endif /* USE_SPI_CRC */ |
1263 | #endif /* USE_SPI_CRC */ |
| 1267 | 1264 | ||
| Line 1304... | Line 1301... | ||
| 1304 | SPI_RESET_CRC(hspi); |
1301 | SPI_RESET_CRC(hspi); |
| 1305 | } |
1302 | } |
| 1306 | #endif /* USE_SPI_CRC */ |
1303 | #endif /* USE_SPI_CRC */ |
| 1307 | 1304 | ||
| 1308 | /* Set the Rx Fifo threshold */ |
1305 | /* Set the Rx Fifo threshold */ |
| 1309 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || (initial_RxXferCount > 1U)) |
1306 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
| 1310 | { |
1307 | { |
| 1311 | /* Set fiforxthreshold according the reception data length: 16bit */ |
1308 | /* Set fiforxthreshold according the reception data length: 16bit */ |
| 1312 | CLEAR_BIT(hspi->Instance->CR2, SPI_RXFIFO_THRESHOLD); |
1309 | CLEAR_BIT(hspi->Instance->CR2, SPI_RXFIFO_THRESHOLD); |
| 1313 | } |
1310 | } |
| 1314 | else |
1311 | else |
| Line 1377... | Line 1374... | ||
| 1377 | /* Transmit and Receive data in 8 Bit mode */ |
1374 | /* Transmit and Receive data in 8 Bit mode */ |
| 1378 | else |
1375 | else |
| 1379 | { |
1376 | { |
| 1380 | if ((hspi->Init.Mode == SPI_MODE_SLAVE) || (initial_TxXferCount == 0x01U)) |
1377 | if ((hspi->Init.Mode == SPI_MODE_SLAVE) || (initial_TxXferCount == 0x01U)) |
| 1381 | { |
1378 | { |
| 1382 | if (hspi->TxXferCount > 1U) |
- | |
| 1383 | { |
- | |
| 1384 | hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr); |
1379 | *((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr); |
| 1385 | hspi->pTxBuffPtr += sizeof(uint16_t); |
1380 | hspi->pTxBuffPtr += sizeof(uint8_t); |
| 1386 | hspi->TxXferCount -= 2U; |
- | |
| 1387 | } |
- | |
| 1388 | else |
- | |
| 1389 | { |
- | |
| 1390 | *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr); |
- | |
| 1391 | hspi->pTxBuffPtr++; |
- | |
| 1392 | hspi->TxXferCount--; |
1381 | hspi->TxXferCount--; |
| 1393 | } |
- | |
| 1394 | } |
1382 | } |
| 1395 | while ((hspi->TxXferCount > 0U) || (hspi->RxXferCount > 0U)) |
1383 | while ((hspi->TxXferCount > 0U) || (hspi->RxXferCount > 0U)) |
| 1396 | { |
1384 | { |
| 1397 | /* Check TXE flag */ |
1385 | /* Check TXE flag */ |
| 1398 | if ((__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_TXE)) && (hspi->TxXferCount > 0U) && (txallowed == 1U)) |
1386 | if ((__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_TXE)) && (hspi->TxXferCount > 0U) && (txallowed == 1U)) |
| 1399 | { |
1387 | { |
| 1400 | if (hspi->TxXferCount > 1U) |
- | |
| 1401 | { |
- | |
| 1402 | hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr); |
- | |
| 1403 | hspi->pTxBuffPtr += sizeof(uint16_t); |
- | |
| 1404 | hspi->TxXferCount -= 2U; |
- | |
| 1405 | } |
- | |
| 1406 | else |
- | |
| 1407 | { |
- | |
| 1408 | *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr); |
1388 | *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr); |
| 1409 | hspi->pTxBuffPtr++; |
1389 | hspi->pTxBuffPtr++; |
| 1410 | hspi->TxXferCount--; |
1390 | hspi->TxXferCount--; |
| 1411 | } |
- | |
| 1412 | /* Next Data is a reception (Rx). Tx not allowed */ |
1391 | /* Next Data is a reception (Rx). Tx not allowed */ |
| 1413 | txallowed = 0U; |
1392 | txallowed = 0U; |
| 1414 | 1393 | ||
| 1415 | #if (USE_SPI_CRC != 0U) |
1394 | #if (USE_SPI_CRC != 0U) |
| 1416 | /* Enable CRC Transmission */ |
1395 | /* Enable CRC Transmission */ |
| Line 1427... | Line 1406... | ||
| 1427 | } |
1406 | } |
| 1428 | 1407 | ||
| 1429 | /* Wait until RXNE flag is reset */ |
1408 | /* Wait until RXNE flag is reset */ |
| 1430 | if ((__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_RXNE)) && (hspi->RxXferCount > 0U)) |
1409 | if ((__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_RXNE)) && (hspi->RxXferCount > 0U)) |
| 1431 | { |
1410 | { |
| 1432 | if (hspi->RxXferCount > 1U) |
- | |
| 1433 | { |
- | |
| 1434 | *((uint16_t *)hspi->pRxBuffPtr) = (uint16_t)hspi->Instance->DR; |
- | |
| 1435 | hspi->pRxBuffPtr += sizeof(uint16_t); |
- | |
| 1436 | hspi->RxXferCount -= 2U; |
- | |
| 1437 | if (hspi->RxXferCount <= 1U) |
- | |
| 1438 | { |
- | |
| 1439 | /* Set RX Fifo threshold before to switch on 8 bit data size */ |
- | |
| 1440 | SET_BIT(hspi->Instance->CR2, SPI_RXFIFO_THRESHOLD); |
- | |
| 1441 | } |
- | |
| 1442 | } |
- | |
| 1443 | else |
- | |
| 1444 | { |
- | |
| 1445 | (*(uint8_t *)hspi->pRxBuffPtr) = *(__IO uint8_t *)&hspi->Instance->DR; |
1411 | (*(uint8_t *)hspi->pRxBuffPtr) = *(__IO uint8_t *)&hspi->Instance->DR; |
| 1446 | hspi->pRxBuffPtr++; |
1412 | hspi->pRxBuffPtr++; |
| 1447 | hspi->RxXferCount--; |
1413 | hspi->RxXferCount--; |
| 1448 | } |
- | |
| 1449 | /* Next Data is a Transmission (Tx). Tx is allowed */ |
1414 | /* Next Data is a Transmission (Tx). Tx is allowed */ |
| 1450 | txallowed = 1U; |
1415 | txallowed = 1U; |
| 1451 | } |
1416 | } |
| 1452 | if ((((HAL_GetTick() - tickstart) >= Timeout) && ((Timeout != HAL_MAX_DELAY))) || (Timeout == 0U)) |
1417 | if ((((HAL_GetTick() - tickstart) >= Timeout) && ((Timeout != HAL_MAX_DELAY))) || (Timeout == 0U)) |
| 1453 | { |
1418 | { |
| Line 1471... | Line 1436... | ||
| 1471 | } |
1436 | } |
| 1472 | /* Read CRC */ |
1437 | /* Read CRC */ |
| 1473 | if (hspi->Init.DataSize == SPI_DATASIZE_16BIT) |
1438 | if (hspi->Init.DataSize == SPI_DATASIZE_16BIT) |
| 1474 | { |
1439 | { |
| 1475 | /* Read 16bit CRC */ |
1440 | /* Read 16bit CRC */ |
| 1476 | READ_REG(hspi->Instance->DR); |
1441 | tmpreg = READ_REG(hspi->Instance->DR); |
| - | 1442 | /* To avoid GCC warning */ |
|
| - | 1443 | UNUSED(tmpreg); |
|
| 1477 | } |
1444 | } |
| 1478 | else |
1445 | else |
| 1479 | { |
1446 | { |
| - | 1447 | /* Initialize the 8bit temporary pointer */ |
|
| - | 1448 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
|
| 1480 | /* Read 8bit CRC */ |
1449 | /* Read 8bit CRC */ |
| - | 1450 | tmpreg8 = *ptmpreg8; |
|
| 1481 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
1451 | /* To avoid GCC warning */ |
| - | 1452 | UNUSED(tmpreg8); |
|
| 1482 | 1453 | ||
| 1483 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT) |
1454 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT) |
| 1484 | { |
1455 | { |
| 1485 | if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SET, Timeout, tickstart) != HAL_OK) |
1456 | if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SET, Timeout, tickstart) != HAL_OK) |
| 1486 | { |
1457 | { |
| Line 1488... | Line 1459... | ||
| 1488 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
1459 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
| 1489 | errorcode = HAL_TIMEOUT; |
1460 | errorcode = HAL_TIMEOUT; |
| 1490 | goto error; |
1461 | goto error; |
| 1491 | } |
1462 | } |
| 1492 | /* Read 8bit CRC again in case of 16bit CRC in 8bit Data mode */ |
1463 | /* Read 8bit CRC again in case of 16bit CRC in 8bit Data mode */ |
| - | 1464 | tmpreg8 = *ptmpreg8; |
|
| 1493 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
1465 | /* To avoid GCC warning */ |
| - | 1466 | UNUSED(tmpreg8); |
|
| 1494 | } |
1467 | } |
| 1495 | } |
1468 | } |
| 1496 | } |
1469 | } |
| 1497 | 1470 | ||
| 1498 | /* Check if CRC error occurred */ |
1471 | /* Check if CRC error occurred */ |
| Line 1529... | Line 1502... | ||
| 1529 | */ |
1502 | */ |
| 1530 | HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size) |
1503 | HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size) |
| 1531 | { |
1504 | { |
| 1532 | HAL_StatusTypeDef errorcode = HAL_OK; |
1505 | HAL_StatusTypeDef errorcode = HAL_OK; |
| 1533 | 1506 | ||
| 1534 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || ((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (Size > 1U))) |
- | |
| 1535 | { |
- | |
| 1536 | /* in this case, 16-bit access is performed on Data |
- | |
| 1537 | So, check Data is 16-bit aligned address */ |
- | |
| 1538 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pData)); |
- | |
| 1539 | } |
- | |
| 1540 | - | ||
| 1541 | /* Check Direction parameter */ |
1507 | /* Check Direction parameter */ |
| 1542 | assert_param(IS_SPI_DIRECTION_2LINES_OR_1LINE(hspi->Init.Direction)); |
1508 | assert_param(IS_SPI_DIRECTION_2LINES_OR_1LINE(hspi->Init.Direction)); |
| 1543 | 1509 | ||
| 1544 | /* Process Locked */ |
1510 | /* Process Locked */ |
| 1545 | __HAL_LOCK(hspi); |
1511 | __HAL_LOCK(hspi); |
| Line 1580... | Line 1546... | ||
| 1580 | } |
1546 | } |
| 1581 | 1547 | ||
| 1582 | /* Configure communication direction : 1Line */ |
1548 | /* Configure communication direction : 1Line */ |
| 1583 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
1549 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| 1584 | { |
1550 | { |
| - | 1551 | /* Disable SPI Peripheral before set 1Line direction (BIDIOE bit) */ |
|
| - | 1552 | __HAL_SPI_DISABLE(hspi); |
|
| 1585 | SPI_1LINE_TX(hspi); |
1553 | SPI_1LINE_TX(hspi); |
| 1586 | } |
1554 | } |
| 1587 | 1555 | ||
| 1588 | #if (USE_SPI_CRC != 0U) |
1556 | #if (USE_SPI_CRC != 0U) |
| 1589 | /* Reset CRC Calculation */ |
1557 | /* Reset CRC Calculation */ |
| Line 1619... | Line 1587... | ||
| 1619 | */ |
1587 | */ |
| 1620 | HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size) |
1588 | HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size) |
| 1621 | { |
1589 | { |
| 1622 | HAL_StatusTypeDef errorcode = HAL_OK; |
1590 | HAL_StatusTypeDef errorcode = HAL_OK; |
| 1623 | 1591 | ||
| 1624 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || ((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (Size > 1U))) |
- | |
| 1625 | { |
- | |
| 1626 | /* in this case, 16-bit access is performed on Data |
- | |
| 1627 | So, check Data is 16-bit aligned address */ |
- | |
| 1628 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pData)); |
- | |
| 1629 | } |
- | |
| 1630 | - | ||
| 1631 | if ((hspi->Init.Direction == SPI_DIRECTION_2LINES) && (hspi->Init.Mode == SPI_MODE_MASTER)) |
1592 | if ((hspi->Init.Direction == SPI_DIRECTION_2LINES) && (hspi->Init.Mode == SPI_MODE_MASTER)) |
| 1632 | { |
1593 | { |
| 1633 | hspi->State = HAL_SPI_STATE_BUSY_RX; |
1594 | hspi->State = HAL_SPI_STATE_BUSY_RX; |
| 1634 | /* Call transmit-receive function to send Dummy data on Tx line and generate clock on CLK line */ |
1595 | /* Call transmit-receive function to send Dummy data on Tx line and generate clock on CLK line */ |
| 1635 | return HAL_SPI_TransmitReceive_IT(hspi, pData, pData, Size); |
1596 | return HAL_SPI_TransmitReceive_IT(hspi, pData, pData, Size); |
| Line 1678... | Line 1639... | ||
| 1678 | } |
1639 | } |
| 1679 | 1640 | ||
| 1680 | /* Configure communication direction : 1Line */ |
1641 | /* Configure communication direction : 1Line */ |
| 1681 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
1642 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| 1682 | { |
1643 | { |
| - | 1644 | /* Disable SPI Peripheral before set 1Line direction (BIDIOE bit) */ |
|
| - | 1645 | __HAL_SPI_DISABLE(hspi); |
|
| 1683 | SPI_1LINE_RX(hspi); |
1646 | SPI_1LINE_RX(hspi); |
| 1684 | } |
1647 | } |
| 1685 | 1648 | ||
| 1686 | #if (USE_SPI_CRC != 0U) |
1649 | #if (USE_SPI_CRC != 0U) |
| 1687 | /* Reset CRC Calculation */ |
1650 | /* Reset CRC Calculation */ |
| Line 1733... | Line 1696... | ||
| 1733 | { |
1696 | { |
| 1734 | uint32_t tmp_mode; |
1697 | uint32_t tmp_mode; |
| 1735 | HAL_SPI_StateTypeDef tmp_state; |
1698 | HAL_SPI_StateTypeDef tmp_state; |
| 1736 | HAL_StatusTypeDef errorcode = HAL_OK; |
1699 | HAL_StatusTypeDef errorcode = HAL_OK; |
| 1737 | 1700 | ||
| 1738 | if ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || ((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (Size > 1U))) |
- | |
| 1739 | { |
- | |
| 1740 | /* in this case, 16-bit access is performed on Data |
- | |
| 1741 | So, check Data is 16-bit aligned address */ |
- | |
| 1742 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pTxData)); |
- | |
| 1743 | assert_param(IS_SPI_16BIT_ALIGNED_ADDRESS(pRxData)); |
- | |
| 1744 | } |
- | |
| 1745 | - | ||
| 1746 | /* Check Direction parameter */ |
1701 | /* Check Direction parameter */ |
| 1747 | assert_param(IS_SPI_DIRECTION_2LINES(hspi->Init.Direction)); |
1702 | assert_param(IS_SPI_DIRECTION_2LINES(hspi->Init.Direction)); |
| 1748 | 1703 | ||
| 1749 | /* Process locked */ |
1704 | /* Process locked */ |
| 1750 | __HAL_LOCK(hspi); |
1705 | __HAL_LOCK(hspi); |
| Line 1886... | Line 1841... | ||
| 1886 | hspi->RxXferCount = 0U; |
1841 | hspi->RxXferCount = 0U; |
| 1887 | 1842 | ||
| 1888 | /* Configure communication direction : 1Line */ |
1843 | /* Configure communication direction : 1Line */ |
| 1889 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
1844 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| 1890 | { |
1845 | { |
| - | 1846 | /* Disable SPI Peripheral before set 1Line direction (BIDIOE bit) */ |
|
| - | 1847 | __HAL_SPI_DISABLE(hspi); |
|
| 1891 | SPI_1LINE_TX(hspi); |
1848 | SPI_1LINE_TX(hspi); |
| 1892 | } |
1849 | } |
| 1893 | 1850 | ||
| 1894 | #if (USE_SPI_CRC != 0U) |
1851 | #if (USE_SPI_CRC != 0U) |
| 1895 | /* Reset CRC Calculation */ |
1852 | /* Reset CRC Calculation */ |
| Line 2016... | Line 1973... | ||
| 2016 | hspi->TxXferCount = 0U; |
1973 | hspi->TxXferCount = 0U; |
| 2017 | 1974 | ||
| 2018 | /* Configure communication direction : 1Line */ |
1975 | /* Configure communication direction : 1Line */ |
| 2019 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
1976 | if (hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| 2020 | { |
1977 | { |
| - | 1978 | /* Disable SPI Peripheral before set 1Line direction (BIDIOE bit) */ |
|
| - | 1979 | __HAL_SPI_DISABLE(hspi); |
|
| 2021 | SPI_1LINE_RX(hspi); |
1980 | SPI_1LINE_RX(hspi); |
| 2022 | } |
1981 | } |
| 2023 | 1982 | ||
| 2024 | #if (USE_SPI_CRC != 0U) |
1983 | #if (USE_SPI_CRC != 0U) |
| 2025 | /* Reset CRC Calculation */ |
1984 | /* Reset CRC Calculation */ |
| Line 2035... | Line 1994... | ||
| 2035 | { |
1994 | { |
| 2036 | /* Restriction the DMA data received is not allowed in this mode */ |
1995 | /* Restriction the DMA data received is not allowed in this mode */ |
| 2037 | errorcode = HAL_ERROR; |
1996 | errorcode = HAL_ERROR; |
| 2038 | goto error; |
1997 | goto error; |
| 2039 | } |
1998 | } |
| 2040 | #endif |
- | |
| - | 1999 | #endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F038xx || STM32F051x8 || STM32F058xx */ |
|
| 2041 | 2000 | ||
| 2042 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_LDMARX); |
2001 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_LDMARX); |
| 2043 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
2002 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
| 2044 | { |
2003 | { |
| 2045 | /* Set RX Fifo threshold according the reception data length: 16bit */ |
2004 | /* Set RX Fifo threshold according the reception data length: 16bit */ |
| Line 2188... | Line 2147... | ||
| 2188 | { |
2147 | { |
| 2189 | /* Restriction the DMA data received is not allowed in this mode */ |
2148 | /* Restriction the DMA data received is not allowed in this mode */ |
| 2190 | errorcode = HAL_ERROR; |
2149 | errorcode = HAL_ERROR; |
| 2191 | goto error; |
2150 | goto error; |
| 2192 | } |
2151 | } |
| 2193 | #endif |
- | |
| - | 2152 | #endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F038xx || STM32F051x8 || STM32F058xx */ |
|
| 2194 | 2153 | ||
| 2195 | /* Reset the threshold bit */ |
2154 | /* Reset the threshold bit */ |
| 2196 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_LDMATX | SPI_CR2_LDMARX); |
2155 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_LDMATX | SPI_CR2_LDMARX); |
| 2197 | 2156 | ||
| 2198 | /* The packing mode management is enabled by the DMA settings according the spi data size */ |
2157 | /* The packing mode management is enabled by the DMA settings according the spi data size */ |
| Line 3076... | Line 3035... | ||
| 3076 | */ |
3035 | */ |
| 3077 | static void SPI_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
3036 | static void SPI_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
| 3078 | { |
3037 | { |
| 3079 | SPI_HandleTypeDef *hspi = (SPI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */ |
3038 | SPI_HandleTypeDef *hspi = (SPI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */ |
| 3080 | uint32_t tickstart; |
3039 | uint32_t tickstart; |
| - | 3040 | #if (USE_SPI_CRC != 0U) |
|
| - | 3041 | __IO uint32_t tmpreg = 0U; |
|
| - | 3042 | __IO uint8_t * ptmpreg8; |
|
| - | 3043 | __IO uint8_t tmpreg8 = 0; |
|
| - | 3044 | #endif /* USE_SPI_CRC */ |
|
| 3081 | 3045 | ||
| 3082 | /* Init tickstart for timeout management*/ |
3046 | /* Init tickstart for timeout management*/ |
| 3083 | tickstart = HAL_GetTick(); |
3047 | tickstart = HAL_GetTick(); |
| 3084 | 3048 | ||
| 3085 | /* DMA Normal Mode */ |
3049 | /* DMA Normal Mode */ |
| Line 3100... | Line 3064... | ||
| 3100 | } |
3064 | } |
| 3101 | /* Read CRC */ |
3065 | /* Read CRC */ |
| 3102 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
3066 | if (hspi->Init.DataSize > SPI_DATASIZE_8BIT) |
| 3103 | { |
3067 | { |
| 3104 | /* Read 16bit CRC */ |
3068 | /* Read 16bit CRC */ |
| 3105 | READ_REG(hspi->Instance->DR); |
3069 | tmpreg = READ_REG(hspi->Instance->DR); |
| - | 3070 | /* To avoid GCC warning */ |
|
| - | 3071 | UNUSED(tmpreg); |
|
| 3106 | } |
3072 | } |
| 3107 | else |
3073 | else |
| 3108 | { |
3074 | { |
| - | 3075 | /* Initialize the 8bit temporary pointer */ |
|
| - | 3076 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
|
| 3109 | /* Read 8bit CRC */ |
3077 | /* Read 8bit CRC */ |
| - | 3078 | tmpreg8 = *ptmpreg8; |
|
| 3110 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
3079 | /* To avoid GCC warning */ |
| - | 3080 | UNUSED(tmpreg8); |
|
| 3111 | 3081 | ||
| 3112 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT) |
3082 | if (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT) |
| 3113 | { |
3083 | { |
| 3114 | if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SET, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) |
3084 | if (SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SET, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) |
| 3115 | { |
3085 | { |
| 3116 | /* Error on the CRC reception */ |
3086 | /* Error on the CRC reception */ |
| 3117 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
3087 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
| 3118 | } |
3088 | } |
| 3119 | /* Read 8bit CRC again in case of 16bit CRC in 8bit Data mode */ |
3089 | /* Read 8bit CRC again in case of 16bit CRC in 8bit Data mode */ |
| - | 3090 | tmpreg8 = *ptmpreg8; |
|
| 3120 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
3091 | /* To avoid GCC warning */ |
| - | 3092 | UNUSED(tmpreg8); |
|
| 3121 | } |
3093 | } |
| 3122 | } |
3094 | } |
| 3123 | } |
3095 | } |
| 3124 | #endif /* USE_SPI_CRC */ |
3096 | #endif /* USE_SPI_CRC */ |
| 3125 | 3097 | ||
| - | 3098 | /* Check if we are in Master RX 2 line mode */ |
|
| - | 3099 | if ((hspi->Init.Direction == SPI_DIRECTION_2LINES) && (hspi->Init.Mode == SPI_MODE_MASTER)) |
|
| - | 3100 | { |
|
| 3126 | /* Disable Rx/Tx DMA Request (done by default to handle the case master rx direction 2 lines) */ |
3101 | /* Disable Rx/Tx DMA Request (done by default to handle the case master rx direction 2 lines) */ |
| 3127 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_TXDMAEN | SPI_CR2_RXDMAEN); |
3102 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_TXDMAEN | SPI_CR2_RXDMAEN); |
| - | 3103 | } |
|
| - | 3104 | else |
|
| - | 3105 | { |
|
| - | 3106 | /* Normal case */ |
|
| - | 3107 | CLEAR_BIT(hspi->Instance->CR2, SPI_CR2_RXDMAEN); |
|
| - | 3108 | } |
|
| 3128 | 3109 | ||
| 3129 | /* Check the end of the transaction */ |
3110 | /* Check the end of the transaction */ |
| 3130 | if (SPI_EndRxTransaction(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) |
3111 | if (SPI_EndRxTransaction(hspi, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) |
| 3131 | { |
3112 | { |
| 3132 | hspi->ErrorCode = HAL_SPI_ERROR_FLAG; |
3113 | hspi->ErrorCode = HAL_SPI_ERROR_FLAG; |
| Line 3171... | Line 3152... | ||
| 3171 | */ |
3152 | */ |
| 3172 | static void SPI_DMATransmitReceiveCplt(DMA_HandleTypeDef *hdma) |
3153 | static void SPI_DMATransmitReceiveCplt(DMA_HandleTypeDef *hdma) |
| 3173 | { |
3154 | { |
| 3174 | SPI_HandleTypeDef *hspi = (SPI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */ |
3155 | SPI_HandleTypeDef *hspi = (SPI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */ |
| 3175 | uint32_t tickstart; |
3156 | uint32_t tickstart; |
| - | 3157 | #if (USE_SPI_CRC != 0U) |
|
| - | 3158 | __IO uint32_t tmpreg = 0U; |
|
| - | 3159 | __IO uint8_t * ptmpreg8; |
|
| - | 3160 | __IO uint8_t tmpreg8 = 0; |
|
| - | 3161 | #endif /* USE_SPI_CRC */ |
|
| 3176 | 3162 | ||
| 3177 | /* Init tickstart for timeout management*/ |
3163 | /* Init tickstart for timeout management*/ |
| 3178 | tickstart = HAL_GetTick(); |
3164 | tickstart = HAL_GetTick(); |
| 3179 | 3165 | ||
| 3180 | /* DMA Normal Mode */ |
3166 | /* DMA Normal Mode */ |
| Line 3193... | Line 3179... | ||
| 3193 | tickstart) != HAL_OK) |
3179 | tickstart) != HAL_OK) |
| 3194 | { |
3180 | { |
| 3195 | /* Error on the CRC reception */ |
3181 | /* Error on the CRC reception */ |
| 3196 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
3182 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
| 3197 | } |
3183 | } |
| 3198 | /* Read CRC to Flush DR and RXNE flag */ |
3184 | /* Initialize the 8bit temporary pointer */ |
| 3199 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
3185 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
| - | 3186 | /* Read 8bit CRC */ |
|
| - | 3187 | tmpreg8 = *ptmpreg8; |
|
| - | 3188 | /* To avoid GCC warning */ |
|
| - | 3189 | UNUSED(tmpreg8); |
|
| 3200 | } |
3190 | } |
| 3201 | else |
3191 | else |
| 3202 | { |
3192 | { |
| 3203 | if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_HALF_FULL, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) |
3193 | if (SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_HALF_FULL, SPI_DEFAULT_TIMEOUT, tickstart) != HAL_OK) |
| 3204 | { |
3194 | { |
| 3205 | /* Error on the CRC reception */ |
3195 | /* Error on the CRC reception */ |
| 3206 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
3196 | SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_CRC); |
| 3207 | } |
3197 | } |
| 3208 | /* Read CRC to Flush DR and RXNE flag */ |
3198 | /* Read CRC to Flush DR and RXNE flag */ |
| 3209 | READ_REG(hspi->Instance->DR); |
3199 | tmpreg = READ_REG(hspi->Instance->DR); |
| - | 3200 | /* To avoid GCC warning */ |
|
| - | 3201 | UNUSED(tmpreg); |
|
| 3210 | } |
3202 | } |
| 3211 | } |
3203 | } |
| 3212 | #endif /* USE_SPI_CRC */ |
3204 | #endif /* USE_SPI_CRC */ |
| 3213 | 3205 | ||
| 3214 | /* Check the end of the transaction */ |
3206 | /* Check the end of the transaction */ |
| Line 3539... | Line 3531... | ||
| 3539 | * the configuration information for SPI module. |
3531 | * the configuration information for SPI module. |
| 3540 | * @retval None |
3532 | * @retval None |
| 3541 | */ |
3533 | */ |
| 3542 | static void SPI_2linesRxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi) |
3534 | static void SPI_2linesRxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi) |
| 3543 | { |
3535 | { |
| - | 3536 | __IO uint8_t * ptmpreg8; |
|
| - | 3537 | __IO uint8_t tmpreg8 = 0; |
|
| - | 3538 | ||
| 3544 | /* Read 8bit CRC to flush Data Regsiter */ |
3539 | /* Initialize the 8bit temporary pointer */ |
| 3545 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
3540 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
| - | 3541 | /* Read 8bit CRC to flush Data Register */ |
|
| - | 3542 | tmpreg8 = *ptmpreg8; |
|
| - | 3543 | /* To avoid GCC warning */ |
|
| - | 3544 | UNUSED(tmpreg8); |
|
| 3546 | 3545 | ||
| 3547 | hspi->CRCSize--; |
3546 | hspi->CRCSize--; |
| 3548 | 3547 | ||
| 3549 | /* Check end of the reception */ |
3548 | /* Check end of the reception */ |
| 3550 | if (hspi->CRCSize == 0U) |
3549 | if (hspi->CRCSize == 0U) |
| Line 3647... | Line 3646... | ||
| 3647 | * the configuration information for SPI module. |
3646 | * the configuration information for SPI module. |
| 3648 | * @retval None |
3647 | * @retval None |
| 3649 | */ |
3648 | */ |
| 3650 | static void SPI_2linesRxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi) |
3649 | static void SPI_2linesRxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi) |
| 3651 | { |
3650 | { |
| - | 3651 | __IO uint32_t tmpreg = 0U; |
|
| - | 3652 | ||
| 3652 | /* Read 16bit CRC to flush Data Regsiter */ |
3653 | /* Read 16bit CRC to flush Data Register */ |
| 3653 | READ_REG(hspi->Instance->DR); |
3654 | tmpreg = READ_REG(hspi->Instance->DR); |
| - | 3655 | /* To avoid GCC warning */ |
|
| - | 3656 | UNUSED(tmpreg); |
|
| 3654 | 3657 | ||
| 3655 | /* Disable RXNE interrupt */ |
3658 | /* Disable RXNE interrupt */ |
| 3656 | __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE); |
3659 | __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE); |
| 3657 | 3660 | ||
| 3658 | SPI_CloseRxTx_ISR(hspi); |
3661 | SPI_CloseRxTx_ISR(hspi); |
| Line 3703... | Line 3706... | ||
| 3703 | * the configuration information for SPI module. |
3706 | * the configuration information for SPI module. |
| 3704 | * @retval None |
3707 | * @retval None |
| 3705 | */ |
3708 | */ |
| 3706 | static void SPI_RxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi) |
3709 | static void SPI_RxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi) |
| 3707 | { |
3710 | { |
| - | 3711 | __IO uint8_t * ptmpreg8; |
|
| - | 3712 | __IO uint8_t tmpreg8 = 0; |
|
| - | 3713 | ||
| - | 3714 | /* Initialize the 8bit temporary pointer */ |
|
| - | 3715 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
|
| 3708 | /* Read 8bit CRC to flush Data Register */ |
3716 | /* Read 8bit CRC to flush Data Register */ |
| - | 3717 | tmpreg8 = *ptmpreg8; |
|
| 3709 | READ_REG(*(__IO uint8_t *)&hspi->Instance->DR); |
3718 | /* To avoid GCC warning */ |
| - | 3719 | UNUSED(tmpreg8); |
|
| 3710 | 3720 | ||
| 3711 | hspi->CRCSize--; |
3721 | hspi->CRCSize--; |
| 3712 | 3722 | ||
| 3713 | if (hspi->CRCSize == 0U) |
3723 | if (hspi->CRCSize == 0U) |
| 3714 | { |
3724 | { |
| Line 3757... | Line 3767... | ||
| 3757 | * the configuration information for SPI module. |
3767 | * the configuration information for SPI module. |
| 3758 | * @retval None |
3768 | * @retval None |
| 3759 | */ |
3769 | */ |
| 3760 | static void SPI_RxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi) |
3770 | static void SPI_RxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi) |
| 3761 | { |
3771 | { |
| - | 3772 | __IO uint32_t tmpreg = 0U; |
|
| - | 3773 | ||
| 3762 | /* Read 16bit CRC to flush Data Register */ |
3774 | /* Read 16bit CRC to flush Data Register */ |
| 3763 | READ_REG(hspi->Instance->DR); |
3775 | tmpreg = READ_REG(hspi->Instance->DR); |
| - | 3776 | /* To avoid GCC warning */ |
|
| - | 3777 | UNUSED(tmpreg); |
|
| 3764 | 3778 | ||
| 3765 | /* Disable RXNE and ERR interrupt */ |
3779 | /* Disable RXNE and ERR interrupt */ |
| 3766 | __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_RXNE | SPI_IT_ERR)); |
3780 | __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_RXNE | SPI_IT_ERR)); |
| 3767 | 3781 | ||
| 3768 | SPI_CloseRx_ISR(hspi); |
3782 | SPI_CloseRx_ISR(hspi); |
| Line 3864... | Line 3878... | ||
| 3864 | * @retval HAL status |
3878 | * @retval HAL status |
| 3865 | */ |
3879 | */ |
| 3866 | static HAL_StatusTypeDef SPI_WaitFlagStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, FlagStatus State, |
3880 | static HAL_StatusTypeDef SPI_WaitFlagStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, FlagStatus State, |
| 3867 | uint32_t Timeout, uint32_t Tickstart) |
3881 | uint32_t Timeout, uint32_t Tickstart) |
| 3868 | { |
3882 | { |
| - | 3883 | __IO uint32_t count; |
|
| - | 3884 | uint32_t tmp_timeout; |
|
| - | 3885 | uint32_t tmp_tickstart; |
|
| - | 3886 | ||
| - | 3887 | /* Adjust Timeout value in case of end of transfer */ |
|
| - | 3888 | tmp_timeout = Timeout - (HAL_GetTick() - Tickstart); |
|
| - | 3889 | tmp_tickstart = HAL_GetTick(); |
|
| - | 3890 | ||
| - | 3891 | /* Calculate Timeout based on a software loop to avoid blocking issue if Systick is disabled */ |
|
| - | 3892 | count = tmp_timeout * ((SystemCoreClock * 32U) >> 20U); |
|
| - | 3893 | ||
| 3869 | while ((__HAL_SPI_GET_FLAG(hspi, Flag) ? SET : RESET) != State) |
3894 | while ((__HAL_SPI_GET_FLAG(hspi, Flag) ? SET : RESET) != State) |
| 3870 | { |
3895 | { |
| 3871 | if (Timeout != HAL_MAX_DELAY) |
3896 | if (Timeout != HAL_MAX_DELAY) |
| 3872 | { |
3897 | { |
| 3873 | if (((HAL_GetTick() - Tickstart) >= Timeout) || (Timeout == 0U)) |
3898 | if (((HAL_GetTick() - tmp_tickstart) >= tmp_timeout) || (tmp_timeout == 0U)) |
| 3874 | { |
3899 | { |
| 3875 | /* Disable the SPI and reset the CRC: the CRC value should be cleared |
3900 | /* Disable the SPI and reset the CRC: the CRC value should be cleared |
| 3876 | on both master and slave sides in order to resynchronize the master |
3901 | on both master and slave sides in order to resynchronize the master |
| 3877 | and slave for their respective CRC calculation */ |
3902 | and slave for their respective CRC calculation */ |
| 3878 | 3903 | ||
| 3879 | /* Disable TXE, RXNE and ERR interrupts for the interrupt process */ |
3904 | /* Disable TXE, RXNE and ERR interrupts for the interrupt process */ |
| 3880 | __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR)); |
3905 | __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR)); |
| 3881 | 3906 | ||
| 3882 | if ((hspi->Init.Mode == SPI_MODE_MASTER) && ((hspi->Init.Direction == SPI_DIRECTION_1LINE) |
3907 | if ((hspi->Init.Mode == SPI_MODE_MASTER) && ((hspi->Init.Direction == SPI_DIRECTION_1LINE) |
| Line 3897... | Line 3922... | ||
| 3897 | /* Process Unlocked */ |
3922 | /* Process Unlocked */ |
| 3898 | __HAL_UNLOCK(hspi); |
3923 | __HAL_UNLOCK(hspi); |
| 3899 | 3924 | ||
| 3900 | return HAL_TIMEOUT; |
3925 | return HAL_TIMEOUT; |
| 3901 | } |
3926 | } |
| - | 3927 | /* If Systick is disabled or not incremented, deactivate timeout to go in disable loop procedure */ |
|
| - | 3928 | if(count == 0U) |
|
| - | 3929 | { |
|
| - | 3930 | tmp_timeout = 0U; |
|
| - | 3931 | } |
|
| - | 3932 | count--; |
|
| 3902 | } |
3933 | } |
| 3903 | } |
3934 | } |
| 3904 | 3935 | ||
| 3905 | return HAL_OK; |
3936 | return HAL_OK; |
| 3906 | } |
3937 | } |
| Line 3916... | Line 3947... | ||
| 3916 | * @retval HAL status |
3947 | * @retval HAL status |
| 3917 | */ |
3948 | */ |
| 3918 | static HAL_StatusTypeDef SPI_WaitFifoStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Fifo, uint32_t State, |
3949 | static HAL_StatusTypeDef SPI_WaitFifoStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Fifo, uint32_t State, |
| 3919 | uint32_t Timeout, uint32_t Tickstart) |
3950 | uint32_t Timeout, uint32_t Tickstart) |
| 3920 | { |
3951 | { |
| - | 3952 | __IO uint32_t count; |
|
| - | 3953 | uint32_t tmp_timeout; |
|
| - | 3954 | uint32_t tmp_tickstart; |
|
| - | 3955 | __IO uint8_t * ptmpreg8; |
|
| - | 3956 | __IO uint8_t tmpreg8 = 0; |
|
| - | 3957 | ||
| - | 3958 | /* Adjust Timeout value in case of end of transfer */ |
|
| - | 3959 | tmp_timeout = Timeout - (HAL_GetTick() - Tickstart); |
|
| - | 3960 | tmp_tickstart = HAL_GetTick(); |
|
| - | 3961 | ||
| - | 3962 | /* Initialize the 8bit temporary pointer */ |
|
| - | 3963 | ptmpreg8 = (__IO uint8_t *)&hspi->Instance->DR; |
|
| - | 3964 | ||
| - | 3965 | /* Calculate Timeout based on a software loop to avoid blocking issue if Systick is disabled */ |
|
| - | 3966 | count = tmp_timeout * ((SystemCoreClock * 35U) >> 20U); |
|
| - | 3967 | ||
| 3921 | while ((hspi->Instance->SR & Fifo) != State) |
3968 | while ((hspi->Instance->SR & Fifo) != State) |
| 3922 | { |
3969 | { |
| 3923 | if ((Fifo == SPI_SR_FRLVL) && (State == SPI_FRLVL_EMPTY)) |
3970 | if ((Fifo == SPI_SR_FRLVL) && (State == SPI_FRLVL_EMPTY)) |
| 3924 | { |
3971 | { |
| 3925 | /* Read 8bit CRC to flush Data Register */ |
3972 | /* Flush Data Register by a blank read */ |
| - | 3973 | tmpreg8 = *ptmpreg8; |
|
| 3926 | READ_REG(*((__IO uint8_t *)&hspi->Instance->DR)); |
3974 | /* To avoid GCC warning */ |
| - | 3975 | UNUSED(tmpreg8); |
|
| 3927 | } |
3976 | } |
| 3928 | 3977 | ||
| 3929 | if (Timeout != HAL_MAX_DELAY) |
3978 | if (Timeout != HAL_MAX_DELAY) |
| 3930 | { |
3979 | { |
| 3931 | if (((HAL_GetTick() - Tickstart) >= Timeout) || (Timeout == 0U)) |
3980 | if (((HAL_GetTick() - tmp_tickstart) >= tmp_timeout) || (tmp_timeout == 0U)) |
| 3932 | { |
3981 | { |
| 3933 | /* Disable the SPI and reset the CRC: the CRC value should be cleared |
3982 | /* Disable the SPI and reset the CRC: the CRC value should be cleared |
| 3934 | on both master and slave sides in order to resynchronize the master |
3983 | on both master and slave sides in order to resynchronize the master |
| 3935 | and slave for their respective CRC calculation */ |
3984 | and slave for their respective CRC calculation */ |
| 3936 | 3985 | ||
| Line 3955... | Line 4004... | ||
| 3955 | /* Process Unlocked */ |
4004 | /* Process Unlocked */ |
| 3956 | __HAL_UNLOCK(hspi); |
4005 | __HAL_UNLOCK(hspi); |
| 3957 | 4006 | ||
| 3958 | return HAL_TIMEOUT; |
4007 | return HAL_TIMEOUT; |
| 3959 | } |
4008 | } |
| - | 4009 | /* If Systick is disabled or not incremented, deactivate timeout to go in disable loop procedure */ |
|
| - | 4010 | if(count == 0U) |
|
| - | 4011 | { |
|
| - | 4012 | tmp_timeout = 0U; |
|
| - | 4013 | } |
|
| - | 4014 | count--; |
|
| 3960 | } |
4015 | } |
| 3961 | } |
4016 | } |
| 3962 | 4017 | ||
| 3963 | return HAL_OK; |
4018 | return HAL_OK; |
| 3964 | } |
4019 | } |
| Line 4041... | Line 4096... | ||
| 4041 | */ |
4096 | */ |
| 4042 | static void SPI_CloseRxTx_ISR(SPI_HandleTypeDef *hspi) |
4097 | static void SPI_CloseRxTx_ISR(SPI_HandleTypeDef *hspi) |
| 4043 | { |
4098 | { |
| 4044 | uint32_t tickstart; |
4099 | uint32_t tickstart; |
| 4045 | 4100 | ||
| 4046 | /* Init tickstart for timeout managment*/ |
4101 | /* Init tickstart for timeout management */ |
| 4047 | tickstart = HAL_GetTick(); |
4102 | tickstart = HAL_GetTick(); |
| 4048 | 4103 | ||
| 4049 | /* Disable ERR interrupt */ |
4104 | /* Disable ERR interrupt */ |
| 4050 | __HAL_SPI_DISABLE_IT(hspi, SPI_IT_ERR); |
4105 | __HAL_SPI_DISABLE_IT(hspi, SPI_IT_ERR); |
| 4051 | 4106 | ||