cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412RB Option Bytes configuration error in debugging session (perhaps HAL call bug)

BHerr.1
Associate

Hi,

I'm trying to replicate the Hands-on Flash memory Technical training for the STM32L4 (https://www.youtube.com/watch?v=ZMtsR0nZjt4) but i'm having some issues when changing the BOR level and specially in the debugging.

The instruction "HAL_FLASH_OB_Launch" seems to break/hang and thus the debugger terminates the session. The weird part is that after the reset and checking with the STM32cubeprogrammer the BOR level has indeed changed to the desired one.

I attach the code use below:

/* USER CODE END Header */
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;
 
/* USER CODE BEGIN PV */
 
static FLASH_OBProgramInitTypeDef flashOB;
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
  * @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 */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
 
  HAL_FLASH_Unlock();
  HAL_FLASH_OB_Unlock();
 
  HAL_FLASHEx_OBGetConfig(&flashOB);
  flashOB.OptionType = OPTIONBYTE_USER;
  flashOB.USERType = OB_USER_BOR_LEV;
 
  if (((flashOB.USERConfig) & (OB_BOR_LEVEL_2)) != OB_BOR_LEVEL_2)
  {
	  flashOB.USERConfig = OB_BOR_LEVEL_2;
	  if (HAL_FLASHEx_OBProgram(&flashOB) != HAL_OK) {Error_Handler();}
	  if (HAL_FLASH_OB_Launch() != HAL_OK) {Error_Handler();}
  }
  else
  {
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
  }
 
  HAL_FLASH_OB_Lock();
  HAL_FLASH_Lock();
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Any help would be highly appreciated.

Regards,

Borja H.

0 REPLIES 0