cancel
Showing results for 
Search instead for 
Did you mean: 

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

skrowten_hermit
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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".

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