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();
}

 

 

{} 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 */

 

 

 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

 

0 REPLIES 0