说实话,我不喜欢hall库,也许很多人用起来很顺手,但是我用起来不习惯,而且LL库效率明显高得多,也许是没有接触过上层代码的原因吧,那么我就来说一下LL库的环境搭建以及点灯。
9 I d4 L5 ~' P( |3 w 我们首先根据官方的LL库以及例程做更改,新建文件夹,拷贝文件,具体如下图。
5 K7 e0 C1 s5 A" }, Z+ Z2 X2 E; L" b% U
并将文件拷贝到个个文件夹内,方便将文件归类以及后期文件管理,具体的可以看附件里,附件内的源码。具体的可以查看keil工程下的文件,如下图 9 N2 p, B* U, s1 I0 p' S9 R3 j
7 F5 r7 m0 w( b) o2 o9 I
文件拷贝完成之后,然后添加文件路径和初始化定义,然后增加如下代码到Main.c文件。 1 x7 T" ~0 o) R% _! b b
- / n* F9 e ~3 e( Y. l
- #include "stm32u5xx_ll_icache.h"+ H! j0 I1 W7 g2 Q. P0 Y( e
- #include "stm32u5xx_ll_pwr.h"
, p, I9 f1 p P$ }3 O - #include "stm32u5xx_ll_crs.h"" @8 R: ?( W I1 l- F
- #include "stm32u5xx_ll_rcc.h"
- [$ o! x) ^6 I - #include "stm32u5xx_ll_bus.h"
9 f, B( d8 Y6 U# _! S) C8 H4 { - #include "stm32u5xx_ll_system.h"1 X0 z+ @4 t: n2 z9 I
- #include "stm32u5xx_ll_exti.h"
. d9 p0 H% A, h/ V% Z - #include "stm32u5xx_ll_cortex.h"- Z' y) ?. q5 K9 f
- #include "stm32u5xx_ll_utils.h"9 W7 Y1 E: j- Y/ |0 y
- #include "stm32u5xx_ll_dma.h"
' N. N5 ]3 E( }6 C - #include "stm32u5xx_ll_gpio.h"
1 ]) g8 p% D( k2 S8 h - #include "stm32u5xx_ll_lpgpio.h"5 M( l4 O& q6 o2 r7 A& Q1 X
- 5 c2 `2 I" ], E! U) {! N o
- ; C) P9 ?$ J$ Y/ j+ G
- 0 E" Q' Z5 E0 s2 o' y5 O
- - p0 Q) {7 `" s7 B0 _
- #define LED1_Pin LL_GPIO_PIN_79 C9 G) s$ L) G0 A% f
- #define LED1_GPIO_Port GPIOC- M4 q& m! v. y5 p0 S
( }3 R; v6 i& y- . H% K! T8 O$ P# ^* j' u7 C
- 6 X$ J% Y- r! \, u- C
- /**
0 W- j E2 ?2 {+ _( n - * @brief Power Configuration4 ~/ [3 b: s7 |+ Y' \& ?" A
- * @retval None
" X% c* L, Q0 O/ n: S9 X' Y$ @ - */
- J& s& |. s) F2 ~; A0 X/ c" P - static void SystemPower_Config(void)# [1 s9 x/ Z0 S+ |: A
- {
( N: P8 \8 S s% T# V. z - & T% O- f e q! @( P3 [; X9 b
- /*
$ P" q: f* [9 u- r - * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral- X+ S5 A5 G! L
- */- @3 {7 M4 M+ n+ U' o$ d7 T3 Z
- LL_PWR_DisableUCPDDeadBattery();
; D% ~) T& f+ h2 ^
0 Q5 X9 }2 S, p- /*
) F/ o2 w3 N0 Z. n8 u0 d. X! s - * Switch to SMPS regulator instead of LDO
( o4 G) i: D: K8 S: i/ B - */
) `; M/ U# J; y1 n4 z! Z& x/ |/ | - LL_PWR_SetRegulatorSupply(LL_PWR_SMPS_SUPPLY);
" F7 f8 N4 ~$ _0 B: ^* @
: s! B- L* T; Y) d- while(LL_PWR_IsActiveFlag_REGULATOR()!=1)( o/ h+ @* T U, C. B0 h
- {
5 a3 n4 S; t* k) L& S4 i; S - }. u3 g- k& {' x+ A: l. G
- }" i7 n5 ~% Q/ B) q9 m
' `( {/ g$ F) a/ N- /**
4 A' |! r2 P) q) ^ - * @brief ICACHE Initialization Function, P6 `9 q" r. V. {
- * @param None4 y: t( c- e1 J. T& k0 W" G
- * @retval None
" O( H2 L& Z2 q1 `6 \ - */
" H; c- \1 v9 Q: a4 P0 s" |( ^ - static void MX_ICACHE_Init(void)
6 f* H5 @$ Q" g x - {
5 s+ Q/ J S' h
6 `: @, H' G Z$ N: O5 b0 W- /** Enable instruction cache in 1-way (direct mapped cache)6 B- n1 f ^) c
- */) y4 P* Y2 D% B6 M. W$ ]+ \5 J
- LL_ICACHE_SetMode(LL_ICACHE_1WAY);3 |, m! x* {/ w. g$ S* g
- LL_ICACHE_Enable();
% p D' \- U2 d1 C$ E+ u( C3 X. G- D - /* USER CODE BEGIN ICACHE_Init 2 *// V: A* g2 t0 Q& I* y# V
- ) w9 @# t/ S( c9 B0 R6 R
- /* USER CODE END ICACHE_Init 2 */
( j9 e$ j2 M/ p
( ]9 {5 m! j% {8 z& m3 M- }
# M _ R1 f% T! l
( p2 Y5 Z4 E q3 U; [- ! y/ X0 h m* D8 U% u) m: R! D9 J
- void SystemClock_Config(void)
* R |" a* t1 X w0 O' l4 g - {8 M9 h& ?/ n2 B3 Z6 t
- LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);1 ^1 P* b% p9 {# d, Z" o5 Q' m
- while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)% Z. h& B( ]( Q8 R, e0 _2 e
- {6 j6 O _9 v0 H
- }6 U6 J& Q( H; {) j4 D9 Y
/ l% Q. N' U Q0 ]3 h5 W1 Q7 _. K- LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
( K9 s7 O' X2 y* Y- ?9 @$ I X - LL_RCC_MSIS_Enable();. L# t+ O' Y, ~: Z* c' ~5 U; O+ L
- # F4 z# S8 M2 i3 J* p0 k
- /* Wait till MSIS is ready */; S, m* s2 u2 G3 s+ }8 ?! n! J
- while(LL_RCC_MSIS_IsReady() != 1)7 n8 b ]. \0 K. f
- {
* _: `; a: V3 a3 H4 d - }
6 m' ?6 ]0 K. ~( ^
9 _6 V1 W. V5 J, }- LL_RCC_MSI_EnableRangeSelection();: O2 n3 r% h, ?1 G
- LL_RCC_MSIS_SetRange(LL_RCC_MSISRANGE_4);
( n0 Q% R! }7 a: V3 Q. T - LL_RCC_MSI_SetCalibTrimming(16, LL_RCC_MSI_OSCILLATOR_1);% m3 m/ g4 _; c" p" A" I
- LL_RCC_PLL1_ConfigDomain_SYS(LL_RCC_PLL1SOURCE_MSIS, 1, 80, 2);' w0 Z. G1 r4 P
- LL_RCC_PLL1_EnableDomain_SYS();
$ ]0 |. s; m: y! U( U$ e - LL_RCC_SetPll1EPodPrescaler(LL_RCC_PLL1MBOOST_DIV_1);
. p" q4 X+ t) B! m - LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_4_8);- U+ y3 u$ n, O% M7 z, G
- LL_RCC_PLL1_Enable();* M. z9 \1 B. b& ~ Q1 F5 z H! W9 W# T
- " X5 E0 R4 f* u& P& p, d) e
- /* Wait till PLL is ready */
: B P/ V1 _& H5 f7 X9 f - while(LL_RCC_PLL1_IsReady() != 1)
/ d" S! q7 ?( J' E; H, g - {$ ]- F& T- o- C& \
- }4 X# N" {8 F1 V+ R+ F
- ; O. D$ l, M: z9 n X' w% s
- /* Intermediate AHB prescaler 2 when target frequency clock is higher than 80 MHz */! @5 c2 A) T; B R1 x" d
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);* d- J5 l3 n/ s2 L7 `
- ! W; x4 P' I0 y5 K( _' P* W3 ]
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);6 } z6 r0 b( W: ]6 G1 ?' v
- 4 `9 a5 J. e3 ^8 u% P! ~% L
- /* Wait till System clock is ready */ J7 c# }" H# \- X/ ^! W
- while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1): L6 I3 J G9 E6 y* |7 r
- {
- y# q. F7 h+ h9 ]- A9 I4 ^ q+ J8 B - }2 C( a. Z3 y3 x- Y+ `% L
- * y8 p% [( U9 b4 u M0 u
- /* Insure 1µs transition state at intermediate medium speed clock based on DWT*/. K# X8 L3 A0 Y3 _' h
- CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;/ e9 g+ E% ^7 Z7 g0 H( T" I( g, c
- ( T2 ~# u! _: f3 h N8 t
- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
- t; A$ K2 |2 X8 | - DWT->CYCCNT = 0;
, A: g) R: O& e) M4 u( x0 E3 k - while(DWT->CYCCNT < 100);* M" K6 A) S" \3 v" E# m! C+ X1 p' x" D
. I y" v- n# o- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
, F$ e4 K; @& _4 W$ E7 R) y - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); F9 H- u5 V; T8 I) n% L% ~# R
- LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
; f4 A( s; }; M3 O) L! Q; S, m - LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_1);2 K' `8 l3 M/ G8 L8 c6 ^) A* ^
- . G/ e5 Z! t: _! N Z& Y) y- ?
- LL_Init1msTick(160000000);
7 Y1 m9 T# n; N0 i7 ]) \5 q) W' [ - ! ^4 U j0 C; P0 E( Q
- LL_SetSystemCoreClock(160000000);
6 r7 K% l* d4 Z9 K$ S/ p - }# ]4 k9 ~* K7 O
* T |/ G% f, S0 J7 {& q" Y" ]* ~' D& T- /**
( n" A6 X( v3 E) h: O, L) w - * @brief GPIO Initialization Function3 b. y* i" n- B/ b( G. v' J
- * @param None
% O8 n- G+ u$ i - * @retval None5 T( f* S( E/ k
- */
! d" m2 S- E! s9 k4 U" t - static void MX_GPIO_Init(void)( j. z2 i: M% f7 V6 t" h' V
- {0 R: P7 c, k4 H8 J
- LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/ @* Z' L! n' Z& g, S - 6 v# U8 [/ \- L
- /* GPIO Ports Clock Enable */1 c0 [) T; \8 b! L/ D8 ?" a
- LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
: L, c: J. @9 z. w
1 d4 S2 g$ f% V9 b- /**/2 t* f0 Y6 a( I4 q
- LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);
$ ^4 \( R8 O1 n+ d R# G0 z- O - ' C8 B* l5 ^' q3 l% n3 G" {* g
- /**/) h9 \8 f5 B; w; \6 F) ^) Q7 ?% x
- GPIO_InitStruct.Pin = LED1_Pin;- a6 r. s* W# S
- GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;) @7 P8 w" t& o2 o+ g) K
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
: t/ B* [9 W6 C. R - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;0 r* W& |# j. U' }$ H6 x" G
- GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;8 P! |- U& ~* q% O7 u: T
- LL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
3 T2 ]4 p+ y- F5 G: w% X - % G+ H/ R5 {; E) s2 t' R& A5 O+ i
- }
- k! v) G* o1 Y' s v' Q
* P/ \7 }9 z% M* r6 X7 e
$ {! l# k8 w& @; N/ \
' o8 h1 j% h7 ?# E- int main(void)
2 R; K7 w( Y1 j0 R - {, E& m& L; W% I4 c
- LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);* h% [" z1 l4 v! f, E- H" L
- SystemClock_Config();
! U$ R' V( T, W. J - SystemPower_Config();9 I/ X+ d0 j* C9 P7 H! d! L
- MX_GPIO_Init();, m: J8 |" L# K" S. W* [
- MX_ICACHE_Init();
) |: Z) y' P! ^: E0 B/ R; \8 N. m - while (1)
, x- x0 w/ \2 w3 @7 c* s% Q9 ~ - {4 v& M) l, `2 U) {0 V
- LL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);; m' d# v& n) L/ E
- LL_mDelay(500);, h. p- H& o8 M4 Q
- }9 x8 V: T8 J% R+ K- p
- /* USER CODE END 3 */% F) j% [3 k) z' W) D* l C
- }: s* Y# w! J8 u, J C; e/ L
: O5 N) M+ T( L* _
- I8 a; o2 m0 I5 @$ h9 a- X6 i5 |" V/ e7 T
- #ifdef USE_FULL_ASSERT
7 c0 s. }) ^9 y- S3 m* z - /**
4 j: [) j8 `; j5 Y6 I' ? - * @brief Reports the name of the source file and the source line number4 q' a9 m8 x- P- R5 e @8 Z
- * where the assert_param error has occurred., d: O J# g- ~% k% J
- * @param file: pointer to the source file name
" S2 W- i2 f9 N - * @param line: assert_param error line source number' q9 K) w. `2 Z7 }0 `& i, F
- * @retval None
+ d9 _ h, I7 Q4 ]" i* e - */5 O6 H6 L, Y; r" l
- void assert_failed(uint8_t *file, uint32_t line)
3 |/ D4 c# a: Q - {
6 R8 U7 r) b1 I6 g - /* USER CODE BEGIN 6 */
* P1 W- Z# l+ I2 L, H - W7 `9 u2 A5 T! A0 |! c5 r
- /* User can add his own implementation to report the file name and line number,( a! g2 z4 q5 q; k
- ex: printf("Wrong parameters value: file %s on line %d", file, line) */6 d% Q2 T; a- h& p
- " w) L* T; J( E
- /* Infinite loop */: p; O5 g5 h5 X2 W9 b% C
- while (1)' l: Q' @2 G2 j+ S( L
- {. p" c& O0 Z! s( g2 u8 q9 ~1 n
- }1 ?' Z) [ z$ ]
- /* USER CODE END 6 */
' s; G2 l' }0 S - }
6 k. {- Y8 @& Z- p) f9 W" H4 d! u" i - #endif /* USE_FULL_ASSERT */
% y- C% ^( w" m5 T
复制代码在完成之后,编译,就可成功下载点灯,具体可查看附件。
! x; w7 E' u0 j" y5 q, g- E
; {! q# h+ |( _, T* T- _9 ]好了,先分享到这,过年后来了的第一篇。 . J; W2 U3 K; O. a1 n
. q( S7 N& o/ G9 O; x6 ]
, J+ c7 Z* H' q K, U |
期待下一篇