Hard fault error when cast variable in stm32g070
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-24 2:13 PM
I have migrated code from stm32f4 to stm32g0 suscesfully in almost all my aplication. However there is a part of code that rise a hard fault error.
This is the code:
crc_received = *((uint32_t*)&e22_uart_rx_buffer[(uint16_t)(e22_uart_rx_buffer_length - 4)]);
This is the assembler compiled:
113 crc_received = *((uint32_t*)&e22_uart_rx_buffer[(uint16_t)(e22_uart_rx_buffer_length - 4)]);
08003c6a: uxth r3, r1
08003c6c: ldr r3, [r5, r3]
08003c6e: uxtb r1, r1
08003c70: movs r0, #0
08003c72: str r3, [r7, #0]
The error rise after execute: ldr r3, [r5, r3]
And this is the fault analizer viewer from stm32cube ide:
The Register content is this one:
I can't realize where is the trouble, even fault analizer didn't show a partircular issue. This code operation is a simple cast from 4 bytes uint8_t buffer[] to uint32_t.
Solved! Go to Solution.
- Labels:
-
DEBUG
-
STM32G0 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-24 3:41 PM
The Cortex-M0+ processor, which is core in 'G0, does not support unaligned accesses, i.e. you must not read an uint32_t from an address which is not multiple of 4.
Read 4 bytes and assemble them into the uint32_t "manually".
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-24 3:41 PM
The Cortex-M0+ processor, which is core in 'G0, does not support unaligned accesses, i.e. you must not read an uint32_t from an address which is not multiple of 4.
Read 4 bytes and assemble them into the uint32_t "manually".
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-24 4:15 PM
Is there any gcc flag compilation in order to make this automatically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-24 7:00 PM
You can try the -mno-unaligned-access flag in GCC to see if it works. Unsure how it will handle the casting.
