本帖最后由 LiuDW091 于 2025-7-30 15:02 编辑
#有奖活动# #申请开发板# #申请原创#@21小跑堂
一、首先通原理图、数据手册,找到低功耗模式有关的介绍
通过数据手册知道,低功耗模式分为这几种:sleep(睡眠)、stop(0/1/2/3)(停止),standby(待机)、shutdown(关机)。
通过串口选择不同的模式,然后进行此次低功耗模式测试实验。
二、IDE软件配置
PWR配置:
USART1配置:
ICACHE配置:
NVIC配置:
RCC配置:
GPIO配置:
三、代码调试
参考例程进行代码的添加、修改。
添加串口选择代码:
static const char limiter_lg[] = " *******************\r\n"; static const char start_lg[] = " * 低功耗测试 * \r\n";
/* Configuration selection buffer */ static const char mode_select_lg[] = "模式选择: \r\n";
/* Low power buffer */ static const char *const lowpower_mode_lg[] = { "01 -->SLEEP mode \r\n", " 02 -->STOP1 mode \r\n", " 03 -->STOP2 mode \r\n", " 04 -->STOP3 mode \r\n", " 05 -->STANDBY mode \r\n", " 06 -->SHUTDOWN mode \r\n", };
/* Footer buffer */ static const char system_lowpower_config_lg[] = " 选择的模式为: \r\n"; static const char start_measure_lg[] = " 可以开始测试了 \r\n";
配置时钟,选择通道
System_StatusTypeDef system_ram_retention_config(System_LowPowerModeScenarioTypeDef scenario)
{
System_StatusTypeDef status = SYSTEM_OK;
/* Enable Power Clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* Disable cache and clear flags for low power modes */
if (scenario >= SYSTEM_LOWPOWER_S1)
{
HAL_ICACHE_Disable();
HAL_ICACHE_DeInit();
__HAL_ICACHE_CLEAR_FLAG(ICACHE_FLAG_BUSYEND | ICACHE_FLAG_ERROR);
}
HAL_PWREx_DisableSRAM2ContentStandbyRetention(PWR_SRAM2_FULL_STANDBY_RETENTION);
HAL_PWREx_DisableRAMsContentStopRetention(PWR_SRAM1_FULL_STOP_RETENTION);
HAL_PWREx_DisableRAMsContentStopRetention(PWR_SRAM2_FULL_STOP_RETENTION);
HAL_PWREx_DisableRAMsContentStopRetention(PWR_FDCAN_USB_STOP_RETENTION);
HAL_PWREx_DisableRAMsContentStopRetention(PWR_ICACHE_STOP_RETENTION);
HAL_PWREx_DisableRAMsContentStopRetention(PWR_PKA_STOP_RETENTION);
HAL_PWREx_DisableSRAMFastWakeUp();
/* Wait that default config is effective */
__DSB();
/* Set specific configurations */
switch (scenario)
{
/* Stop 1 - 8-Kbyte SRAM */
case SYSTEM_LOWPOWER_S2:
{
HAL_PWREx_EnableRAMsContentStopRetention(PWR_SRAM2_PAGE3_STOP_RETENTION);
break;
}
/* Stop 2 - 8-Kbyte SRAM */
case SYSTEM_LOWPOWER_S3:
{
HAL_PWREx_EnableRAMsContentStopRetention(PWR_SRAM2_PAGE3_STOP_RETENTION);
break;
}
/* Stop 3 - 8-Kbyte SRAM */
case SYSTEM_LOWPOWER_S4:
{
HAL_PWREx_EnableRAMsContentStopRetention(PWR_SRAM2_PAGE3_STOP_RETENTION);
break;
}
/* Standby - No retention */
case SYSTEM_LOWPOWER_S5:
{
/* Do nothing */
break;
}
/* Shutdown - No retention */
case SYSTEM_LOWPOWER_S6:
{
/* Do Nothing */
break;
}
}
/* Wait that default config is effective */
__DSB();
return status;
}
主函数:
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ICACHE_Init();
MX_USART1_UART_Init();
/* Enable SMPS if required */
if(USE_SMPS == 1U)
{
HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY);
}
/* Print header hyper-terminal lg */
if (lowpower_header_scenario(&LowPower_Scenario) != SCENARIO_OK)
{
Error_Handler();
}
/* Get system low power configuration */
if (lowpower_get_scenario(&LowPower_Scenario) != SCENARIO_OK)
{
Error_Handler();
}
/* Print footer hyper-terminal lg */
if (lowpower_footer_scenario(&LowPower_Scenario) != SCENARIO_OK)
{
Error_Handler();
}
/* DeInit UART before entering in the selected power mode */
USART1_UART_DeInit();
/* Configure system low power as selected */
if (lowpower_config_scenario(&LowPower_Scenario) != SCENARIO_OK)
{
Error_Handler();
}
四、实验效果
硬件连接:使用万用表,将表笔插在电流档,并调至电流测试档口,表笔另一头接入JP4两端。
通过串口发送命令,测试不同低功耗模式下电流值。
sleep模式电流:126.3uA
stop1模式电流:57.9uA
stop2模式电流:4uA
stop3模式电流:1.6uA
standby模式电流:0.8uA
shutdown模式电流:0.7uA
视频如下:
真的是超低功耗,在手持设备上可以作为首选。
|