说实话,我不喜欢hall库,也许很多人用起来很顺手,但是我用起来不习惯,而且LL库效率明显高得多,也许是没有接触过上层代码的原因吧,那么我就来说一下LL库的环境搭建以及点灯。
我们首先根据官方的LL库以及例程做更改,新建文件夹,拷贝文件,具体如下图。
并将文件拷贝到个个文件夹内,方便将文件归类以及后期文件管理,具体的可以看附件里,附件内的源码。具体的可以查看keil工程下的文件,如下图
文件拷贝完成之后,然后添加文件路径和初始化定义,然后增加如下代码到Main.c文件。
- #include "stm32u5xx_ll_icache.h"
- #include "stm32u5xx_ll_pwr.h"
- #include "stm32u5xx_ll_crs.h"
- #include "stm32u5xx_ll_rcc.h"
- #include "stm32u5xx_ll_bus.h"
- #include "stm32u5xx_ll_system.h"
- #include "stm32u5xx_ll_exti.h"
- #include "stm32u5xx_ll_cortex.h"
- #include "stm32u5xx_ll_utils.h"
- #include "stm32u5xx_ll_dma.h"
- #include "stm32u5xx_ll_gpio.h"
- #include "stm32u5xx_ll_lpgpio.h"
- #define LED1_Pin LL_GPIO_PIN_7
- #define LED1_GPIO_Port GPIOC
- /**
- * @brief Power Configuration
- * @retval None
- */
- static void SystemPower_Config(void)
- {
- /*
- * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
- */
- LL_PWR_DisableUCPDDeadBattery();
- /*
- * Switch to SMPS regulator instead of LDO
- */
- LL_PWR_SetRegulatorSupply(LL_PWR_SMPS_SUPPLY);
- while(LL_PWR_IsActiveFlag_REGULATOR()!=1)
- {
- }
- }
- /**
- * @brief ICACHE Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ICACHE_Init(void)
- {
- /** Enable instruction cache in 1-way (direct mapped cache)
- */
- LL_ICACHE_SetMode(LL_ICACHE_1WAY);
- LL_ICACHE_Enable();
- /* USER CODE BEGIN ICACHE_Init 2 */
- /* USER CODE END ICACHE_Init 2 */
- }
- void SystemClock_Config(void)
- {
- LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);
- while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)
- {
- }
- LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
- LL_RCC_MSIS_Enable();
- /* Wait till MSIS is ready */
- while(LL_RCC_MSIS_IsReady() != 1)
- {
- }
- LL_RCC_MSI_EnableRangeSelection();
- LL_RCC_MSIS_SetRange(LL_RCC_MSISRANGE_4);
- LL_RCC_MSI_SetCalibTrimming(16, LL_RCC_MSI_OSCILLATOR_1);
- LL_RCC_PLL1_ConfigDomain_SYS(LL_RCC_PLL1SOURCE_MSIS, 1, 80, 2);
- LL_RCC_PLL1_EnableDomain_SYS();
- LL_RCC_SetPll1EPodPrescaler(LL_RCC_PLL1MBOOST_DIV_1);
- LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_4_8);
- LL_RCC_PLL1_Enable();
- /* Wait till PLL is ready */
- while(LL_RCC_PLL1_IsReady() != 1)
- {
- }
- /* Intermediate AHB prescaler 2 when target frequency clock is higher than 80 MHz */
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);
- /* Wait till System clock is ready */
- while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1)
- {
- }
- /* Insure 1µs transition state at intermediate medium speed clock based on DWT*/
- CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
- DWT->CYCCNT = 0;
- while(DWT->CYCCNT < 100);
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
- LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
- LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
- LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_1);
- LL_Init1msTick(160000000);
- LL_SetSystemCoreClock(160000000);
- }
- /**
- * @brief GPIO Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GPIO_Init(void)
- {
- LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
- /* GPIO Ports Clock Enable */
- LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
- /**/
- LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);
- /**/
- GPIO_InitStruct.Pin = LED1_Pin;
- GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
- LL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
- }
- int main(void)
- {
- LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
- SystemClock_Config();
- SystemPower_Config();
- MX_GPIO_Init();
- MX_ICACHE_Init();
- while (1)
- {
- LL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
- LL_mDelay(500);
- }
- /* USER CODE END 3 */
- }
- #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", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- /* USER CODE END 6 */
- }
- #endif /* USE_FULL_ASSERT */
复制代码在完成之后,编译,就可成功下载点灯,具体可查看附件。
好了,先分享到这,过年后来了的第一篇。
|
期待下一篇