说实话,我不喜欢hall库,也许很多人用起来很顺手,但是我用起来不习惯,而且LL库效率明显高得多,也许是没有接触过上层代码的原因吧,那么我就来说一下LL库的环境搭建以及点灯。. l" A- T( o1 S! t, t
我们首先根据官方的LL库以及例程做更改,新建文件夹,拷贝文件,具体如下图。
, w+ c, x; g6 s& r6 X. m, C/ h
$ Q' n% E0 z; y6 V8 l7 c5 w 并将文件拷贝到个个文件夹内,方便将文件归类以及后期文件管理,具体的可以看附件里,附件内的源码。具体的可以查看keil工程下的文件,如下图 ; e) v* g6 R3 T# Y
' W5 {" q" b0 J/ f$ D% S
文件拷贝完成之后,然后添加文件路径和初始化定义,然后增加如下代码到Main.c文件。 + K( j8 f' O1 B) a4 N& I
/ y8 D2 P0 H* Y6 {- #include "stm32u5xx_ll_icache.h"" H7 b0 u# n0 _8 | n* n+ X$ I3 z
- #include "stm32u5xx_ll_pwr.h"
^9 U8 _$ Z4 R1 M; }6 b, m; Q - #include "stm32u5xx_ll_crs.h"& M! {, L. d; g4 x' Z1 o
- #include "stm32u5xx_ll_rcc.h"
8 a1 S6 |! h! C* V+ z' _+ Y3 Z - #include "stm32u5xx_ll_bus.h". [0 C/ G4 m+ \+ ~' j
- #include "stm32u5xx_ll_system.h"8 i, O7 O. E7 _
- #include "stm32u5xx_ll_exti.h"
( F4 B' j+ m% _* C8 W3 |* a - #include "stm32u5xx_ll_cortex.h"
3 I) I3 |/ f5 ]: { - #include "stm32u5xx_ll_utils.h"
; X# o% `& {3 M4 m - #include "stm32u5xx_ll_dma.h") P9 W e' P3 m) R: W. P& c4 U
- #include "stm32u5xx_ll_gpio.h"
% W. j! T" I; _4 {/ n+ Q - #include "stm32u5xx_ll_lpgpio.h"
3 v3 n( I% v3 a: y; w6 D
& F) F) A* m# J+ b0 Q O8 H
0 O4 w+ M# l6 Y4 b8 K. t' V- + E. {/ E2 z( n+ L- C) r6 l
- . N9 u6 G7 ^7 _! e0 H
- #define LED1_Pin LL_GPIO_PIN_70 M' S0 P( {. x) K
- #define LED1_GPIO_Port GPIOC
( }$ N* V. C9 a, [; g - $ x* n0 o o* _) g0 q* y
- 9 I" P( _- t6 f3 N9 p, O& s5 L( l1 ]
- / @7 q- V& V% ]5 T$ e: r; I& G
- /**
4 G% I. X" t; y" r - * @brief Power Configuration
* D9 R3 i' O+ W6 ?! g$ H% x8 H2 X, i - * @retval None
- B' t9 _1 k4 q, U5 s - */
+ o& E1 @2 y. C5 K v {6 | - static void SystemPower_Config(void)0 z; q/ `) l) |1 C+ z7 R4 o. y
- {) g: X+ R) h$ n9 V0 L1 O* E
& i! P' J& j$ X8 D$ b- /*
0 I0 H' Q/ T* X0 m - * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
2 Y' t* n' g, N1 N" ]3 J - *// V/ O1 R2 U: I0 E( _6 d& k/ j
- LL_PWR_DisableUCPDDeadBattery();
" M/ w8 R- U" \( j& S- Z
, Z- E6 K4 B8 a$ w: N6 A. n& |- /*
" n. f" |- R8 J1 J2 R) I( T - * Switch to SMPS regulator instead of LDO
7 m9 ?3 U+ y; y& g4 S; N - */
0 P; ~1 Z; ^4 J& S- ~" J - LL_PWR_SetRegulatorSupply(LL_PWR_SMPS_SUPPLY);
; v* R& |* h) [7 T c1 a, o - / ~4 l" c/ D# u
- while(LL_PWR_IsActiveFlag_REGULATOR()!=1)5 O( t* I6 c5 ]1 K) l3 M4 \
- {/ `8 {$ W- Z8 ?: Z7 e( m( ^
- }9 q* `! k8 j% P& X" Y- a
- }
" o7 b9 O% k! I6 t0 C% ]( i
: e% E7 p+ d( C W' F- /**
9 G) v" {# m; o& |1 `# o1 b" R% a - * @brief ICACHE Initialization Function
; z2 M& K4 Y! P& ] |. ?5 G - * @param None
( D. k5 G& i5 {# o* r - * @retval None
* i" d% n4 v% V4 E1 ` - */; H4 ^+ ?+ N/ ^( G
- static void MX_ICACHE_Init(void): D8 I4 e& Y( t" k; r1 B
- {
' T: _+ P/ P6 G9 p, F5 v7 f - 5 U4 `4 n% ^' |) f8 V. w0 o( K) V% G
- /** Enable instruction cache in 1-way (direct mapped cache)3 d3 |/ {4 d' X; `6 E
- */
' |4 v7 N$ l' k6 p4 ?+ ` - LL_ICACHE_SetMode(LL_ICACHE_1WAY);
3 U1 j( a) [0 M% w6 b i - LL_ICACHE_Enable();
9 o1 O* P1 u. `. ?3 g9 s - /* USER CODE BEGIN ICACHE_Init 2 */
7 u; S& B ?+ b0 S - / {# m+ \/ Q: {. } s, {5 r
- /* USER CODE END ICACHE_Init 2 */- F* O& ]' j! G0 V1 q& ]1 e5 a
R+ ]5 t% l) D% A" c9 g- }
% E: v, M0 B$ U" X1 ~& P' F W6 v5 l - # y. T, V% P: n! m: E
- 3 t. {4 g6 [( r0 I$ `% i5 y
- void SystemClock_Config(void): x. F0 B" x" M' ?# d
- {
7 x" W5 d' T& ^ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);
& l# r9 F2 O' o( A* {5 ^% y - while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)* V+ ^% a" n n4 S3 N, J$ g& c
- { K0 \# _2 X, R4 {' O: p
- }
" R% F5 r# ~7 Q) r
* x9 L4 k4 E1 c9 P. n: y% d- LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);. t* r, m* y7 X) O/ v! d& z1 D
- LL_RCC_MSIS_Enable();
. Q) W5 l" R/ q' z" C
& k! |/ Y U0 P) l1 M- /* Wait till MSIS is ready */8 Q6 F) d' j$ x7 h4 m9 u1 G- |
- while(LL_RCC_MSIS_IsReady() != 1)( J3 N! v* o( j s$ f- u1 q
- {
+ b" S Q* G! d1 i; x5 M - }
0 G/ M2 @* K, ^- |/ ]
* q5 U: x( @* |0 a' U& P- LL_RCC_MSI_EnableRangeSelection();
$ A+ ~; R$ b1 F( [ - LL_RCC_MSIS_SetRange(LL_RCC_MSISRANGE_4);
' z/ I, z7 {, x' t. d! o8 X - LL_RCC_MSI_SetCalibTrimming(16, LL_RCC_MSI_OSCILLATOR_1);( Q7 C4 x5 W8 M2 n+ d0 q/ \7 K4 d! T
- LL_RCC_PLL1_ConfigDomain_SYS(LL_RCC_PLL1SOURCE_MSIS, 1, 80, 2);
# q# M! K/ X4 g5 i8 j9 K9 k - LL_RCC_PLL1_EnableDomain_SYS();
" s$ _4 a1 y) A, r, g' f - LL_RCC_SetPll1EPodPrescaler(LL_RCC_PLL1MBOOST_DIV_1);
8 d U: f% F& T - LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_4_8);) M; y6 W" ^: d9 D6 }5 n
- LL_RCC_PLL1_Enable();
/ f2 P+ Y- a8 y1 o5 `
* A( O4 C, T' H6 d6 c/ p- /* Wait till PLL is ready */
9 ^3 q0 E5 s) ~% s2 q: k; m - while(LL_RCC_PLL1_IsReady() != 1)
+ l9 E$ M/ b* e5 T& [ - {
# [) p3 S2 R* j9 n. A: _) ^ - }- Z/ O7 ?/ G. Y! h
- 6 Z3 s2 f2 f, @3 I) w4 `
- /* Intermediate AHB prescaler 2 when target frequency clock is higher than 80 MHz */$ I0 H0 ^1 O2 U
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);
, q& `; ~5 o4 r9 g: o - $ h: ^ y& }! ]& L$ F
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);5 b3 ]0 [3 |5 F w. H \
$ p/ _& Q$ w. A: f: M8 i/ \5 E" T- /* Wait till System clock is ready */
! a' E4 l& _1 B' u3 i% ]& J: g - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1)
* ]3 E8 R4 o0 X% \, S - {& K- J2 \1 H6 X6 J7 j8 A
- }2 p% f+ G, F6 W2 F- |
- 9 A8 B# r o3 O
- /* Insure 1µs transition state at intermediate medium speed clock based on DWT*/
* H. u1 U% o' g n. s - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;: S& w ~- {$ D3 b8 E
o) k% F1 x9 S k- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
; ?& F# Q4 C f/ w4 g8 m - DWT->CYCCNT = 0;
' C {9 s7 h- V { - while(DWT->CYCCNT < 100);- R# K P* Q9 E: h" _5 V
- : S0 C2 k9 t/ P. f8 w) o
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);( ]# b# f S& l* ?& k( v" _# w7 a
- LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
_( h& h/ d F+ g# O% h+ b! Y - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
( c' g3 M: V6 i( [+ [% m - LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_1);
0 j7 L3 J) d- Q' n/ P+ L5 ?
; ]: M* R) |7 w. a- LL_Init1msTick(160000000);. W x+ k# H- P; H6 Z! z
z3 J3 F# W8 V- LL_SetSystemCoreClock(160000000);
1 S ~, d4 Z1 y3 X8 y0 O+ v4 k - }
5 B% x/ ]6 d* i" o3 S
& w. Z" t; M, B1 ]& A- /**
4 h8 x9 J6 m+ J8 l, C% C - * @brief GPIO Initialization Function u4 g( Y. b! u, k% n* U
- * @param None
' {6 i( }+ w0 G" Z - * @retval None. B* F% x$ \+ D( A7 U
- */
0 y* Q* K8 g; ]8 E& a - static void MX_GPIO_Init(void)
+ e- J4 U* D. p$ a. x- i, o - {9 \+ G |+ ? K2 `1 z
- LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
8 Y: `9 v7 m: g4 @, e+ y. b - 3 e6 N6 g: K6 G$ Z0 ?4 M9 }
- /* GPIO Ports Clock Enable */
0 ?; e/ ]4 V3 T" A5 g1 [5 I# c4 v - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
9 M. |5 T! P1 h8 a: g
/ b% _/ q& O$ k- /**/% m9 k9 i/ z, B$ _) W' |4 z
- LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);
- P8 _( g: L8 {9 d5 I - 6 m! X& C' \- f, O5 B
- /**/
# c" p0 w- |! y+ |/ ?2 ^ - GPIO_InitStruct.Pin = LED1_Pin;
: c! s( g. N, o: G" g( {" C# f - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;, _$ [; v6 {4 y; E6 k7 {
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
1 J7 P. n/ |/ A7 u, N( y# v - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
! g, @" T9 K8 `/ o& z - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
$ D% J' }/ V% ` - LL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
4 k4 g2 H- b$ H" K/ x( H5 H4 N - 0 M4 a! S' T1 V R/ ?: g9 d7 l
- }/ B& f+ ^7 D. v0 M/ F$ a: O
- 2 p2 @. Y4 I) t# {* w" Y# f
- 7 a5 D- @: D/ Z& k2 ?
! n- ~' n8 T$ [- int main(void) t6 C: T, y# X, i5 ~9 j
- {
, o; U; V! k8 g - LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
& h) H& |+ N3 B, H - SystemClock_Config();
5 Y8 M% P0 G) M - SystemPower_Config();8 i5 _. U! }" H5 c' j
- MX_GPIO_Init();1 ^; ?; N! ^6 r% e3 ?6 m
- MX_ICACHE_Init();
; G K5 @& s' E7 x - while (1)1 D4 o9 Z# z( Q' p: F
- {
/ w* H* v. P, N$ E# t& s - LL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
0 c# @: z& A: E! q0 x - LL_mDelay(500);
/ ?% G. q+ C0 o4 v3 r: H! { - }+ v3 ]/ }3 x) P1 b6 ?, S
- /* USER CODE END 3 */- [$ Y( a! y; G& m& B4 \
- }
h5 b9 j6 o \2 `2 z: \0 H
( L2 E8 `- Y/ T: T( \, x- * X$ I1 A- A' z! p7 a {: J
: a2 b6 T. Y, B* c$ R: G- #ifdef USE_FULL_ASSERT5 m1 ^) {$ u& C/ P& U
- /**; f5 ]6 Y6 j: j; y
- * @brief Reports the name of the source file and the source line number
6 R# y" x+ Y3 M# G2 y! f - * where the assert_param error has occurred.
! H! c1 V w1 j - * @param file: pointer to the source file name
( V Y! [1 A+ Q" Z - * @param line: assert_param error line source number- p \" o6 w. _; @: ~' i: p0 W
- * @retval None L. l: H) l, E9 d6 w8 W5 C6 Y
- */
2 w4 W/ Q5 a/ a; g - void assert_failed(uint8_t *file, uint32_t line)
; O% M1 N" g! s$ o - {
4 J2 `; `; e* k# [1 r - /* USER CODE BEGIN 6 */
! c, { D, {( V7 {0 {+ y" C
2 z* K7 r' S9 ]6 V5 p5 d/ y- /* User can add his own implementation to report the file name and line number,) R6 [& S0 c6 l; H
- ex: printf("Wrong parameters value: file %s on line %d", file, line) */; c$ f6 W+ V Z! Q( Z! d
- ! K2 e% q. O" i" L
- /* Infinite loop */
6 c$ P4 d$ a% R G! X) d - while (1)
1 A# n- C# s; J- K, u' n - {) b d9 T! N) o1 l. s
- }
0 M' D8 t, ]+ K& _ - /* USER CODE END 6 */5 n# x5 C0 W6 D# X% p
- }
& Y8 A6 D ?8 p( L: F/ V/ T - #endif /* USE_FULL_ASSERT */
7 d2 |7 Z: u* K: ~
复制代码在完成之后,编译,就可成功下载点灯,具体可查看附件。 8 r: t4 g8 A0 l) b3 c4 G
' @" R( g, `1 T5 V0 C7 x7 w好了,先分享到这,过年后来了的第一篇。 ; f8 x" B6 X8 Q8 V9 n! V. d3 N
: I( W; {3 ~: _! W1 F9 p9 Q
c( z$ T; u9 F9 M4 \4 l |
期待下一篇