cancel
Showing results for 
Search instead for 
Did you mean: 

how to program the option bytes within firmware

KoSt
Associate III

Hello,
After reading the following threads:
How to program STM32 Option Bytes with the HAL API - STMicroelectronics Community
What are option bytes in STM32 and how do I use th... - STMicroelectronics Community
Problem with option bytes set from program level- ... - STMicroelectronics Community
and the manual:
STM32L41xxx/42xxx/43xxx/44xxx/45xxx/46xxx advanced Arm®-based 32-bit MCUs - Reference manual

I tried to stop the watchdog in the STM32G030C8TX under low power MCU modes, by adjusting the option bytes accordingly using the following examples of the HAL library but I get hardware faults. What am I missing?

 

HAL_StatusTypeDef set_OB(void) {

    FLASH_OBProgramInitTypeDef OB;
    HAL_FLASHEx_OBGetConfig(&OB);

    HAL_FLASH_Unlock();
    HAL_FLASH_OB_Unlock();

    OB.OptionType = OPTIONBYTE_USER;
    OB.USERType = OB_USER_IWDG_STOP;
    OB.USERConfig = OB_IWDG_STOP_FREEZE;

    if ( HAL_FLASHEx_OBProgram(&OB) != HAL_OK )
    {
      HAL_FLASH_OB_Lock();
      HAL_FLASH_Lock();
      return HAL_ERROR;
    }

    HAL_FLASH_OB_Launch();

    /* We should not make it past the Launch, so lock
    * flash memory and return an error from function
    */
    HAL_FLASH_OB_Lock();
    HAL_FLASH_Lock();
    return HAL_ERROR;
}

 

 

 

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */
  set_OB();
  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_ADC1_Init();
  MX_RTC_Init();
  MX_TIM16_Init();
  MX_IWDG_Init();
  /* USER CODE BEGIN 2 */
  Application();		// Call Application
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

0 REPLIES 0