有网友在问为什么PG2点不亮,这是介绍下,因为PG2使用VDDIO2需要单独配置其VDDIO2电源.
需要先使能VDDIO2,注意在PWR配置前需要先使能PWR时钟。
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
HAL_PWREx_EnableVddIO2();
HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY);
先要PWR的SVMCR,bit29置位使能VDDIO2
然后PWR的CR3的bit1,选择VDDIO2的来源
PWR的SVMSR的bit1回读确认是否选择成功。
原理图中VDDIO2来源于SB28->VDD_MCU->JP5->VDD,确认该链路OK。
其他的就和其他端口一样了,注意使能对应端口的时钟。
#include "stm32u575xx.h"
#include "stm32u5xx_ll_gpio.h"
#include "stm32u5xx_ll_bus.h"
void SysTick_Handler(void)
{
static volatile uint32_t num = 0;
if(num++ >= 1000)
{
LL_GPIO_TogglePin(GPIOB, 1u<<7);
LL_GPIO_TogglePin(GPIOG, 1u<<2);
LL_GPIO_TogglePin(GPIOC, 1u<<7);
num=0;
}
HAL_IncTick();
}
void delay(uint32_t t)
{
volatile uint32_t timeout = t;
while(t--);
}
int main(void)
{
HAL_Init();
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
HAL_PWREx_EnableVddIO2();
HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY);
#if 1
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitTypeDef pRCC_OscInitStruct;
pRCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
pRCC_OscInitStruct.HSIState = RCC_HSI_ON;
pRCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
pRCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
pRCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
pRCC_OscInitStruct.PLL.PLLM = 1;
pRCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
pRCC_OscInitStruct.PLL.PLLN = 20;
pRCC_OscInitStruct.PLL.PLLP = 1;
pRCC_OscInitStruct.PLL.PLLQ = 1;
pRCC_OscInitStruct.PLL.PLLR = 2;
pRCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_0;
pRCC_OscInitStruct.PLL.PLLFRACN = 0; /* */
HAL_RCC_OscConfig(&pRCC_OscInitStruct);
RCC_ClkInitTypeDef pRCC_ClkInitStruct;
pRCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
pRCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
pRCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
pRCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
pRCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
pRCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&pRCC_ClkInitStruct, FLASH_LATENCY_4);
#endif
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
LL_GPIO_InitTypeDef GPIO_InitStruct;
//LL_GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOG, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
while(1)
{
///delay(1000000ul);
///LL_GPIO_TogglePin(GPIOB, 1u<<7);
}
}
本帖最后由 qinyunti 于 2022-12-15 13:47 编辑