最近使用STM32G030来做项目,使用的过程发现有太多的坑了,折腾自己快要崩溃,主要问题还是初始化的过程中初始化失败,导致程序不运行。' m. m: t7 O7 L3 L9 v( s" I
' b1 _8 R/ }1 n: G! ?& O: v. J5 F& |
现在总结下遇到的问题:+ {7 S' i' g- z; |
1.ADC使用多通道扫描模式用DMA传输数据,HAL_ADC_Start(&hadc1);这个开始必须要放在DMA初始化相关函数的后面。3 K' c0 q! R" m( n5 w
2.开启串口中断后导致程序异常不运行,最后把开启传偶中断函数放在main函数的最前面就可以正常运行% B8 W9 M2 F7 t% A* U; q
3.程序是按顺序上之下运行,初始化时候要考虑好顺序关系。
2 r$ B& L: f' D
B' ?. ?0 O* r; T' h/ B7 h比如按下面的顺序进行初始化才可以正常的运行& e6 ^# ?/ Q0 R. d; m- E
- /* USER CODE BEGIN 1 /+ L Z$ y1 E* e) G3 v' P
- / STM32G0xx HAL library initialization:3 t# i! W4 a! h& u4 e- z+ @: H
- - Configure the Flash prefetch
% A# ]( a _5 e4 M( e! k' a0 d( h - - Systick timer is configured by default as source of time base, but user
7 Q0 {; T# l* R/ s1 J - can eventually implement his proper time base source (a general purpose
; \+ n+ |$ n j - timer for example or other time source), keeping in mind that Time base. V) v1 w% E) e
- duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
, [* n) W, u& m" ?6 y - handled in milliseconds basis.6 l. r) [8 P; [+ |
- - Low Level Initialization
+ N# {$ C7 Q- W6 A5 V4 s - */
8 D/ @' V2 Z( t$ L* {! b4 X - , t8 `2 i. a$ k6 t* U
- /* USER CODE END 1 */
2 w4 z% o" G$ X `/ @/ |# x
( }" E. v7 U7 H* U& a' T/ u- /* MCU Configuration--------------------------------------------------------*/
# o) Q$ O( r6 I6 W; x7 H7 o
# O* x8 n: l1 r( f8 ]- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
: m+ b6 B6 q( } T! i; S - HAL_Init();6 e' v- O+ R, o4 F% ^3 W( P
- Enable_IT_Uart_Fun();
4 z+ \0 y7 W! `7 Z$ K! P2 ?9 h - 5 {) B3 f6 }4 S! v& q# G
- /* USER CODE BEGIN Init /
3 X8 J2 d" x; c% O; m8 D) E - / Configure the system clock to 56 MHz /
. j: F) _% ^" b. K - / USER CODE END Init */5 {7 L. a2 ^9 \
/ z) Y6 b/ W; o1 M- /* Configure the system clock */
l7 p# n, v2 w5 F7 d# S - SystemClock_Config();) Q4 q6 d0 R$ b: P' W3 y, i& F3 y
! L: }# u( s. p, a$ v- /* USER CODE BEGIN SysInit */
( l, T: I# s+ y8 S( `2 i! P - 6 B4 ~5 x9 X" r- R: O% }) }6 ^
- /* USER CODE END SysInit */
/ s/ }3 N- @2 K# A- m - - @# L- s1 T2 ]# ~; Y0 Q" H
- /* Initialize all configured peripherals /2 ]: O2 K. \( N+ y7 v# O- L) o
- MX_GPIO_Init();4 {# ^2 ]! h$ Y6 Q
- MX_DMA_Init();
8 ^! e0 X0 D) o8 R - MX_ADC1_Init();- I' h2 i! y: e( }1 y$ I
- MX_USART2_UART_Init();3 @$ T/ L v0 k0 l1 U* E
- MX_IWDG_Init();
+ [# \) n" M3 Y i2 O% Y - MX_USART1_UART_Init();, T2 H5 a# e: g: w3 D* s& Z
- / USER CODE BEGIN 2 */4 c+ j$ I# n! C2 P' r* n! K0 i7 l
- LED_Config();& U/ v; o+ `9 f0 |. ^
- Lcd_Init();* T- n5 ]/ I/ ?( b
- Clear_Screen();
6 `. ?" B; `) U4 m* {$ D! y - Show_Picture();/开机显示logo/
/ b1 p* B% y' Z9 y - Wireless_Mode_Config();6 W6 ?# {7 X3 K1 A- v8 S
0 S+ Y# U2 Q; Z0 e2 M' [5 L- Flash_Init();
) f+ w; o, j2 n/ K- b6 } - if (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK). l+ g6 N$ R3 Z0 v0 `
- {3 s( W$ r- k3 U% b$ H& Z( y
- /* Calibration Error */
2 _$ y. b! \& H2 ` - while(1);2 s: Y& a( `9 C
- }8 d- w& B0 d0 Z
- if (HAL_ADC_Start_DMA(&hadc1,(uint32_t )ADC_ConvertedValue,7) != HAL_OK), F+ u6 q# d7 e: w4 G1 r$ d
- {5 X) y0 o0 l8 `( D9 J/ L
- / ADC conversion start error */' @. e( ~2 Z- w% H
- while(1);2 V9 I4 N& C& ?) ] y9 J
- }
. B! E% R; @* J: ^# h( e7 N, ? - HAL_ADC_Start(&hadc1);$ e9 i: R6 J3 n( p
- . f- N& N7 r( {) ^9 e8 r+ x6 S
复制代码 5 F& V5 Z$ `4 @' ^/ G& K
2 y# C# T+ F ]3 u$ E
|