Write Flash memory over virtual Com Port (USB)
Hello, I am developing a dual processor application with a host (STM32F205xx) and a slave (Radio Module SoC). The idea is to update the wireless module's firmware from the PC via the virtual COM port.
The firmware is temporarily stored in STM flash memory. The problem is that only the first segment is saved correctly. Attempting to save the next segment to flash memory will cause the Virtaul Com port to reboot.
When USB data reception interruption, the function below is called, the flash address was set to 0x080E0000 (will be cleared when STM restarts)
uint8_t ReceiveSegmentClb(const uint32_t offset, uint8_t *segmentData, uint8_t chunkSize)
{
if(offset + chunkSize <= FirmwareLength)
{
uint8_t chunkIndex = 0;
HAL_FLASH_Unlock();
while(chunkIndex < chunkSize)
{
flashStatus = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE,
0x080E0000 +offset + chunkIndex), segmentData[chunkIndex]);
if(flashStatus != HAL_OK)
{
return -1:
break;
}
chunkIndex++;
}
HAL_FLASH_Lock();
}
return 0;
}
After the ReceiveSegmentClb function is executed, the CDC_Transmit_HS(functionStatus, 1); shall be called.

As can be seen from the image above, the first write was successful. On the PC side, the response comes correctly, but the next segment write cannot be started because the STM restarts itself.
What am I doing wrong?
Thanks in advance!!!
