STM32 - Getting HardFault when assigning uint32_t value
This looks like an unaligned access, which causes hard faults on Cortex M0 cores. M3 &amp; M4 cores can handle this with some performance penalties.
Basically, when you try to access a memory location using a uint32_t pointer, the compiler generates a 32 bit word access instruction. This word address must be aligned to a 4 byte address boundary. In other words, the address must be divisible by 4.
Your uint8_t buffer may or may not be aligned to 4 byte boundary. Actually, unless they are in structs, compilers seem to align all variables on word boundaries. Of course you can't count on that, so it's better to demand it explicitly. In GCC, you can align variables like below:
uint8_t buffer[200] __attribute__ ((aligned (4)));

Unfortunately, this kind of alignment won't solve your problem in your situation. Because even if the start of the buffer is aligned, you are using uint8_t pointers to access it. So unless the length is divisible by 4, you will still cause unaligned access faults.
You may need to reconsider your memory layout. Or you can manually extract uint32_t from the buffer. memcpy() function is a well known and easy to use solution in these situations.
#include &lt;string.h&gt;
uint32_t val32;
memcpy(&amp;val32, buffer + length - 4, sizeof(val32));