最近使用STM32G030来做项目,使用的过程发现有太多的坑了,折腾自己快要崩溃,主要问题还是初始化的过程中初始化失败,导致程序不运行。2 Q H! z3 x4 E1 P, N; Z0 d5 n
( N( F* H# U9 G0 L3 u现在总结下遇到的问题:8 J; o, S1 L5 O- _* [1 _
1.ADC使用多通道扫描模式用DMA传输数据,HAL_ADC_Start(&hadc1);这个开始必须要放在DMA初始化相关函数的后面。
u7 _( ^. x! i; w1 N2.开启串口中断后导致程序异常不运行,最后把开启传偶中断函数放在main函数的最前面就可以正常运行
' `7 Q |2 |/ B$ M$ s& x3.程序是按顺序上之下运行,初始化时候要考虑好顺序关系。
6 s6 \* u! M' l1 ^3 K
4 j. r i" ]5 W; G* k比如按下面的顺序进行初始化才可以正常的运行$ W# i1 |- f' U8 v# k; r
- /* USER CODE BEGIN 1 /! K/ p: l; Y: m$ n" j4 P
- / STM32G0xx HAL library initialization:
: y0 M; S% T9 K - - Configure the Flash prefetch# O3 j0 V% [6 a. u. ^+ e1 o
- - Systick timer is configured by default as source of time base, but user
! |$ D4 V H% ?$ T - can eventually implement his proper time base source (a general purpose4 a; d% p! P" ]4 n- g. }& ]( s" n
- timer for example or other time source), keeping in mind that Time base% Y2 k) ~. M: o
- duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and+ n* {$ {/ L# B& P# V, P
- handled in milliseconds basis.
- y+ U5 k( h! f* v - - Low Level Initialization
; c) d9 l/ C' w8 u - */
. L, f/ G7 H# l& t - + O- \ Q9 e4 k, \
- /* USER CODE END 1 */
5 w1 c# K/ S3 K( H - 0 w5 |4 A8 D6 r" Y$ L# y# U
- /* MCU Configuration--------------------------------------------------------*/
. W% c7 i4 n' y4 G2 ]8 c
J/ j0 ?8 l5 }4 ^7 V3 p- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
% Q: }6 F( E$ m5 {% \4 h - HAL_Init();7 E+ i6 s" a1 i' `
- Enable_IT_Uart_Fun();2 x# ?) d+ b; ]. C$ H9 o1 @- S$ `7 ]
- 2 |1 H* d0 I, a8 K9 L
- /* USER CODE BEGIN Init /
- c7 \0 W7 z7 @0 K$ y - / Configure the system clock to 56 MHz /" l5 @* V6 C% X; } q# U' x
- / USER CODE END Init */( U/ P4 P" K- ]
- 6 w/ S* u6 O! B% R+ d2 E' N
- /* Configure the system clock */5 i8 u0 I" T$ O6 y! l# C
- SystemClock_Config();
! n! n4 b" s( G& u, K% j - . `) f N% }( v! X5 x
- /* USER CODE BEGIN SysInit */. U \; R5 \% X; N
- 4 z% x, v8 k$ v
- /* USER CODE END SysInit */
+ X1 k3 k) O6 [+ |- M7 ]3 e
: L6 ?/ o0 U& M$ F7 M5 O' d, D- /* Initialize all configured peripherals /0 |+ A* U& i6 O, j: \, d% `5 E2 d
- MX_GPIO_Init();
3 x3 F) P; }: ?9 A% h - MX_DMA_Init();3 h/ _5 q4 F/ ]; Q
- MX_ADC1_Init();( e9 D' l% N: }7 H6 p6 r/ r
- MX_USART2_UART_Init();
, K' `2 V) C* a g: Z - MX_IWDG_Init();
6 f: j- D0 W' V3 D! f( k& K - MX_USART1_UART_Init();! @9 l; I/ T- x% r' d
- / USER CODE BEGIN 2 */
/ V; j0 O( {: i1 U% {& g2 n - LED_Config();$ m3 Z z9 \0 V
- Lcd_Init();5 Q( m& \$ ~- o1 N/ r
- Clear_Screen();8 U9 w5 B7 m2 ~$ T: Z) s! q
- Show_Picture();/开机显示logo/. k. G, `; X4 M& ]: c% B
- Wireless_Mode_Config();
$ l2 X+ [* r' a l$ A+ w, g5 y% W7 q
' m# p( S: `/ E! ?+ ]5 h. P+ ~3 F7 E- Flash_Init();: ?5 [' g6 s }& P% m2 V' S( k
- if (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)5 \3 r( m2 h7 K* Y& h O8 n
- {; z. b0 {/ Y7 P
- /* Calibration Error */
/ P( |% }( q" q+ Q O - while(1);
1 ~7 V3 t$ K$ W - }& _6 z6 `2 H) ^( i
- if (HAL_ADC_Start_DMA(&hadc1,(uint32_t )ADC_ConvertedValue,7) != HAL_OK)
. r g' b0 V" G8 ~( ]2 C - {, }0 K4 m/ Y. ?) ?
- / ADC conversion start error */
7 k/ M9 j4 ^* {2 J9 [# y - while(1);
6 i% y0 T) w6 i& A1 s* t. | - }( O t2 L0 B: J
- HAL_ADC_Start(&hadc1);5 V5 c5 U" Q/ N+ H
8 d/ k! F" Y/ x) k7 e. e, t0 u
复制代码
1 E; w8 ^, F. i4 V/ ~, {
% T; d) k& g% ~ |