2024-01-24 03:43 AM
Hi there!
I'm experiencing a new trouble: trying to program a simple flash Word it results in an hard fault; moreover, also trying to read the same area gives an hard fault.
Debugging the application I discovered that the HAL_FLASH_Unlock function fails.
Since I already seen sutch code work, it's quite strange to me!
b08t InitFLASHwrite(void)
{
/*.-.-.| Local variables: |.-.-.*/
b08t bIsError = FALSE; // Output error indication
HAL_StatusTypeDef enuUnlock = HAL_FLASH_Unlock(); // Unlock state
/*.-.-.| Execution: |.-.-.*/
// Unlock FLASH memory...
if(enuUnlock == HAL_OK)
{
// No errors:
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGSERR | FLASH_FLAG_WRPERR); // Clear pending flags (if any)
// Needed after an update retry otherwise flash erase is not executed
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK2);
}
else
{
bIsError = TRUE; // Else indicate error
printf("**** HAL_FLASH_Unlock() fail! ****\r\n");
}
return bIsError;
}
Above there is the code.
What's wrong?
iTTy
PS - Environment:
Nucleo-H755ZI-Q, Cube Ide 1.13.2, FW lib. 1.11.1, Cube MX 6.9.2
Solved! Go to Solution.
2024-01-24 05:45 AM
The HAL_FLASH_Unlock function is simple. Debug and step through the program to see what it does.
If unlocking the flash fails, perhaps it is locked due to an invalid access. Look at the FLASH registers or step through to see where and why it's failing.
2024-01-24 05:45 AM
The HAL_FLASH_Unlock function is simple. Debug and step through the program to see what it does.
If unlocking the flash fails, perhaps it is locked due to an invalid access. Look at the FLASH registers or step through to see where and why it's failing.
2024-01-25 08:00 AM
Hi @TDK,
Thanks to your advice, I found that the function was working as expected but the application fails at the return.
finally I fixed by cleaning the project and recopiling it.
Incremental building is faster but is sometimes is a nightmare.