2025-08-28 11:12 PM
Hi everyone,
I’m working on an STM32U3 project and ran into an issue where flash erase was failing with error code 0x00000080 on page erase, even though the option bytes and addresses appeared correct.
After debugging, I found that explicitly setting the voltage scaling to PWR_REGULATOR_VOLTAGE_SCALE1 before flash erase resolved the issue. The working sequence I use is:
HAL_FLASH_Unlock();
HAL_StatusTypeDef status = HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
if(status != HAL_OK)
{
return status;
}
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = BankNumber;
EraseInitStruct.Page = FirstPage;
EraseInitStruct.NbPages = NbOfPages;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
{
return status;
}
This step wasn’t required on my Nucleo board but was essential on my custom hardware.
My questions now are:
Is it safe and recommended to keep the voltage scaling at SCALE1 permanently after flash erase, or should I revert it to a lower scale for power saving?
If switching back to a lower scale after flash operations, are there any precautions or delays needed during the transition?
Are there any additional best practices around voltage scaling and flash erase/programming on STM32U3 devices that I should be aware of?
Thanks in advance for your help!
Rakesh
Solved! Go to Solution.
2025-08-31 7:32 AM
Hello @vijayrakesh
Thanks a lot for your detailed and pertinent questions.
Regarding your issue and the use of voltage scaling during flash erase/program operations on STM32U3 devices, here are some clarifications based on the STM32U3 Reference Manual (RM0487 Rev 1), pages 202 and 203:
Voltage range for Flash operations:
Flash program and erase operations are only allowed when the device is operating in range 1. Attempting these operations in range 2 will result in a PGSERR (Programming Sequence Error), which matches the error code you observed (0x00000080).
This means the voltage regulator must be set to PWR_REGULATOR_VOLTAGE_SCALE1 before starting any flash erase/program sequence to ensure proper operation and avoid errors.
Power saving after Flash operations:
If your application does not require additional flash operations immediately after, it is perfectly safe and recommended to revert the voltage scaling back to range 2 (lower voltage range) to save power.
When switching back to a lower voltage scale, ensure that the system clock frequency is adjusted accordingly because range 2 supports a maximum CPU frequency of 20 MHz. You may need to adjust flash latency and clock settings to match this lower frequency to maintain system stability.
Precautions when switching Voltage Scales:
Additional Best Practices:
Illustrations:
Please feel free to respond and confirm whether this resolves your request or not.
Best regards,
Haifa.
2025-08-31 7:32 AM
Hello @vijayrakesh
Thanks a lot for your detailed and pertinent questions.
Regarding your issue and the use of voltage scaling during flash erase/program operations on STM32U3 devices, here are some clarifications based on the STM32U3 Reference Manual (RM0487 Rev 1), pages 202 and 203:
Voltage range for Flash operations:
Flash program and erase operations are only allowed when the device is operating in range 1. Attempting these operations in range 2 will result in a PGSERR (Programming Sequence Error), which matches the error code you observed (0x00000080).
This means the voltage regulator must be set to PWR_REGULATOR_VOLTAGE_SCALE1 before starting any flash erase/program sequence to ensure proper operation and avoid errors.
Power saving after Flash operations:
If your application does not require additional flash operations immediately after, it is perfectly safe and recommended to revert the voltage scaling back to range 2 (lower voltage range) to save power.
When switching back to a lower voltage scale, ensure that the system clock frequency is adjusted accordingly because range 2 supports a maximum CPU frequency of 20 MHz. You may need to adjust flash latency and clock settings to match this lower frequency to maintain system stability.
Precautions when switching Voltage Scales:
Additional Best Practices:
Illustrations:
Please feel free to respond and confirm whether this resolves your request or not.
Best regards,
Haifa.
2025-08-31 9:21 PM
Thanks for the detailed explanation @Hai