From 09e94b3e15d882d88a3d9c2645abb6e67b97c32b Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Thu, 24 Nov 2022 10:39:25 +0100 Subject: [PATCH] sys/usb/usbus/dfu: check min sector size for STM32 F2/F4/F7 STM32F2/4/7 MCUs use sectors instead of pages, where the minimum sector size is defined by FLASHPAGE_MIN_SECTOR_SIZE, which is 16KB or 32KB (the first sector) depending on the CPU_MODEL. In this case SLOT0_OFFSET must be a multiple of the minimum sector size to cover a whole sector. --- sys/usb/usbus/dfu/dfu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/usb/usbus/dfu/dfu.c b/sys/usb/usbus/dfu/dfu.c index b838978d24..d2ab4f9652 100644 --- a/sys/usb/usbus/dfu/dfu.c +++ b/sys/usb/usbus/dfu/dfu.c @@ -101,7 +101,17 @@ void usbus_dfu_init(usbus_t *usbus, usbus_dfu_device_t *handler, unsigned mode) DEBUG("DFU: initialization\n"); assert(usbus); assert(handler); - assert((SLOT0_OFFSET % FLASHPAGE_SIZE) == 0); +#if defined(FLASHPAGE_SIZE) + static_assert((SLOT0_OFFSET % FLASHPAGE_SIZE) == 0, + "SLOT0_OFFSET has to be a multiple of FLASHPAGE_SIZE"); +#elif defined(FLASHPAGE_MIN_SECTOR_SIZE) + /* STM32F2/4/7 MCUs use sectors instead of pages, where the minimum sector + * size is defined by FLASHPAGE_MIN_SECTOR_SIZE, which is 16KB or 32KB + * (the first sector) depending on the CPU_MODEL. In this case SLOT0_OFFSET + * must be a multiple of the minimum sector size to cover a whole sector. */ + static_assert((SLOT0_OFFSET % FLASHPAGE_MIN_SECTOR_SIZE) == 0, + "SLOT0_OFFSET has to be a multiple of FLASHPAGE_MIN_SECTOR_SIZE"); +#endif memset(handler, 0, sizeof(usbus_dfu_device_t)); handler->usbus = usbus; handler->handler_ctrl.driver = &dfu_driver;