【STM32U5A5ZJ开发板】EXIT中断测试及低功耗测试
[复制链接]
STM32U5A5ZJ的MCU可以使用1.8V电压进行直接供电,而不经过芯片内部的LDO调压器,这可以大幅度的降低芯片的功耗,而且芯片还具有睡眠等状态的管理,比较遗憾的是如果降到1.5V以下就更好了,直接使用电池供电。因为开发板上设置有可供电压转换的跳线,JP4跳线1-2接为3.3V供电,2-3接为1.8V供电,本次测试在1.8V电压供电下进行。
将 LED1 设置为切换指示 ,显示MCU 是处于睡眠模式还是运行模式。运行闪烁,睡眠熄灭。通过按键BUTTON唤醒。
一、系统设置
PC.13 连接到用户按钮,设置为EXTI中断,并配置为在按下按键时,在下降沿产生中断。PC7连接为LED1。用来指示系统运行状态。系统时钟设置为160MHZ,SysTick 设置为每 1 毫秒生成一个中断。
参考PWR_SLEEP例程,设置。
1、打开STM32CubeMX,选择RCC设置,
将RCC的时钟,高速和低速都设置为内部振荡器,不知道为什么外部时钟不可以工作,试过几次都不成功。
2、设置GPIO引脚
这一步使用默认设置,因为使用了例程中的初始化代码。BUTTON为EXIT中断,PC7为GPIO输出。
3、设置电源管理为SMPS。
直接供电和LDO供电自动切换,这里使用1.8V供电。
4、生成程序
除了程序名称外,注意把生成到root选上,项目使用vscode为开发环境,所以选择STM32CubeIDE类型。
二、测试程序
1、转换为CMAKE项目,VSCODE 打开项目。
转换完后打开文件夹, 程序代码参考例程如下:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* [url=home.php?mod=space&uid=1307177]@File[/url] PWR/PWR_SLEEP/Src/main.c
* [url=home.php?mod=space&uid=1315547]@author[/url] MCD Application Team
* [url=home.php?mod=space&uid=159083]@brief[/url] This sample code shows how to use STM32U5xx PWR HAL API to enter
* and exit the Sleep mode.
******************************************************************************
* [url=home.php?mod=space&uid=1020061]@attention[/url] *
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define LED_TOGGLE_DELAY 100
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
static uint32_t TimingDelay;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void SystemPower_Config(void);
static void MX_ICACHE_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the System Power */
SystemPower_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_ICACHE_Init();
/* USER CODE BEGIN 2 */
/* Enable PWR clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* Configure LED1 */
BSP_LED_Init(LED1);
/* User push-button (line 13) will be used to wakeup the system from SLEEP mode */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* Insert 5 seconds delay */
HAL_Delay(5000);
BSP_LED_Off(LED1);
/*Suspend Tick increment to prevent wakeup by Systick interrupt.
Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
HAL_SuspendTick();
/* Enter Sleep Mode , wake up is done once User push-button is pressed */
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
/* Resume Tick interrupt if disabled prior to SLEEP mode entry */
HAL_ResumeTick();
/* Re-configure LED1 */
BSP_LED_Init(LED1);
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 80;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_0;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_PCLK3;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief Power Configuration
* @retval None
*/
static void SystemPower_Config(void)
{
/*
* Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
*/
HAL_PWREx_DisableUCPDDeadBattery();
/*
* Switch to SMPS regulator instead of LDO
*/
if (HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN PWR */
/* USER CODE END PWR */
}
/**
* @brief ICACHE Initialization Function
* @param None
* @retval None
*/
static void MX_ICACHE_Init(void)
{
/* USER CODE BEGIN ICACHE_Init 0 */
/* USER CODE END ICACHE_Init 0 */
/* USER CODE BEGIN ICACHE_Init 1 */
/* USER CODE END ICACHE_Init 1 */
/** Enable instruction cache in 1-way (direct mapped cache)
*/
if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK)
{
Error_Handler();
}
if (HAL_ICACHE_Enable() != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ICACHE_Init 2 */
/* USER CODE END ICACHE_Init 2 */
}
/* USER CODE BEGIN 4 */
/**
* @brief SYSTICK callback
* @param None
* @retval None
*/
void HAL_SYSTICK_Callback(void)
{
if (TimingDelay != 0)
{
TimingDelay--;
}
else
{
/* Toggle LED1 */
BSP_LED_Toggle(LED1);
TimingDelay = LED_TOGGLE_DELAY;
}
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Turn on the LED1 */
BSP_LED_On(LED1);
/* Infinite loop */
while (1)
{
}
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
三、运行
1、将JP4跳线到1.8V电压。
板子上带了一片LDO芯片,电压降到1.8V。测量了一下差不多。
2、下载程序
因为程序不能在调试模式下运行,所以必须完成编译后使用STM32CubeProgrammer烧录,
程序烧写完成后,RESET一下,启动 板子LED1灯闪烁5秒,
5秒过后,板子LED1熄灭,按BUTTON后,开始闪烁5秒。
过程可以重复。
四、抗干扰测试。
工具还是电子打火机。在睡眠状态,反复的打火,发现并不能使得板子启动。这虽然说明不了什么,但是可以肯定睡眠状态比较稳定。当然这一方法需要改进。等有更好的方案了在进行测试。
|