Forum: Mikrocontroller und Digitale Elektronik STM32L1 geht nicht in den low power Modus


von Gerhard G (Gast)


Lesenswert?

Hallo,

ich hab das Problem das der Microcontroller sich nicht auf den low power 
Regulator wechseln will.

Ich hab mit CubeMX das Grundgerüst erstellt, CPU läuft auf über den MSI 
mit 65,536 Khz.

Ich hab dem grundgerüst nichts weiter zugefügt ausser die verschiedenen 
versuche in den low power run modus zu schalten.

Weder das hier bringt was:
1
HAL_PWREx_EnableLowPowerRunMode();

Noch das hier:
1
  void enter_LPRun( void ){
2
3
      /* 1. Each digital IP clock must be enabled or disabled by using the
4
                     RCC_APBxENR and RCC_AHBENR registers */
5
      RCC->APB1ENR |= RCC_APB1ENR_PWREN;
6
      /* 2. The frequency of the system clock must be decreased to not exceed the
7
            frequency of f_MSI range1. */
8
      /* 3. The regulator is forced in low-power mode by software
9
            (LPRUN and LPSDSR bits set ) */
10
      PWR->CR &= ~PWR_CR_LPRUN; // Be sure LPRUN is cleared!
11
12
      PWR->CR |= PWR_CR_LPSDSR; // must be set before LPRUN
13
      PWR->CR |= PWR_CR_LPRUN; // enter low power run mode
14
  }

Der Stromverbrauch liegt bei 168µA und ändert sich nicht.
(gemessen immer mit abgestöpseltem ST-Link)
Laut Datenblatt sollen ja bis zu 11 μA im Low-power run mode möglich 
sein.

Der STANDBY Mode dagegen funktioniert wunderbar, der Stromverbrauch der 
gesamten Schaltung liegt dann bei um die 2µA.

Kann mir einer sagen was ich da falsch mache oder falsch denke?

Hier nochmal der gesamte Code:
1
/* USER CODE BEGIN Header */
2
/**
3
  ******************************************************************************
4
  * @file           : main.c
5
  * @brief          : Main program body
6
  ******************************************************************************
7
  * @attention
8
  *
9
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
10
  * All rights reserved.</center></h2>
11
  *
12
  * This software component is licensed by ST under BSD 3-Clause license,
13
  * the "License"; You may not use this file except in compliance with the
14
  * License. You may obtain a copy of the License at:
15
  *                        opensource.org/licenses/BSD-3-Clause
16
  *
17
  ******************************************************************************
18
  */
19
/* USER CODE END Header */
20
/* Includes ------------------------------------------------------------------*/
21
#include "main.h"
22
23
/* Private includes ----------------------------------------------------------*/
24
/* USER CODE BEGIN Includes */
25
26
/* USER CODE END Includes */
27
28
/* Private typedef -----------------------------------------------------------*/
29
/* USER CODE BEGIN PTD */
30
31
/* USER CODE END PTD */
32
33
/* Private define ------------------------------------------------------------*/
34
/* USER CODE BEGIN PD */
35
/* USER CODE END PD */
36
37
/* Private macro -------------------------------------------------------------*/
38
/* USER CODE BEGIN PM */
39
40
/* USER CODE END PM */
41
42
/* Private variables ---------------------------------------------------------*/
43
44
/* USER CODE BEGIN PV */
45
46
/* USER CODE END PV */
47
48
/* Private function prototypes -----------------------------------------------*/
49
void SystemClock_Config(void);
50
/* USER CODE BEGIN PFP */
51
52
/* USER CODE END PFP */
53
54
/* Private user code ---------------------------------------------------------*/
55
/* USER CODE BEGIN 0 */
56
57
/* USER CODE END 0 */
58
59
/**
60
  * @brief  The application entry point.
61
  * @retval int
62
  */
63
int main(void)
64
{
65
  /* USER CODE BEGIN 1 */
66
67
  /* USER CODE END 1 */
68
69
  /* MCU Configuration--------------------------------------------------------*/
70
71
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
72
  HAL_Init();
73
74
  /* USER CODE BEGIN Init */
75
76
  /* USER CODE END Init */
77
78
  /* Configure the system clock */
79
  SystemClock_Config();
80
81
  /* USER CODE BEGIN SysInit */
82
83
  /* USER CODE END SysInit */
84
85
  /* Initialize all configured peripherals */
86
  /* USER CODE BEGIN 2 */
87
  void enter_LPRun( void ){
88
89
      /* 1. Each digital IP clock must be enabled or disabled by using the
90
                     RCC_APBxENR and RCC_AHBENR registers */
91
      RCC->APB1ENR |= RCC_APB1ENR_PWREN;
92
      /* 2. The frequency of the system clock must be decreased to not exceed the
93
            frequency of f_MSI range1. */
94
      /* 3. The regulator is forced in low-power mode by software
95
            (LPRUN and LPSDSR bits set ) */
96
      PWR->CR &= ~PWR_CR_LPRUN; // Be sure LPRUN is cleared!
97
98
      PWR->CR |= PWR_CR_LPSDSR; // must be set before LPRUN
99
      PWR->CR |= PWR_CR_LPRUN; // enter low power run mode
100
  }
101
102
103
  //HAL_SuspendTick();
104
  //HAL_PWREx_EnableLowPowerRunMode();
105
  //enter_LPRun();
106
  //SET_BIT(PWR->CR, PWR_CR_LPSDSR);
107
  //SET_BIT(PWR->CR, PWR_CR_LPRUN);
108
109
  /* USER CODE END 2 */
110
111
  /* Infinite loop */
112
  /* USER CODE BEGIN WHILE */
113
  while (1)
114
  {
115
    /* USER CODE END WHILE */
116
117
    /* USER CODE BEGIN 3 */
118
  }
119
  /* USER CODE END 3 */
120
}
121
122
/**
123
  * @brief System Clock Configuration
124
  * @retval None
125
  */
126
void SystemClock_Config(void)
127
{
128
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
129
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
130
131
  /** Configure the main internal regulator output voltage
132
  */
133
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
134
  /** Initializes the RCC Oscillators according to the specified parameters
135
  * in the RCC_OscInitTypeDef structure.
136
  */
137
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
138
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
139
  RCC_OscInitStruct.MSICalibrationValue = 0;
140
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
141
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
142
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
143
  {
144
    Error_Handler();
145
  }
146
  /** Initializes the CPU, AHB and APB buses clocks
147
  */
148
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
149
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
150
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
151
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
152
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
153
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
154
155
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
156
  {
157
    Error_Handler();
158
  }
159
}
160
161
/* USER CODE BEGIN 4 */
162
163
/* USER CODE END 4 */
164
165
/**
166
  * @brief  This function is executed in case of error occurrence.
167
  * @retval None
168
  */
169
void Error_Handler(void)
170
{
171
  /* USER CODE BEGIN Error_Handler_Debug */
172
  /* User can add his own implementation to report the HAL error return state */
173
  __disable_irq();
174
  while (1)
175
  {
176
  }
177
  /* USER CODE END Error_Handler_Debug */
178
}
179
180
#ifdef  USE_FULL_ASSERT
181
/**
182
  * @brief  Reports the name of the source file and the source line number
183
  *         where the assert_param error has occurred.
184
  * @param  file: pointer to the source file name
185
  * @param  line: assert_param error line source number
186
  * @retval None
187
  */
188
void assert_failed(uint8_t *file, uint32_t line)
189
{
190
  /* USER CODE BEGIN 6 */
191
  /* User can add his own implementation to report the file name and line number,
192
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
193
  /* USER CODE END 6 */
194
}
195
#endif /* USE_FULL_ASSERT */
196
197
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

von reminder (Gast)


Angehängte Dateien:

Lesenswert?

F*ck!

Lesen, verinnerlichen und umsetzen!

von Johannes S. (Gast)


Lesenswert?

da würde mal dieses Beispiel probieren:
https://github.com/STMicroelectronics/STM32CubeL1/tree/master/Projects/NUCLEO-L152RE/Examples/PWR/PWR_LPRUN

Im wesentlichen wird wohl auch EnableLowPowerRun aufgerufen.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.