cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL5MOC EXTI and STOP2

JE
Associate II

Hi,

I am trying to write a battery powered application with a STM32WL5MOC. The LoRa capability and the form factor are crucial. The dual-core feature unfortunately makes everything so much more complex. I only need the CM0+... so in the future the CM4 shall stay in stop/standby mode, but for simplicity it's currently running in a while(1) loop.

Now I simply want to set CM0+ into stop mode to save some power, so I did this:

 

 

volatile uint8_t lptim_timeout_flag = 0; void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) { if(hlptim->Instance == LPTIM1) lptim_timeout_flag = 1; } void HAL_Delay(uint32_t ms) { /* Suspend SysTick to prevent periodic wake-ups. */ HAL_SuspendTick(); /* Reset the LPTIM timeout flag. */ lptim_timeout_flag = 0; /* Start LPTIM in timeout mode. */ if(HAL_LPTIM_OnePulse_Start_IT(&hlptim1, ms, ms) != HAL_OK) Error_Handler(); /* Enter STOP mode */ while (ms > 0 && lptim_timeout_flag == 0) // {} WORKS // __WFI(); WORKS // HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI); NEVER returns??? /* Execution resumes here after wake-up */ /* Clear Stop2 flag of CPU2 */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_C2STOP2); //QUESTION: can CPU2 do this? SystemClock_Config(); //ALTERNATIVE approach wake up CPU1 to reconfig clock (in case it sleeps as well) HAL_HSEM_Take(HSEM_ENTERSTOP, HSEM_PROCESSID_MIN); while(HAL_HSEM_IsSemTaken(HSEM_ENTERSTOP) == 0); HAL_HSEM_Release(HSEM_ENTERSTOP, HSEM_PROCESSID_MIN); HAL_LPTIM_OnePulse_Stop_IT(&hlptim1); /* update time */ uwTick += ms; HAL_ResumeTick(); }
View more

 

 

{} and __WFI() both work, but are not as efficient as the real deal: HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
However, it seems to never return, also the interrupt is working?! I must admit i loose the debugger during this call as well. HAL_EnableDBGStopMode(); seems not to be available for the CM0+?

[I have a follow up questions: once this is solved: Can CM0+ config the system clock as well, or do i need to wake up CPU1 for this job? Already tried the latter, that seems to work.]

Now, back to my main problem. I tried to wake the CPU2 in line 24 by using an external interrupt (EXTI). But I must admit I even failed to configure it... Sure I configured a pin as GPIO_EXTIx but in NVIC2 all the EXTI lines are grayed out, for BOTH CPUs (=NVIC1 as well). I have seen other assiging the interrupt pin to a certain CPU like so:
Screenshot 2025-02-05 at 15.05.51.png

Screenshot 2025-02-05 at 15.13.46.png

But this option is not available for my GPIOs? The picture shows its for an I2C pin, which i can't select anything. No matter what i press, it always shows 'free'???

So I tried to configure everything manually:

 

 

/* USER CODE BEGIN 1 */ #if 0 /* USER CODE END 1 */ /** Pinout Configuration */ void MX_GPIO_Init(void) { /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); } /* USER CODE BEGIN 2 */ #endif //note: due to some reason it does not generate GPIO code... so we have to do it... void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /* Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); /* Configure GPIO pins : LED_Pin */ GPIO_InitStruct.Pin = LED_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); /* Configure GPIO pin : BTN0_Pin */ GPIO_InitStruct.Pin = BTN0_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(BTN0_GPIO_Port, &GPIO_InitStruct); HAL_NVIC_SetPriority(EXTI3_2_IRQn, 1, 0); HAL_NVIC_EnableIRQ(EXTI3_2_IRQn); } /* USER CODE END 2 */
View more

 

 

 Unfortunately with limited success. It wakes up again, i can debug it. BUT if gets stuck in the UART2 Handler which is not configured at all (=some random place indicating that something is wrong).

So why doesn't the configurator allow me to asign various GPIOs to individual CPUs (incl EXIT) and why isn't the code generated? I am missing something here?!

 

Thanks in advance!

Juergen

 

4 REPLIES 4
JE
Associate II

Ok I am a little further.

First I found the trick to make a single core project out of it. Right in the beginning of the project setup... quite hidden.
NONETHELESS I'd really would like to understand the dual core config stuff: why I can't even get a simple GPIO generated automatically AND how to configure interrupts (EXTI lines) properly. So please tell me.

 

Currently everything is running on the CM4, but the CM0+ is much more energy conserving and would have enough power...

 

Regarding the Stop mode, I figured it out. LPTIM1 does not need to generates an NVIC interrupt for wakeup but rather an EXTI.
I was missing this line:
__HAL_LPTIM_LPTIM1_EXTI_ENABLE_IT();

 

Bests,

Juergen

Hello @JE 

If you want to have more details on how to work on dual core STM32WL Projects, I suggest you take a look at the AN5564.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

cmars
Associate

@JE , The ST answer does not really help you sadly, I doubt they have a definitive answer. 

I have found out the cubeMX interface does not always garantee a code generation after modifications have been made. I have had better luck cycling components/features for increased reliability (tick off, save project, generate, restart cubemx, tick on, save, generate). 

As the  AN5564 (not so) clearly states, you should start from a bare project, then add features one by one, and checking at which point your option becomes greyed out. You will have to bypass this conflict or find another combination of features/settings to render your goal possible.

We're in the same boat my friend.

JE
Associate II

@cmars ,

Hi, I must admit defeat. Having the change for a dual core APP really kicked me and I wanted to make it happen, really hard... But in the end I just configured the project as 'single core' and went with it.

If you don't know, there is an option for that right when you generate the project. One can select between single and dual core.

 

Sure AN5564 fixed some issues and I could as well ignore the code generator. But for my 2 cent, I think ST has to do some more homework before it is really usable.

 

Cheers,

Juergen