2019-02-08 01:14 AM
Hi community,
I'm currently struggling hard with the dual bank boot on the stm32L476:
Did anybody here managed in achieving my option B, if yes, where to find the small bit of code that would achieve that feature ?
2019-02-11 04:59 AM
Well, I've been struggling hard again with ST's HAL documentation, and I'm now stucked there: as soon as I call the HAL_FLASHEx_OBProgram, I got an HAL_ERROR code in return (and option bytes are not writen, of course). Here's the code I'm trying:
void OptionByteSet(bool bfb2)
{
int retCode;
FLASH_OBProgramInitTypeDef optionBytes; // Structure that holds the option bytes to be programmed
printf("\r\n*********************** SETTING BFB2 ****************************");
if(HAL_FLASH_Unlock()==HAL_OK) // Unlock the flash controls registers
{
printf("\r\n\tHAL_FLASH_Unlock -> OK");
}
else
{
printf("\r\n\tHAL_FLASH_Unlock -> Failure");
}
if (HAL_FLASH_OB_Unlock()==HAL_OK) // Unlock the option bytes controls registers
{
printf("\r\n\tHAL_FLASH_OB_Unlock -> OK");
}
else
{
printf("\r\n\tHAL_FLASH_OB_Unlock -> Failure");
}
HAL_FLASHEx_OBGetConfig(&optionBytes); // Get current optionbytes configuration
printf("\r\n-------------------Before modifications");
OptionByteDisplay(&optionBytes);
optionBytes.OptionType = OPTIONBYTE_USER;
optionBytes.USERType = OB_USER_BFB2;
if (bfb2) // Set the bfb2 option bit as needed
optionBytes.USERConfig |= OB_BFB2_ENABLE;
else
optionBytes.USERConfig &= ~OB_BFB2_ENABLE;
printf("\r\n-------------------Projected modifications");
OptionByteDisplay(&optionBytes);
if ((retCode=HAL_FLASHEx_OBProgram(&optionBytes))==HAL_OK)
{
printf("\r\n\r\n BFB2 Configuration OK");
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
retCode = HAL_FLASH_OB_Launch();
printf("\r\n\r\n BFB2 Validation, code=%02X",retCode);
}
else
{
printf("\r\n\r\n BFB2 Configuration Failure, code=%02X",retCode);
}
printf("\r\n-------------------After modifications");
HAL_FLASHEx_OBGetConfig(&optionBytes); // Get current optionbytes configuration
OptionByteDisplay(&optionBytes);
}
Here's the ouput I'm getting:
*********************** SETTING BFB2 ****************************
HAL_FLASH_Unlock -> OK
HAL_FLASH_OB_Unlock -> OK
-------------------Before modifications
OPTION BYTES
OptionType = 00000007
WRPArea = 00000000
WRPStartOffset = 000000FF
WRPEndOffset = 00000000
RDPLevel = 000000AA
USERType = 20000014
USERConfig = FFAFF800
PCROPConfig = 5C613118
PCROPStartAddr = 00000000
PCROPEndAddr = 00000000
-------------------Projected modifications
OPTION BYTES
OptionType = 00000004
WRPArea = 00000000
WRPStartOffset = 000000FF
WRPEndOffset = 00000000
RDPLevel = 000000AA
USERType = 00000080
USERConfig = FFBFF800
PCROPConfig = 5C613118
PCROPStartAddr = 00000000
PCROPEndAddr = 00000000
BFB2 Configuration Failure, code=01
-------------------After modifications
OPTION BYTES
OptionType = 00000007
WRPArea = 00000000
WRPStartOffset = 000000FF
WRPEndOffset = 00000000
RDPLevel = 000000AA
USERType = 00000080
USERConfig = FFAFF800
PCROPConfig = 5C613118
PCROPStartAddr = 00000000
PCROPEndAddr = 00000000
Does anyone here have an idea on what I'm currently missing ?