STM32 Flash Write fail
Due to engineering requirements, the code is divided into two parts: USB DFU, including encrypted signature verification, and the APP code with header signature file. Currently, there is an attempt to rewrite the flash in the USB DFU orange section from the APP code, but it has not been successful. The reason has not been identified yet. Are there any other directions to test, considering that writing Flash data at the end of the APP code is working fine?
The MCU in use is STM32F401RET6.
code as below
int pending_len = writing_len;//writing_len=374
int wr_idx = 0;
ret = HAL_FLASH_Unlock();
if (ret != 0) {
uart_printf("flash unlock failed\n");
goto failed;
}
}
// writing by 8 bits
for (; wr_idx < writing_len; wr_idx++) {
uint8_t *src8 = &cached_data[wr_idx];
ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, flash_addr + wr_idx, *src8);
if (ret != 0) {
uart_printf("flash program 8 failed\n");
goto failed;
}
pending_len--;
}
}
// lock
ret = HAL_FLASH_Lock();
if (ret != 0) {
uart_printf("flash lock failed\n");
goto failed;
}

