cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U385VGT6Q fails to write FLASH (EEPROM)

george-metasphere
Associate III

Hello,

I've been using the Nucleo-U385RG-Q for my project and all features work fine, but when I switch the code to a STM32U385VGT6Q, there is a problem when attempting to write to FLASH. My Write function starts with:

    if (HAL_FLASHEx_Erase(&flashErase, &error) != HAL_OK)
    {
      break;
    }

and it precisely crashes at: FLASH_WaitForLastOperation in error = ((*reg_sr) & FLASH_FLAG_SR_ERRORS); with error code 128 (0x80). Searching for the error leads me to believe that the CPU is attempting to write protected/secure state areas but the Option Bytes says otherwise.I use Nima-LTD-I-CUBE-EE library.

1 ACCEPTED SOLUTION

Accepted Solutions
george-metasphere
Associate III

OK, I finally found the issue by accident. It was a Clock Configuration issue. Because I set my UART at 19200bps, the MSIS divider is downclocked and the entire system runs at 1.5Mhz instead of the stable 12Mhz. This apparently causes the EEPROM write to fail. Pushing the UART and clock speeds higher solves this issue.

View solution in original post

5 REPLIES 5
TDK
Super User

If it's crashing here:

stm32u3xx-hal-driver/Src/stm32u3xx_hal_flash_ex.c at 192823dc5f75d31dae7723163b86bf11bb218be6 · STMicroelectronics/stm32u3xx-hal-driver

there are error codes present prior to calling HAL_FLASHEx_Erase and you should address those first and find out the reason why. Why are the errors set? What does your program do?

 

If you feel a post has answered your question, please click "Accept as Solution".

Actually the error occurs at line 225. I've now tried a small program to Erase a page as such:

void attempt_erase()
{
	FLASH_EraseInitTypeDef flashErase2;
	uint32_t error;
HAL_FLASH_Unlock();
HAL_ICACHE_Disable();

flashErase2.TypeErase = 2;
flashErase2.Page = 96;
flashErase2.NbPages = 1;
flashErase2.Banks = 0;

/* erasing page/sector */
if (HAL_FLASHEx_Erase(&flashErase2, &error) != HAL_OK)
{
  printf("Failed to erase. Error code 0x%x!!!\r\n\r\n", error);
}
HAL_FLASH_Lock();
HAL_ICACHE_Enable();
}

 

And what I'm getting is: 
Failed to erase. Error code 0x60!!!

TDK
Super User

> flashErase2.Banks = 0;

Invalid parameter. Should be FLASH_BANK_1.

If you feel a post has answered your question, please click "Accept as Solution".

Doesn't make any difference. Tried with:

flashErase2.TypeErase = FLASH_TYPEERASE_PAGES;
flashErase2.Page = 96;
flashErase2.NbPages = 1;
flashErase2.Banks = FLASH_BANK_2;

 

george-metasphere
Associate III

OK, I finally found the issue by accident. It was a Clock Configuration issue. Because I set my UART at 19200bps, the MSIS divider is downclocked and the entire system runs at 1.5Mhz instead of the stable 12Mhz. This apparently causes the EEPROM write to fail. Pushing the UART and clock speeds higher solves this issue.