2015-09-05 01:40 AM
Dear all
I have a boot problem with the STM32F042G4U6 (uVision V5.14.0.0.). I designed a custom board and sadly forgot to connect the Boot0 (floating) to GND. Because of that, I can program the MCU, but the controller don’t starts my program... In the Reference manual (RM0091), Page 52 I found some information about booting options. The table 3 shows me, that I can set the boot option also by BOOT_SEL and nBOOT0, independent of the Boot0 Pin level. Further, I found the corresponding Bits in the Flash Option byte register (FLASH_OBR). BOOT_SEL -> Bit 15 of FLASH_OBR, nBOOT0 -> Bit 11 of FLASH_OBR. Now my big question: Where and how can I change this two Bits, before start up? Has anybody an idea or did this before? For me it’s really important to solve this problem! My guess is, that I have to change something in the startup file (startup_stm32f042.s). But I don’t have the view about this file… I already activated the Configuration Wizard in the startup File, but there are no information about startup. Thanks for your help, Simon2015-09-05 05:35 AM
While you can set the option bytes within your own code, it sounds more like what you need to do here is use the ST-LINK utilities, or Flash Loader Demonstrator, and set them as part of your part programming scheme.
The System Loader should also permit you to upload code into RAM, and execute it. This would allow you to code what every you want into a small applet.2015-09-05 12:01 PM
Hi Clive
Thanks for your quick answer! For me the best and easiest way will be, if I can add some code to fix my problem. Do you have a clue, where I have to add this code? In the system_stm32f0xx.c file or in the startup_stm32f042.s file? And how can I write the FLASH_OBR register? I downloaded the STM32 ST-LINK Utility software. Sadly I don’t have a ST-LINK (onely a j-link and a ULINK-ME) at the moment. But that’s not a problem to get one in the next few days. In the STM32 ST-LINK Utility software I found the option “Option Bytes�? (Target -> Option Bytes). Will this option help me? Testing is impossible in case of missing ST-Link… But if there is a code option to solve my problem, that will be my favorite! Sorry for my English, it isn’t very good and thanks a lot for helping me! Simon2015-09-05 02:10 PM
Keil should allow you to add a Flash Algorithm for the options portion of the STM32F0, the mechanics of using it aren't something I have delved into.
The way the options work is just basic code execution, it doesn't need to exist in startup_stm32f0xx.s or system_stm32f0xx.c as your code would have to be running to get there anyway. Here's how option bytes get programmed of the F0 parts, you'd have to look at specifically what bits/aspect you need to change and the functions used. [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/flash%20readback%20protection&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=307]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/flash%20readback%20protection&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=307 Specifically FLASH_OB_BootConfig() and FLASH_OB_Boot0Config()/**
* @brief Sets or resets the BOOT1 option bit.
* @param OB_BOOT1: Set or Reset the BOOT1 option bit.
* This parameter can be one of the following values:
* @arg OB_BOOT1_RESET: BOOT1 option bit reset
* @arg OB_BOOT1_SET: BOOT1 option bit set
* @retval None
*/
FLASH_Status FLASH_OB_BOOTConfig(uint8_t OB_BOOT1)
{
FLASH_Status status = FLASH_COMPLETE;
/* Check the parameters */
assert_param(IS_OB_BOOT1(OB_BOOT1));
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(status == FLASH_COMPLETE)
{
/* Enable the Option Bytes Programming operation */
FLASH->CR |= FLASH_CR_OPTPG;
OB->USER = OB_BOOT1 | 0xEF;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(status != FLASH_TIMEOUT)
{
/* If the program operation is completed, disable the OPTPG Bit */
FLASH->CR &= ~FLASH_CR_OPTPG;
}
}
/* Return the Option Byte program Status */
return status;
}
/**
* @brief Sets or resets the BOOT0 option bit.
* @note This function is applicable only for the STM32F042 devices.
* @param OB_BOOT0: Set or Reset the BOOT0 option bit.
* This parameter can be one of the following values:
* @arg OB_BOOT0_RESET: BOOT0 option bit reset
* @arg OB_BOOT0_SET: BOOT0 option bit set
* @retval None
*/
FLASH_Status FLASH_OB_BOOT0Config(uint8_t OB_BOOT0)
{
FLASH_Status status = FLASH_COMPLETE;
/* Check the parameters */
assert_param(IS_OB_BOOT0(OB_BOOT0));
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(status == FLASH_COMPLETE)
{
/* Enable the Option Bytes Programming operation */
FLASH->CR |= FLASH_CR_OPTPG;
OB->USER = OB_BOOT0 | 0xF7;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(status != FLASH_TIMEOUT)
{
/* If the program operation is completed, disable the OPTPG Bit */
FLASH->CR &= ~FLASH_CR_OPTPG;
}
}
/* Return the Option Byte program Status */
return status;
}
/**
* @brief Sets or resets the BOOT0SW option bit.
* @note This function is applicable only for the STM32F042 devices.
* @param OB_BOOT0SW: Set or Reset the BOOT0_SW option bit.
* This parameter can be one of the following values:
* @arg OB_BOOT0_SW: BOOT0_SW option bit reset
* @arg OB_BOOT0_HW: BOOT0_SW option bit set
* @retval None
*/
FLASH_Status FLASH_OB_BOOT0SWConfig(uint8_t OB_BOOT0SW)
{
FLASH_Status status = FLASH_COMPLETE;
/* Check the parameters */
assert_param(IS_OB_BOOT0SW(OB_BOOT0SW));
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(status == FLASH_COMPLETE)
{
/* Enable the Option Bytes Programming operation */
FLASH->CR |= FLASH_CR_OPTPG;
OB->USER = OB_BOOT0SW | 0x7F;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(status != FLASH_TIMEOUT)
{
/* If the program operation is completed, disable the OPTPG Bit */
FLASH->CR &= ~FLASH_CR_OPTPG;
}
}
/* Return the Option Byte program Status */
return status;
}