cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault issue on STM32G030

Paul.Lee
Associate III

Hi,

I'm facing on hardfault error.:(

I have used many ST32F MCUs for projects.

STM32G030C8T6 has two UART.

UART1 is used for debugging message out, and UART2 is for communicated with other system I am using.

But, a few message out thru UART2 cause the hardfault error. just call HAL_UART_Transmit().

just in main.c

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_ADC1_Init();

 MX_USART1_UART_Init();

 MX_USART2_UART_Init();

 while (1) __io_putchar_u2('*');

---

int __io_putchar_u2 (int ch)

{

HAL_UART_Transmit (&huart2, (uint8_t *) &ch, 1, 1);

return ch;

}

I have not seen this situation for STM32.

UART1 is no problem.

What cause the hardfault on this?

BR

Paul

5 REPLIES 5

>>What cause the hardfault on this?

Wouldn't the Handler be able to determine this, the MCU provides a lot of information.

Perhaps the huart2 structure isn't suitably initialized. Or the function is called before expected.

Perhaps look at the generated code, and the specific instruction/registers at the point that faults.

CM0(+) will object to misaligned memory accesses, and accesses to undecoded memory addresses.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Yes!

This code is generated by stmCubeIDE.

I didn't modify MX_USART2_UART_Init(); function.

I think this is so simple code, no room to MY mistake.​

AScha.3
Chief III

why you use an int to send a char (int8_t) ? (and cast to int8 then )

try using int8_t .

If you feel a post has answered your question, please click "Accept as Solution".

I don't think it casting the pointer is the issue here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

>>I think this is so simple code, no room to MY mistake.​

Do you want to resolve the issue or not?

I don't think the issue is with the code fragment you've shared, so you need to expand the horizon here a little.

Have a Hard Fault Handler that develops some actionable information, and look at what specifically the MCU is objecting too, and review / fix that.

I've posted handlers to do this efficiently, although they kind of want the output methods to be functional..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..