You need to enable JavaScript to run this app. 采用循环DMA模式驱动ADC时STM32F401RE无法直接重新烧录的问题
优惠活动
大模型
产品
解决方案
定价
更多

采用循环DMA模式驱动ADC时STM32F401RE无法直接重新烧录的问题

STM32F401RE 搭配ADC循环DMA配置时的烧录异常问题

问题描述

  • 基于STM32F401RE开发的双通道ADC采集程序,配置DMA为循环模式运行,ADC采集功能完全正常
  • 异常表现:重新烧录固件时无法直接完成烧写操作,必须先手动全片擦除芯片后才能正常烧录
  • 触发条件:该问题仅在启用ADC的循环DMA配置时才会出现,关闭对应配置后烧录流程无异常
  • 诉求:恳请各位开发者协助定位故障原因

ADC与DMA初始化配置代码

void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
{
   GPIO_InitTypeDef GPIO_InitStruct = {0};
   if (hadc->Instance == ADC1)
   {
       __HAL_RCC_ADC1_CLK_ENABLE();
       GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
       GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
       GPIO_InitStruct.Pull = GPIO_NOPULL;
       HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

       hdma_adc1.Instance = DMA2_Stream0;
       hdma_adc1.Init.Channel = DMA_CHANNEL_0;
       hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
       hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
       hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
       hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
       hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
       hdma_adc1.Init.Mode = DMA_CIRCULAR;
       hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
       hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
       hdma_adc1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
       if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
       {
           Error_Handler();
       }

       __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
   }
}

void MX_ADC1_Init(void)
{
   ADC_ChannelConfTypeDef sConfig = {0};
   hadc1.Instance = ADC1;
   hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
   hadc1.Init.Resolution = ADC_RESOLUTION_12B;
   hadc1.Init.ScanConvMode = ENABLE;
   hadc1.Init.ContinuousConvMode = ENABLE;
   hadc1.Init.DiscontinuousConvMode = DISABLE;
   hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
   hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
   hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
   hadc1.Init.NbrOfConversion = 2;
   hadc1.Init.DMAContinuousRequests = ENABLE;
   hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
   if (HAL_ADC_Init(&hadc1) != HAL_OK)
   {
     Error_Handler();
   }

   sConfig.Channel = ADC_CHANNEL_8;
   sConfig.Rank = 1;
   sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
   {
       Error_Handler();
   }

   sConfig.Channel = ADC_CHANNEL_9;
   sConfig.Rank = 2;
   sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
   {
       Error_Handler();
   }
}

J-Link烧录异常日志

补充说明:执行芯片全片擦除操作后,所有烧录流程均可正常运行,无报错。

/Applications/SEGGER/JLink_V686c/JLinkGDBServerCLExe -select USB -device STM32F401RE -endian little -if SWD -speed auto -ir -noLocalhostOnly

SEGGER J-Link GDB Server V6.86c Command Line Version
JLinkARM.dll V6.86c (DLL compiled Oct  6 2020 14:16:39)
Command line: -select USB -device STM32F401RE -endian little -if SWD -speed auto -ir -noLocalhostOnly

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            on
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms

------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none

------Target related settings------
Target device:                 STM32F401RE
Target interface:              SWD
Target interface speed:        auto
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link EDU Mini V1 compiled Oct  2 2020 17:00:40
Hardware: V1.00
S/N: 801018944
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.28 V
Listening on TCP/IP port 2331
Connecting to target...
Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 2 bytes @ address 0x0800EF10 (Data = 0xB508)
Read 2 bytes @ address 0x080080A0 (Data = 0x4770)
Read 4 bytes @ address 0x00000000 (Data = 0x20018000)
Read 2 bytes @ address 0x00000000 (Data = 0x8000)
Downloading 408 bytes @ address 0x08000000
Downloading 16048 bytes @ address 0x080001C0
Downloading 16144 bytes @ address 0x08004070
Downloading 16048 bytes @ address 0x08007F80
Downloading 15968 bytes @ address 0x0800BE30
Downloading 16000 bytes @ address 0x0800FC90
Downloading 7876 bytes @ address 0x08013B10
Downloading 5908 bytes @ address 0x080159D8
Downloading 956 bytes @ address 0x080170EC
Downloading 1032 bytes @ address 0x080174A8
Downloading 24 bytes @ address 0x080178B0
Downloading 4 bytes @ address 0x080178C8
Downloading 2496 bytes @ address 0x080178CC
ERROR: Failed to prepare for programming.
*RAM check failed @ addr 0x20000E6C.*
*RAM check failed while testing 0x1050 bytes @ addr 0x200006CC.*
Writing register (PC = 0x 800c8f0)
Read 2 bytes @ address 0x0800EF10 (Data = 0xB508)
Read 2 bytes @ address 0x080080A0 (Data = 0x4770)
Received monitor command: reset
Resetting target
Resetting target
Debugger connected to 127.0.0.1:2331
Starting target CPU...

内容的提问来源于stack exchange,提问作者Roy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.26 20:06:08