diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg.c b/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg.c index 3a2bcf8b12..b6afa71b27 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg.c @@ -244,8 +244,11 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp, #if HAL_USE_SERIAL_USB uint32_t get_usb_baud(uint16_t endpoint_id) { - if(endpoint_id == 0) - return *((uint32_t*)linecoding.dwDTERate); + if (endpoint_id == 0) { + uint32_t rate; + memcpy(&rate, &linecoding.dwDTERate[0], sizeof(rate)); + return rate; + } return 0; } #endif diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_dualcdc.c b/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_dualcdc.c index 5a407d748d..091cabf33d 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_dualcdc.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_dualcdc.c @@ -307,8 +307,10 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp, uint32_t get_usb_baud(uint16_t endpoint_id) { for (uint8_t i = 0; i < ARRAY_SIZE(linecoding); i++) { - if(endpoint_id == ep_index[i]) - return *((uint32_t*)linecoding[i].dwDTERate); + if (endpoint_id == ep_index[i]) { + uint32_t rate; + memcpy(&rate, &linecoding[i].dwDTERate[0], sizeof(rate)); + } } return 0; }