1

I have a simple program that uses ADC to convert 2 inputs, I use DMA in circular mode. Everything works great. The only problem I have is that in order to reflash the STM32, I have to first erase the chip. This is only happening when I set the ADC to circular mode.

Hopefully someone can help with this. Thanks!

Here is the code for setting up DMA/ADC

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();
   }
}

And here is the output from jlink. Again, if I erase the chip everything works fine.

/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...
Roy
  • 11
  • 1

0 Answers0