This post was last edited by Electronic Bad Guy on 2024-5-5 16:58
Recently, when I was working on RTC and LCD, I found that the MSI clock of U0 is very interesting, and it is worth writing a supplementary article separately:
1. Introduction of MSI:
MSI ( Multispeed internal RC oscillator ) is composed of an RC circuit, which consists of a resistor (R) and a capacitor (C) to generate a stable clock signal inside the microcontroller. The term "Multispeed " means that this oscillator can provide multiple different clock frequencies. This design is designed to allow the microcontroller to run in different operating modes to optimize power consumption and performance. The original intention of this design was to flexibly develop clock frequencies at a low cost, and to operate at different frequencies in low power mode and high speed mode.
A more complete composition can be seen in the system diagram in the U0 manual: (The picture is incomplete, the lower half is omitted)
In addition, there is a separate introduction in the RCC clock section of the manual:
The latest MSI application note is for the U5 series and can be used for reference: How to calibrate internal RC oscillators on STM32U5 Series - Application note
2. Configure MSI:
In the clock configuration interface of STM32U0, you can see that MSI can be used as a system clock multiplexer to configure the main frequency (the maximum frequency of U083 microcontroller is 48MHZ).
In addition, the frequency can be increased by passing through the PLL phase-locked loop:
Take the previous case as an example to generate a sample project.
3. Low power mode
STM32U0 has six modes: Sleep, Low-power run mode, Low-power sleep mode, stop, standby, and shutdown, which are sufficient to cope with various usage scenarios in actual development.
The only two modes mentioned are stop and shutdown, and MSI is disabled in both modes.
The stop mode is more diverse, with three sub-modes, corresponding to different situations:
In the actual development of this project, especially when running on battery, the STOP mode is more common. Compared with the standby and shutdown modes, it can retain key data while saving power, and the RTC continues to work, so the stop mode is used as an example for demonstration;
There are two wake-up methods for STOP mode: Interruption and Event. The corresponding parameters are in STM32u0xx_hal_pwr.h:
/** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
* @{
*/
#define PWR_STOPENTRY_WFI ((uint8_t)0x01)/*!< Wait For Interruption instruction to enter Stop mode */
#define PWR_STOPENTRY_WFE ((uint8_t)0x02)/*!< Wait For Event instruction to enter Stop mode */
/**
* @}
*/
The APIs for the three stop modes are:
void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)//STOP0
void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)//STOP1
void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)//STOP2
//注:STOP0模式没有找到该函数,暂不清楚原因,可能是调用与另外两种不同
Taking STOP1 mode as an example, the code definition is as follows: (from the file stm32u0xx hal_pwr_ex.c)
void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
{
/* Check the parameters */
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
/* Stop 1 mode with Low-Power Regulator */
MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_0);
/* Set SLEEPDEEP bit of Cortex System Control Register */
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
/* Select Stop mode entry --------------------------------------------------*/
if (STOPEntry == PWR_STOPENTRY_WFI)
{
/* Request Wait For Interrupt */
__WFI();
}
else
{
/* Request Wait For Event */
__SEV();
__WFE();
__WFE();
}
/* Reset SLEEPDEEP bit of Cortex System Control Register */
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
}
4. Write code and observe the phenomenon
Add the following code to the main function:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
for(i=0;;i++)
{
count=count+1;//设置一个计数器
HAL_Delay(1000);
BSP_LED_Toggle(LED_GREEN);
if(count==9)//计数器9秒后进入STOP模式
{
HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
HAL_Delay(10000);//停止10秒
SystemClock_Config();//重新配置时钟
break;//退出STOP模式,继续计数
}
}
The experimental phenomenon is: after the green light flashes for 9 seconds, it enters the stop mode, stops for 10 seconds and then exits the stop mode. The whole process uses MSI as the clock source.
meeting_01