2025-03-24 6:30 AM - last edited on 2025-03-24 7:14 AM by mƎALLEm
i am trying to implement openBootloader for an stm32l451,
but i cant get the write to work i get the following errors HAL_FLASH_ERROR_PROG | HAL_FLASH_ERROR_PGA |HAL_FLASH_ERROR_PGS
i am trying to write to 800c000 in the flash
this is my code( i used https://github.com/STMicroelectronics/stm32wl-openbl-apps to assist in how to write the interfaces)
void OPENBL_FLASH_Unlock(void) { HAL_FLASH_Unlock(); }
static void OPENBL_FLASH_Program(uint32_t Address, uint64_t Data) {
/* Clear all FLASH errors flags before starting write operation */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, Data);
}
void OPENBL_FLASH_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength) {
uint32_t index;
__ALIGNED(4) uint8_t buffer[FLASH_PROG_STEP_SIZE] = {0x0U};
uint8_t remaining;
if ((Data != NULL) && (DataLength != 0U)) {
/* Unlock the flash memory for write operation */
OPENBL_FLASH_Unlock();
/* Program double-word by double-word (8 bytes) */
while ((DataLength >> 3U) > 0U) {
for (index = 0U; index < FLASH_PROG_STEP_SIZE; index++) {
buffer[index] = *(Data + index);
}
OPENBL_FLASH_Program(Address,
*((uint64_t *)buffer));
Address += FLASH_PROG_STEP_SIZE;
Data += FLASH_PROG_STEP_SIZE;
DataLength -= FLASH_PROG_STEP_SIZE;
}
/* If remaining count, go back to fill the rest with 0xFF */
if (DataLength > 0U) {
remaining = FLASH_PROG_STEP_SIZE - DataLength;
/* Copy the remaining bytes */
for (index = 0U; index < DataLength; index++) {
buffer[index] = *(Data + index);
}
/* Fill the upper bytes with 0xFF */
for (index = 0U; index < remaining; index++) {
buffer[index + DataLength] = 0xFFU;
}
/* FLASH word program */
OPENBL_FLASH_Program(Address,
(uint64_t)(*((uint64_t *)((uint32_t)buffer))));
}
/* Lock the Flash to disable the flash control register access */
OPENBL_FLASH_Lock();
}
is where something i am missing ?