Skip to main content
skrowten_hermit
Associate II
June 1, 2021
Solved

Hard_Fault handler error on API call for basic UART driver for Nucleo-F303RE

  • June 1, 2021
  • 2 replies
  • 1080 views

I was trying to write a simple UART driver using polling method to run on my Nucleo-F303RE. I tried 2 different approaches:

  1. 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.
  2. 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.

This topic has been closed for replies.
Best answer by TDK

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);

2 replies

TDK
TDKBest answer
June 1, 2021

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);

"If you feel a post has answered your question, please click ""Accept as Solution""."
skrowten_hermit
Associate II
June 6, 2021

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);
 
....