2022-09-15 07:53 PM
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
2022-09-15 08:42 PM
>>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.
2022-09-18 06:18 AM
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.
2022-09-18 06:47 AM
why you use an int to send a char (int8_t) ? (and cast to int8 then )
try using int8_t .
2022-09-18 08:58 AM
I don't think it casting the pointer is the issue here.
2022-09-18 09:02 AM
>>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..