From 88ef710ecb12458b3ca28546733208794995cfc9 Mon Sep 17 00:00:00 2001 From: 3djc Date: Thu, 8 Jul 2021 16:07:43 +0200 Subject: [PATCH] Better solution to silence warning on GCC 10 Imported from opentx/opentx#8605 --- .../STM32_USB_OTG_Driver/src/usb_core.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c index 8c96a04fc..f76c587c6 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c @@ -29,6 +29,19 @@ #include "usb_core.h" #include "usb_bsp.h" +// taken from https://github.com/ARMmbed/mbed-os/blob/master/cmsis/TARGET_CORTEX_M/cmsis_compiler.h +#ifndef __PACKED_STRUCT +#define __PACKED_STRUCT struct __attribute__((packed)) +#endif +#ifndef __UNALIGNED_UINT32_WRITE +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif + /** @addtogroup USB_OTG_DRIVER * @{ @@ -180,7 +193,7 @@ USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, fifo = pdev->regs.DFIFO[ch_ep_num]; for (i = 0; i < count32b; i++) { - USB_OTG_WRITE_REG32( fifo, *((uint32_t *)src) ); + USB_OTG_WRITE_REG32( fifo, __UNALIGNED_UINT32_READ(src) ); src+=4; } } @@ -206,7 +219,7 @@ void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, for( i = 0; i < count32b; i++) { - *(uint32_t *)dest = USB_OTG_READ_REG32(fifo); + __UNALIGNED_UINT32_WRITE(dest, USB_OTG_READ_REG32(fifo)); dest += 4 ; } return ((void *)dest);