2019-04-08 08:43 AM
If a charger is plugged into the USB (rather than a computer) then USBD_MSC_Init() is not called. Consequently pClassData is left NULL. If the USB is then stopped via USBD_Stop(), then the USBD_MSC_DeInit() is called and the NULL pointer is accessed (written to). This causes the FLASH SR to have errors set (SIZERR, PGSERR), which in turn prevent subsequent flash erase operations due to initial error check.