diff options
| author | Damien George <damien.p.george@gmail.com> | 2018-03-16 23:48:29 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-03-16 23:52:13 +1100 |
| commit | 06aa13c350af0f3910b2d99303548f31a85c0d9c (patch) | |
| tree | 76499780009f8f26ddb15fb1aac0e3ca68e5da95 | |
| parent | 9600a1f207edf90d72b5f7c545172785f3943ff5 (diff) | |
stm32/can: Use explicit byte extraction instead of casting to word ptr.
Casting the Data array to a uint32_t* leads to strict aliasing errors on
older gcc compilers.
| -rw-r--r-- | ports/stm32/can.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ports/stm32/can.c b/ports/stm32/can.c index b1bcd1c3e..5b5c4ad3f 100644 --- a/ports/stm32/can.c +++ b/ports/stm32/can.c @@ -222,8 +222,16 @@ STATIC int can_receive(CAN_TypeDef *can, int fifo, CanRxMsgTypeDef *msg, uint32_ msg->RTR = box->RIR & 2; msg->DLC = box->RDTR & 0xf; msg->FMI = box->RDTR >> 8 & 0xff; - *(uint32_t*)&msg->Data[0] = box->RDLR; - *(uint32_t*)&msg->Data[4] = box->RDHR; + uint32_t rdlr = box->RDLR; + msg->Data[0] = rdlr; + msg->Data[1] = rdlr >> 8; + msg->Data[2] = rdlr >> 16; + msg->Data[3] = rdlr >> 24; + uint32_t rdhr = box->RDHR; + msg->Data[4] = rdhr; + msg->Data[5] = rdhr >> 8; + msg->Data[6] = rdhr >> 16; + msg->Data[7] = rdhr >> 24; // Release (free) message from FIFO *rfr |= CAN_RF0R_RFOM0; |
