2021-06-01 12:15 AM
I was trying to write a simple UART driver using polling method to run on my Nucleo-F303RE. I tried 2 different approaches:
It seems to me like more should be passed to the API function uartintpolldriver() rather than just the UART handlers. Or am I missing something more here?
What could be wrong here? How do I fix it? It would be helpful if someone could give a pointer on how to do this. Attached below is a zip of my log and source code.
Solved! Go to Solution.
2021-06-01 05:50 AM
You're passing a pointer to a pointer to a handle, rather than a pointer to a handle.
void uartintpolldriver(UART_HandleTypeDef *htxuart, UART_HandleTypeDef *hrxuart)
{
...
TxStatus = HAL_UART_Transmit(&htxuart, &TxDataBuffer, 1, 1000);
...
RxStatus = HAL_UART_Receive(&hrxuart, &RxDataBuffer, 1, 1000);
...
}
It absolutely should be throwing an error. It does for me:
...: In function 'void uartintpolldriver(UART_HandleTypeDef*, UART_HandleTypeDef*)':
...:96:66: error: cannot convert 'UART_HandleTypeDef**' to 'UART_HandleTypeDef*' for argument '1' to 'HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef*, uint8_t*, uint16_t, uint32_t)'
TxStatus = HAL_UART_Transmit(&htxuart, &TxDataBuffer, 1, 1000);
^
...:107:65: error: cannot convert 'UART_HandleTypeDef**' to 'UART_HandleTypeDef*' for argument '1' to 'HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef*, uint8_t*, uint16_t, uint32_t)'
RxStatus = HAL_UART_Receive(&hrxuart, &RxDataBuffer, 1, 1000);
2021-06-01 05:50 AM
You're passing a pointer to a pointer to a handle, rather than a pointer to a handle.
void uartintpolldriver(UART_HandleTypeDef *htxuart, UART_HandleTypeDef *hrxuart)
{
...
TxStatus = HAL_UART_Transmit(&htxuart, &TxDataBuffer, 1, 1000);
...
RxStatus = HAL_UART_Receive(&hrxuart, &RxDataBuffer, 1, 1000);
...
}
It absolutely should be throwing an error. It does for me:
...: In function 'void uartintpolldriver(UART_HandleTypeDef*, UART_HandleTypeDef*)':
...:96:66: error: cannot convert 'UART_HandleTypeDef**' to 'UART_HandleTypeDef*' for argument '1' to 'HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef*, uint8_t*, uint16_t, uint32_t)'
TxStatus = HAL_UART_Transmit(&htxuart, &TxDataBuffer, 1, 1000);
^
...:107:65: error: cannot convert 'UART_HandleTypeDef**' to 'UART_HandleTypeDef*' for argument '1' to 'HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef*, uint8_t*, uint16_t, uint32_t)'
RxStatus = HAL_UART_Receive(&hrxuart, &RxDataBuffer, 1, 1000);
2021-06-06 02:15 AM
Thanks for pointing it out. Have made the following modifications to fix it:
....
TxStatus = HAL_UART_Transmit(htxuart, &TxDataBuffer, 1, 1000);
....
RxStatus = HAL_UART_Receive(hrxuart, &RxDataBuffer, 1, 1000);
....