STM32F0xx HAL library use of records

1. SPI data transceiver function HAL_SPI_xxxIncoming Outgoing buf aligned 16-bit pointer address required

For example, SPI data transceiving function HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout),
pTxData and and pRxData, the necessary 16-bit alignment, can not be guaranteed if the 16-bit alignment, SPI case may call transceiver function, the application of two 16-bit aligned buf buf replace the original SPI for transmitting and receiving data, examples are as follows:

HAL_StatusTypeDef spiTxRx(const uint8_t *txData, uint8_t *rxData, uint16_t length)
{
    HAL_StatusTypeDef ret;
    
    /* txbuf, rxbuf 地址是16位对齐的,可作为SPI收发函数的参数 */
    uint8_t txbuf[255];
    uint8_t rxbuf[255];
    
    /* 将SPI要发送的数据拷贝到txbuf */
    if(txData != NULL) {
        memcpy(rxbuf, txData, length);
    }
    
    /* 使用txbuf和rxbuf进行SPI数据收发 */
    ret = HAL_SPI_TransmitReceive(hspi, txbuf, rxbuf, length, Timeout);

    /* 将SPI接收的数据拷回rxData */
    if(rxData != NULL) {
        memcpy(rxData, rxbuf, length);
    }
    
    return ret;
}

2. Use the HAL library provides a serial port receive interrupt handler, you need to call again in the interrupt processing HAL_UART_Receive_ITis enabled serial port receive interrupt, this function call may fail, resulting in serial port receive interrupt is not enabled, can not receive data through the serial port receive interrupt

HAL library provides a serial port receive interrupt API use:

  1. Interrupt handler call HAL_UART_IRQHandler, this function will disable the serial port receive interrupt calls HAL_UART_RxCpltCallback.
  2. Realization HAL_UART_RxCpltCallback, this function receives serial data, and call again HAL_UART_Receive_ITenable the serial port receive interrupt at this time may fail, resulting in not re-enter the serial receive interrupt.

Solution: Do not use HAL handler provides, directly determines the interrupt handler receives the interrupt flag bit data, and clears the interrupt flag.

Guess you like

Origin www.cnblogs.com/chenbeibei/p/11404296.html