cancel
Showing results for 
Search instead for 
Did you mean: 

Conflict of JTAG Programmer and continuous read from ADC to DMA on STM32F103RB

kwiatkowski
Associate II
Posted on September 28, 2011 at 13:39

Hello,

I have a troubles with JTAG programmers if on my processor runs following program:

    RCC_ADCCLKConfig(RCC_PCLK2_Div8);

    DMA_DeInit(DMA1_Channel1);

    DMA_InitTypeDef dmaInitStructure;

    DMA_StructInit(&dmaInitStructure);

    dmaInitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;

    dmaInitStructure.DMA_MemoryBaseAddr = (uint32_t)m_sensorsValues;

    dmaInitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

    dmaInitStructure.DMA_BufferSize = sizeof(m_sensorsValues)/sizeof(m_sensorsValues[0]);

    dmaInitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

    dmaInitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

    dmaInitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

    dmaInitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

    dmaInitStructure.DMA_Mode = DMA_Mode_Circular;

    dmaInitStructure.DMA_Priority = DMA_Priority_Low;

    dmaInitStructure.DMA_M2M = DMA_M2M_Disable;

    DMA_Init(DMA1_Channel1, &dmaInitStructure);

    DMA_Cmd(DMA1_Channel1, ENABLE);

    ADC_InitTypeDef adcInitStructure;

    ADC_StructInit(&adcInitStructure);

    adcInitStructure.ADC_Mode = ADC_Mode_Independent;

    adcInitStructure.ADC_ScanConvMode = ENABLE;

    adcInitStructure.ADC_ContinuousConvMode = ENABLE;

    adcInitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

    adcInitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    adcInitStructure.ADC_NbrOfChannel = 3;

    ADC_Init(ADC1, &adcInitStructure);

    //CO

    ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_239Cycles5);

    //CWU

    ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 2, ADC_SampleTime_239Cycles5);

    //MOSFET

    ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 3, ADC_SampleTime_239Cycles5);

    //SPALIN

    //ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 4, ADC_SampleTime_239Cycles5);

    ADC_DMACmd(ADC1, ENABLE);

    ADC_Cmd(ADC1, ENABLE);

    ADC_ResetCalibration(ADC1);

    while (ADC_GetResetCalibrationStatus(ADC1));

    ADC_StartCalibration(ADC1);

    while (ADC_GetCalibrationStatus(ADC1));

    ADC_SoftwareStartConvCmd(ADC1, ENABLE);

The program works fine, but I can't

download new program because the programmer corrupts. If I use ST-Link programmer and ST-LinkUtility then I can erease processor but if I have any alternative software I can't do it. I try this on OLIMEX programmer and ereasing program after write above program is imposible. If I disable DMA or if I disable continous read from ADC, it works fine. What I can do? This is done as well as in official example.

#dma #continuous #adc #jtag
5 REPLIES 5
Posted on September 28, 2011 at 14:26

This is probably because the JTAG has to wrestle control after a reset, you could add a delay, or check for a GPIO state before proceeding into your code. Depending on the communication speed this might be a second or so. You could observe this by having a simple application that sends a constant stream of data to the serial port, and see how much data you get as the JTAG pod resets the processor and then tries to stop/control it.

You could also try some more up market JTAG pods that have different reset/startup strategies.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kwiatkowski
Associate II
Posted on September 28, 2011 at 14:59

Could you give me more tips how I can do this in my code? How I can check GPIO state and when I have to do a delay?

Posted on September 28, 2011 at 16:05

Could you give me more tips how I can do this in my code? How I can check GPIO state and when I have to do a delay?

 

Clearly early in the boot process, before you light off the DMA which is operating automously to the ARM Core which is what the JTAG protocol is try to control. The length of an arbitrary delay will depend on your tools, and the window required to gain control of the core. I've suggested a method to quantify that in my original post.

For example a button or jumper on PD.01

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

  /* Configure PD.00 as input pulled-up */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

     if (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0 ) == Bit_RESET) // (PD.00) Button Pressed or Jumper, Grounding

    while(1); // Spin

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kwiatkowski
Associate II
Posted on October 03, 2011 at 07:16

And before while() I can turn off continous work of ADC and have no problems with JTAG?

Posted on October 03, 2011 at 16:12

And before while() I can turn off continous work of ADC and have no problems with JTAG?

Pretty much. Or you could put it before you even set up the DMA or other peripherals, seeing as this is an initial programming issue. I'm sure you could also tear down the peripherals on a running system to get it to a programmable state. You are however better situated to test/evaluate this on your own system.

You could also add a button/switch on the BOOTx pins to get it to reset into the system loader with similar effect.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..