diff --git a/os/hal/platforms/STM32/OTGv1/usb_lld.c b/os/hal/platforms/STM32/OTGv1/usb_lld.c index 4af75ccd2..35b5335e5 100644 --- a/os/hal/platforms/STM32/OTGv1/usb_lld.c +++ b/os/hal/platforms/STM32/OTGv1/usb_lld.c @@ -246,7 +246,7 @@ static uint8_t *otg_do_push(volatile uint32_t *fifop, uint8_t *buf, size_t n) { while (n > 0) { /* Note, this line relies on the Cortex-M3/M4 ability to perform unaligned word accesses and on the LSB-first memory organization.*/ - *fifop = *((uint32_t *)buf); + *fifop = *((PACKED_VAR uint32_t *)buf); buf += 4; n--; } @@ -345,7 +345,7 @@ static uint8_t *otg_do_pop(volatile uint32_t *fifop, uint8_t *buf, size_t n) { uint32_t w = *fifop; /* Note, this line relies on the Cortex-M3/M4 ability to perform unaligned word accesses and on the LSB-first memory organization.*/ - *((uint32_t *)buf) = w; + *((PACKED_VAR uint32_t *)buf) = w; buf += 4; n--; } @@ -374,7 +374,7 @@ static void otg_fifo_read_to_buffer(volatile uint32_t *fifop, if (max) { /* Note, this line relies on the Cortex-M3/M4 ability to perform unaligned word accesses and on the LSB-first memory organization.*/ - *((uint32_t *)buf) = w; + *((PACKED_VAR uint32_t *)buf) = w; buf += 4; max--; } diff --git a/os/ports/GCC/ARMCMx/chtypes.h b/os/ports/GCC/ARMCMx/chtypes.h index a94ae24ae..5116a79a7 100644 --- a/os/ports/GCC/ARMCMx/chtypes.h +++ b/os/ports/GCC/ARMCMx/chtypes.h @@ -75,6 +75,11 @@ typedef int32_t cnt_t; /**< Resources counter. */ */ #define PACK_STRUCT_END +/** + * @brief Packed variable specifier. + */ +#define PACKED_VAR __attribute__((packed)) + #endif /* _CHTYPES_H_ */ /** @} */ diff --git a/os/ports/IAR/ARMCMx/chtypes.h b/os/ports/IAR/ARMCMx/chtypes.h index 9855c4e00..d2a55bbfe 100644 --- a/os/ports/IAR/ARMCMx/chtypes.h +++ b/os/ports/IAR/ARMCMx/chtypes.h @@ -74,6 +74,11 @@ typedef int32_t cnt_t; /**< Resources counter. */ */ #define PACK_STRUCT_END +/** + * @brief Packed variable specifier. + */ +#define PACKED_VAR __packed + #endif /* _CHTYPES_H_ */ /** @} */ diff --git a/os/ports/RVCT/ARMCMx/chtypes.h b/os/ports/RVCT/ARMCMx/chtypes.h index b3f19f674..ec76fd523 100644 --- a/os/ports/RVCT/ARMCMx/chtypes.h +++ b/os/ports/RVCT/ARMCMx/chtypes.h @@ -74,6 +74,11 @@ typedef int32_t cnt_t; /**< Resources counter. */ */ #define PACK_STRUCT_END +/** + * @brief Packed variable specifier. + */ +#define PACKED_VAR __packed + #endif /* _CHTYPES_H_ */ /** @} */ diff --git a/readme.txt b/readme.txt index 89dcc9460..a7045629b 100644 --- a/readme.txt +++ b/readme.txt @@ -100,6 +100,7 @@ - FIX: Fixed timing issue in the STM32 OTGv1 USB driver (bug #436)(backported to 2.6.2). - FIX: Fixed STM32L1 remove reset flag (bug #435)(backported to 2.6.2). +- FIX: Fixed unaligned data access in USB LLD (bug #434)(backported to 2.6.2). - FIX: Fixed add RTC to STM32L1 (bug #433)(backported to 2.6.2). - FIX: Fixed support 10-bit addresses in STM32 I2C driver (bug #432) (backported to 2.6.2).