Hard_Fault handler error on API call for basic UART driver for Nucleo-F303RE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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:
- I wrote the function intpolldriver() to write an integer value between UART4 and UART5 in the main.c, called it in main() and compiled the code. It was built and ran successfully, passing values b/w both UARTs verified by TDR value of UART4 and RDR value of UART5.
- I wrote another function uartintpolldriver(), which accepts the UART handlers for UART4 and UART5, as an API and called it in main(). Though it compiled without errors and was expected to run exactly as above (the function code is exactly the same), it instead branched into hard_fault_handler.
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.
- Labels:
-
STM32F3 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-01 5: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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-01 5: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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-06 2: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);
....
