说实话,我不喜欢hall库,也许很多人用起来很顺手,但是我用起来不习惯,而且LL库效率明显高得多,也许是没有接触过上层代码的原因吧,那么我就来说一下LL库的环境搭建以及点灯。4 h G. e+ ^ p4 {+ K
我们首先根据官方的LL库以及例程做更改,新建文件夹,拷贝文件,具体如下图。0 f3 n& C) ~* ~2 w5 C
t4 l$ q. k7 z 并将文件拷贝到个个文件夹内,方便将文件归类以及后期文件管理,具体的可以看附件里,附件内的源码。具体的可以查看keil工程下的文件,如下图
6 k; w' d. S% A0 e
* H7 _2 |# C1 q$ M0 P; n# o文件拷贝完成之后,然后添加文件路径和初始化定义,然后增加如下代码到Main.c文件。 ' _/ w) J f. Q5 U2 q. l) |
6 W7 R0 P u$ p4 T- #include "stm32u5xx_ll_icache.h"
' q( T1 y( W* _) S - #include "stm32u5xx_ll_pwr.h"" S- D7 F' V( T3 E5 d
- #include "stm32u5xx_ll_crs.h"! V$ S- w0 \5 @ r! {
- #include "stm32u5xx_ll_rcc.h"* y' F+ H) R2 B9 Z% ]5 G
- #include "stm32u5xx_ll_bus.h"/ K: h# r( O+ M; ]: h
- #include "stm32u5xx_ll_system.h"
5 T. R! J7 i: L0 |6 i* S3 q8 D, G - #include "stm32u5xx_ll_exti.h"
/ O6 o+ }9 A" z% m2 k - #include "stm32u5xx_ll_cortex.h"0 V! y+ L5 O3 V9 r
- #include "stm32u5xx_ll_utils.h"; E: W% K" r0 y- g9 S% ?4 w
- #include "stm32u5xx_ll_dma.h"
5 ?: S7 {5 Y. ?# w" ]) ?! h - #include "stm32u5xx_ll_gpio.h"; I: v$ e' D+ x! ~5 t
- #include "stm32u5xx_ll_lpgpio.h"
, {$ A( n9 R* ^* k/ V
; n* x$ f' R2 G( L1 w; B3 T+ ^- ' F2 |! C) W s, o, D' Y- s
9 {. s# g4 b0 |5 q
' F6 o; i2 x7 L( O$ m- #define LED1_Pin LL_GPIO_PIN_7! j& t6 \, i, f9 L3 p, ]+ L
- #define LED1_GPIO_Port GPIOC
3 v; N! Y4 ^, x# X3 L- @! R, h
6 s5 f% c7 d: F w3 m
$ P% e5 v1 x/ O' r2 Z
! u% E" A& ?3 I5 }3 ~/ V- /**
. U. V. {) x) z5 n - * @brief Power Configuration& Y( p1 {) P; Z/ v* w+ e }9 V# |% }
- * @retval None |% t5 F( I5 t5 P2 l+ ~, G, b( L
- */" i/ ~/ ^# F. q- H
- static void SystemPower_Config(void)/ [. y1 R1 o L! F
- {& U M4 _; a% C( J' S
' W- n, |0 \8 R7 ?! U6 a. I4 `8 q- /*8 z5 H; {% P; c& o* o
- * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
$ c4 k! k( V& H3 C; z3 }1 t; S7 |: ~ - */. t$ G1 d4 e$ U+ a
- LL_PWR_DisableUCPDDeadBattery();9 ^. I% c5 K ~# a
" v$ |1 P* J& S( N8 k/ q% }, y- /*
3 M$ ]& ~; L7 S, |! e `6 d7 p - * Switch to SMPS regulator instead of LDO
) b& e8 V9 n0 I `1 I4 N- W - */
( z) S, i: k$ l1 ]8 ?- d. L3 X1 r - LL_PWR_SetRegulatorSupply(LL_PWR_SMPS_SUPPLY);' @, X. S4 a* o5 A5 }/ R; x
C) W/ j+ z. E9 g' ?' Y8 H- while(LL_PWR_IsActiveFlag_REGULATOR()!=1)/ n, c+ R6 r: j" m
- {- d# u2 @# N# Y# H5 T1 X
- }$ v" _" n* _# `3 y0 }
- }2 b7 ]9 V8 w0 ]: M
- , z# T! L9 d) B3 L5 }! G5 _# C. F
- /**
( a' w, _' \. u2 {% D; \/ h - * @brief ICACHE Initialization Function
8 R' F3 t+ f1 b g' _ - * @param None2 f( M" j2 @1 V/ S6 u
- * @retval None
9 D* A- B7 @% r; l1 o# C - */
4 S0 C9 Z% w4 T - static void MX_ICACHE_Init(void)$ r, S* ?5 x U
- {
6 a2 I# O0 x x1 d0 g e
: i+ l4 l* F3 t* S/ i- X9 y- /** Enable instruction cache in 1-way (direct mapped cache)
5 G! j( z! \& I4 I W - */
+ [# {4 Y$ [ Y1 O4 ]- \. H) L. i! Y - LL_ICACHE_SetMode(LL_ICACHE_1WAY);
! |3 [% {" j) q9 [ - LL_ICACHE_Enable();) t4 _$ {' B" }
- /* USER CODE BEGIN ICACHE_Init 2 */
% Q; P" h. K t
9 U' d6 u. o O4 x* N# v" N- /* USER CODE END ICACHE_Init 2 */ x8 q) g' [/ v% S& N. Q
- 4 \$ P4 x$ u) L( J- P" m9 n/ |
- }# \7 a8 ~3 [/ x' A
- / Z) s) p% |5 d, R0 |0 Y; P
- ! S2 ^6 Z6 B) D( f7 m& O
- void SystemClock_Config(void)
; M& l! V2 l7 C' j* Y - {
# w& f) z$ U2 s" W/ y5 } - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);
5 {3 {8 N: M* E3 M+ i - while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)
; L7 Q- D3 a q6 K$ N+ {5 N4 T - {
9 {. H0 O/ ~! e9 q& i' A- l: U - }" z2 m# S- s; k' `5 I$ F
- . X9 r# c7 H% d: {0 E6 i) Y% B
- LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
: K2 j$ o2 n" G" A - LL_RCC_MSIS_Enable();) `2 h7 d3 R+ d% w
- , _( o' f: g0 _7 d4 K) O
- /* Wait till MSIS is ready */
# C4 f# Z& Q+ }) ^. G1 {' e4 ?# ` - while(LL_RCC_MSIS_IsReady() != 1)3 J S6 A3 ?" Q' u* h+ W
- {: f. L2 M: B3 _; x, c9 |
- }8 c3 g- j5 m4 t8 p
- " r4 W( K! `2 F. ^
- LL_RCC_MSI_EnableRangeSelection();1 s0 U2 o7 b. @5 v
- LL_RCC_MSIS_SetRange(LL_RCC_MSISRANGE_4);% z4 B4 C. X# w* Q/ s
- LL_RCC_MSI_SetCalibTrimming(16, LL_RCC_MSI_OSCILLATOR_1);- ]+ d! u+ I% h: C1 K1 Z% X6 U
- LL_RCC_PLL1_ConfigDomain_SYS(LL_RCC_PLL1SOURCE_MSIS, 1, 80, 2);
8 F; y; j, N/ }: d" O - LL_RCC_PLL1_EnableDomain_SYS();
7 P( v, D) ?- V% r! J y$ i - LL_RCC_SetPll1EPodPrescaler(LL_RCC_PLL1MBOOST_DIV_1);6 }. T( V) f3 E2 G7 b' P
- LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_4_8);' ^& E5 @$ I8 D2 q/ U+ i6 S& ~& l
- LL_RCC_PLL1_Enable();5 W' u! V6 z8 F# f; ?' `( L$ s
- 2 e1 e1 @; d: Z1 _
- /* Wait till PLL is ready */
0 o) Q8 W; L1 ~. k& u; e - while(LL_RCC_PLL1_IsReady() != 1)
2 B$ W/ n) J2 Y( B% v" X( U( v) ? - {
) T; {. r( @6 @% j, }$ r8 y! ] - }
1 V' H) j! E( O9 m0 t4 o: \ - 6 P7 b0 ^2 U! m! h' n; P. o
- /* Intermediate AHB prescaler 2 when target frequency clock is higher than 80 MHz */! E) b& \0 N( j
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);4 R1 d# E& Z6 Z
- % u& D! _. O3 J8 ?6 o5 a3 O
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);
0 R& F3 Y1 o3 a) D7 y - & O& h5 Q7 |: }+ E' v
- /* Wait till System clock is ready */
2 e3 V+ i/ d8 N* ]) M+ f1 s - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1) t% F5 ]: C& {0 d
- {9 U+ }9 Q& H' d" k+ W
- }) T) l. F. S( T( K( z" {5 [
- 9 y6 f ]7 s. \/ C4 h
- /* Insure 1µs transition state at intermediate medium speed clock based on DWT*/
$ o7 i& ~3 R7 @9 O5 x, o - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;0 X+ j! ?2 i4 C: [4 G* h9 G
, G: p4 a9 [, U) u& t* @4 `1 z: R: {- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;: X0 C6 a& r* h* C! y
- DWT->CYCCNT = 0;8 p3 g% K8 J) G3 k y5 ~
- while(DWT->CYCCNT < 100);
. u+ a H- m( R2 M/ H
/ V& S4 d) P& U3 W. T7 H- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
- z2 w( ?, m! P" G - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);7 ?9 x$ k& F' e, `4 l4 C
- LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);6 H2 H4 W* Q4 f0 l" x6 R( q1 b
- LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_1);! o2 N7 O0 ~0 \
* f- c7 `+ S( X. c- LL_Init1msTick(160000000);& n" e& H& ~1 H
+ w' s1 U8 e& B# X: d9 ^- LL_SetSystemCoreClock(160000000); Y' `7 M0 }4 m" |$ K* j
- }
' t; @) a& j4 H; }* q
5 T _# ^6 r+ N6 w- /**
. R: }' z7 }7 j% Z - * @brief GPIO Initialization Function$ ~" I' @" Q: M
- * @param None$ B2 ]: o$ y T! Y) i1 I6 W$ Q* L
- * @retval None
Q$ J2 B. U: ` - */4 V/ _ m' y* u1 Z8 v
- static void MX_GPIO_Init(void)7 H0 Q7 Q5 e* m' H8 M) R4 B
- {! x u2 W+ g! I& D
- LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/ V* `! d0 \( k - * f; H, I2 B- O8 R4 ~( G# H
- /* GPIO Ports Clock Enable */- `$ V( {% r% Q# a9 \/ `$ k9 h
- LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
; o# x x# m5 m6 Z
0 q8 f4 W! V5 l. Z; v' q- /**/
' n( R# j7 O8 m) F* b - LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);, W0 J0 D% E- \5 C
7 y" I( @' P% E* k- /**/. X( }+ c# h8 W1 K* j& s8 v% a
- GPIO_InitStruct.Pin = LED1_Pin;/ L: X! ]4 p0 D, V; k2 M/ F# I
- GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;3 A: D; O, E, e& E$ ^
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
- f! n+ T6 c* t/ h2 p U - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
# ` k! P# T! q a) I - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
! i- K5 E! g. I2 R2 O, J6 g- e - LL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
, L7 E6 Z& K/ E, x* |
+ J" e) S Z2 H. ^# _6 P- }
( \9 E0 X9 s) l$ u - * i- B* }5 q5 f4 o! }) G+ X& M
4 o. f& v6 W' G# s+ C8 y' W$ [
$ ]5 f! M7 ]' f1 S% X- int main(void). I! I; W Y3 `+ @# o4 f: i( e
- {+ R3 }$ C% k @/ z4 Y' G7 r
- LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
# |1 J3 b, Y, Q! u - SystemClock_Config();
6 n1 g# \3 b2 p, i; r - SystemPower_Config();
: v6 M4 n* r% ^' W, m; Q - MX_GPIO_Init();+ b9 Y U2 ~$ l( m$ E
- MX_ICACHE_Init();
! f/ u9 {* F6 y1 K - while (1)
" W+ s: ?6 i) G! N+ u6 P, k - {
# S6 Y- l! M7 P" z3 ` - LL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);4 i0 z' s4 |7 x" ]; E3 k; A( E
- LL_mDelay(500);( L: }; c: v2 i# ~
- } ]0 e) M9 s7 a9 L# y
- /* USER CODE END 3 */5 P3 J6 a% W. z
- }
: x5 D. H4 H1 @- v5 X+ g9 C3 `
h! S2 i" y. x/ y- $ }8 I( X& d2 _" B
- 4 A7 S; H1 _5 W5 D7 [! Q& C. j
- #ifdef USE_FULL_ASSERT' S* B3 b* b% Y0 S
- /**2 v2 o- \7 a$ W0 Z# j, N2 p
- * @brief Reports the name of the source file and the source line number
, d! X: z! I: }9 F, s - * where the assert_param error has occurred. f& X7 e9 |; \7 [6 h
- * @param file: pointer to the source file name$ L% g1 C C7 T3 U( r* T
- * @param line: assert_param error line source number
; p1 r/ `/ _) }6 Q" c - * @retval None9 s0 e$ J, o. x/ w5 Z* f' ~4 C
- */( N; H/ A1 m% x5 |
- void assert_failed(uint8_t *file, uint32_t line)! N% Y7 V* g1 o' k& v% {
- {
) g+ C! a( |+ }: I# z/ e3 ^ - /* USER CODE BEGIN 6 */
2 L6 f. G! k$ u* [/ B
, |( i h) p$ y+ ]7 w- /* User can add his own implementation to report the file name and line number,
: p: T) A R; P. W5 s: v - ex: printf("Wrong parameters value: file %s on line %d", file, line) */' O% p+ |0 P+ c& G
3 r2 ~0 Z2 Y: Q% H; m- k P% c6 R- /* Infinite loop */
4 I$ b- X, | s4 s/ I2 ?3 N' h# B0 z - while (1)
* K6 T. i8 e( T- B8 t+ z - {' \- m1 e9 O; g' Z0 [8 ]5 C. Z
- }
0 W5 ]! v4 w" c+ ^: w2 e" o% \1 t - /* USER CODE END 6 */; b4 d- p( n! Q. E- K& ?( {
- }* v, M$ H, y6 A: {/ l6 B1 p
- #endif /* USE_FULL_ASSERT */
5 z$ i& S( A; }% P1 {% Y3 d3 ^# d+ ?
复制代码在完成之后,编译,就可成功下载点灯,具体可查看附件。 2 a1 d# l5 I9 c7 U/ G3 _
7 T( ^6 p' G# k+ O( L8 w3 J' [$ y
好了,先分享到这,过年后来了的第一篇。 0 D" Z/ X+ ]5 {6 Q. {6 d: a
2 _* _+ P: p) ~0 K/ v
* Y2 u7 [" r4 R: u* p |
期待下一篇