cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32l011 refuses to go into stop mode

fanfan6966
Associate II

Hello everyone,

I have a problem with my STM32L011G4U6, I want to put it in stop mode or in standby mode, but the two modes are not taken into account, only the sleep mode works, I must surely make a mistake but where? here is my function:

 

	void Enter_MCU_Sleep(void) {
	
        HAL_Delay(1000);
		HAL_UART_Transmit(&huart2, (uint8_t *)"Dort\r\n", 33, 300);

	    // Configurer et lancer le timer
	    __HAL_TIM_SET_COUNTER(&htim2, 0);
	    HAL_TIM_Base_Start_IT(&htim2); // Timer doit générer une IT de réveil

	    // Désactiver les périphériques pour réduire la consommation
	    //HAL_ADC_DeInit(&hadc);
	    HAL_UART_DeInit(&hlpuart1);
	    HAL_UART_DeInit(&huart2);
	    //__HAL_RCC_ADC1_CLK_DISABLE();
	    __HAL_RCC_LPUART1_CLK_DISABLE();
	    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
	    HAL_NVIC_DisableIRQ(DMA1_Channel2_3_IRQn);
	    HAL_NVIC_DisableIRQ(DMA1_Channel4_5_IRQn);

	    // Désactiver le RTC et l'oscillateur LSE
	    HAL_RTCEx_DeactivateWakeUpTimer(&hrtc); // Désactiver le wakeup timer
	    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
	    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
	    RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
	    HAL_RCC_OscConfig(&RCC_OscInitStruct);
	    __HAL_RCC_RTC_DISABLE(); // Désactiver l'horloge RTC

	    //__HAL_RCC_USART2_CLK_DISABLE();
	    __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_UPDATE);
	    __HAL_TIM_CLEAR_IT(&htim2, TIM_IT_UPDATE);
	    // Entrer en STOP mode


	    HAL_SuspendTick();

	    //HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI); // ou STOP
	   HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
	   //HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
	    //HAL_PWR_EnterSTANDBYMode();

	    HAL_TIM_Base_Stop_IT(&htim2); // Stopper le timer


	    HAL_ResumeTick();

	    // ⚡️ Après STOP
	    SystemClock_Config();   // Rétablir les clocks


	    HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
	    HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
	    HAL_NVIC_EnableIRQ(DMA1_Channel4_5_IRQn);
	    // Réinitialiser les périphériques
	    MX_GPIO_Init();
	   // MX_ADC_Init();
	    MX_LPUART1_UART_Init();
	   // MX_USART2_UART_Init();

	    HAL_Delay(3000); // Stabilisation modem
	    HAL_UART_Transmit(&huart2, (uint8_t *)"Réveil\r\n", 23, 300);
	    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);  // PA5 à l'état bas
	    HAL_Delay(2000);                                        // Attendre 1 seconde
	    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);    // PA5 à l'état haut
	    //gps_and_battery_task();
	    //gestion_sms_etat();
	    //boucle1();
	    //check_moduleori_ready();
	    HAL_Delay(1000);



}
11 REPLIES 11
TDK
Super User

Please see the examples for how to enter stop mode. Get those working. Once working, implement within your code.

STM32CubeL0/Projects/NUCLEO-L011K4/Examples/PWR/PWR_STOP at 804ccaeb6301dfcbfba6c3d18520ddd4226b6355 · STMicroelectronics/STM32CubeL0

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

Thanks, but that doesn't help me.

Andrew Neil
Super User

Welcome to the forum.

Please see How to write your question to maximize your chances to find a solution for best results.

In particular, please fully describe your hardware and software setup.

 


@fanfan6966 wrote:

the two modes are not taken into account

What do you mean by that? 

What, exactly, happens?

 

As @TDK said, you should try the ST examples first, as reference - preferably on an ST board.

Have you done that? What were the results?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Well, the examples are there to refer to if you can't figure it out. I don't think the issue is within the code that you've presented.

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

Hello, 1) Andrew Neil: nothing happens in stop mode or in standby mode the consumption does not vary, on the other hand if I put it in sleep mode then it's OK, 2) TDK, the codes you indicated to me have no effect, I adapted them to my personalized PCB but still the same, I think more of a clock configuration or a forgotten parameter under cubeMX and not a problem since it works in sleep mode.

fanfan6966
Associate II

I would like to point out that I do not know the stm32 and that I am basing my code solely on the official documentation and forums.


@fanfan6966 wrote:

I would like to point out that I do not know the stm32 


All the more reason to start with the standard ST examples on an ST board.

Get the examples working & gain familiarity in a known environment, and then use that as a reference for your custom design.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
fanfan6966
Associate II

Hello, I am disappointed with the answers, my personal PCB works perfectly, my code is taken from the examples given, and what do we propose? to buy a ready-made board from the manufacturer?? What will that do for me? apart from losing money! I don't know the STM32, of course, but I'm not a beginner in coding either. If the solution is to buy a ready-made product, then we must stop all DIY initiatives, and consume like sheep.

I proposed you get a known working example up and running. It's even for the same chip. Not to buy a different board.

You could also post a full compliable project which exhibits the problem. Unfortunately, my powers of clairvoyance are limited and I'm sometimes unable to spot errors in the part of the code that is not posted.

The posted example works on the board it was intended for. It only uses internal clocks so there is no reason for it not to work on any other board with the same chip. Your code differs quite a bit from it, but again, I cannot see all of your code so don't know if that is significant or not.

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