cancel
Showing results for 
Search instead for 
Did you mean: 

High start up time for STM32L4

Waller.George
Associate III

I'm currently developing a project that will see a high number of MCUs connected in the end application so low power consumption is critical. I was aware there will be some initial high power consumption when first powered up however the MCU takes ~300ms before it enters the low power mode I'm using. This is causing us problems in the end application.

Attached is the startup code I am using. By plotting in the input current and setting GPIOs I have determined the high power consumption ends after SystemClock_Config();.

Is this normal? Is it possible to speed up the startup time? I'm using the STM32L431RB.

Thanks

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 */
	MX_GPIO_Init();
 
	/* USER CODE END SysInit */
 
	/* Initialize all configured peripherals */
 
	/* USER CODE BEGIN 2 */
}

This is my clock configuration:

/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 
	RCC_OscInitTypeDef RCC_OscInitStruct = {0};
	RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
	RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
 
	/** Initializes the CPU, AHB and APB busses clocks
	 */
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
	RCC_OscInitStruct.MSIState = RCC_MSI_ON;
	RCC_OscInitStruct.MSICalibrationValue = 0;
	RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
	if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
	{
		Error_Handler();
	}
	/** Initializes the CPU, AHB and APB busses clocks
	 */
	RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
	RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
	if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
	{
		Error_Handler();
	}
	PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
	PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
	if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
	{
		Error_Handler();
	}
	/** Configure the main internal regulator output voltage
	 */
	if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
	{
		Error_Handler();
	}
 
	// Disable HSI to reduce power consumption since MSI is used from that point
	__HAL_RCC_HSI_DISABLE();
}

2 REPLIES 2

300ms sounds way too much. The time while processor is "out of control" beween VCC reaches poweron reset level or any set BOR level (see datasheet) is given in datasheet as "temporization" time, and it's in the order of several 100us (that may be still annoying for some applications, but 3 orders of magnitude less than what you wrote).

Drop Cube and also drop the default startup code. Write your own starupt code, starting with setting clock and voltage regulator of your choice.

JW

TDK
Guru

The startup code copies data to RAM and sets some of RAM to zero, then it does some initialization, then it calls main(), which eventually calls SystemClock_Config.

If you have large data segments, it's reasonable for this to take 300ms.

You can add a call to a clock initialization function at the very start of the startup script, but you need to be aware variables outside of FLASH have not been initialized yet.

The startup script can also be optimized a bit by unrolling loops, but you'll only get a factor of 2-4ish improvement or so by this.

If you feel a post has answered your question, please click "Accept as Solution".