Recent

Author Topic: stm32f103 dma problem  (Read 230 times)

diego bertotti

  • New Member
  • *
  • Posts: 41
stm32f103 dma problem
« on: July 07, 2020, 07:10:37 pm »
hi

im trying bluepill board

using  unit stm32f103fw
{ Converted from STM FWlib

 Contributors:
  Jeppe Johansen
  Bernd Mueller
  Valerio Turrini with really small adjustments.....
}

when i use dma channels system hangs

Code: Pascal  [Select][+][-]
  1.   DMA_InitTypeDef.DMA_BufferSize:= 64;
  2.   DMA_InitTypeDef.DMA_DIR:= DMA_DIR_PeripheralSRC;
  3.   DMA_InitTypeDef.DMA_M2M:= DMA_M2M_Disable;
  4.   DMA_InitTypeDef.DMA_MemoryBaseAddr:=  @RXbuffer1;
  5.   DMA_InitTypeDef.DMA_MemoryDataSize:= DMA_MemoryDataSize_Byte;
  6.   DMA_InitTypeDef.DMA_MemoryInc:= DMA_MemoryInc_Enable;
  7.   DMA_InitTypeDef.DMA_Mode:= DMA_Mode_Circular;
  8.   DMA_InitTypeDef.DMA_PeripheralBaseAddr:= @Usart1.DR;
  9.   DMA_InitTypeDef.DMA_PeripheralDataSize:= DMA_PeripheralDataSize_Byte;
  10.   DMA_InitTypeDef.DMA_PeripheralInc:= DMA_PeripheralInc_Disable;
  11.   DMA_InitTypeDef.DMA_Priority:= DMA_Priority_Medium;
  12.   DMA_Init(DMA1.Channel[5], DMA_InitTypeDef); //USART1_RX
  13.   DMA_CMD(DMA1.Channel[5], Enabled);
  14.  

or even hangs if i use only the dma_deinit function

if i comment out the last 2 lines, dont hang, but ovbiously, dont work the dma controller, but all the rest code work fine


in the stm32f10x_md file i found this ¿bug?
Code: Pascal  [Select][+][-]
  1.  TDMARegisters = record
  2.   ISR,
  3.   IFCR: longword;
  4.   //Channel: array[0..7] of TDMAChannel; //wrong!! 8 channels space but have only 7
  5.   Channel: array[0..6] of TDMAChannel;  //diego bertotti 7/7/2020
  6.  end;
  7.  


 thanks in advance for any help/suggestions

 

MiR

  • Jr. Member
  • **
  • Posts: 96
Re: stm32f103 dma problem
« Reply #1 on: July 07, 2020, 09:35:51 pm »
Looking at the datasheet 0..6 is correct, but better values would have been 1..7 as the DMA channels are numbered 1-7 in the reference manual.

Not sure if you took the offset of one into account in your code, DMA1.Channel[5] actually means use Channel6

Michael
« Last Edit: July 07, 2020, 09:41:29 pm by MiR »

MiR

  • Jr. Member
  • **
  • Posts: 96
Re: stm32f103 dma problem
« Reply #2 on: July 07, 2020, 09:40:10 pm »
Again, from the reference manual:

USART1.RX is attached to Channel5 which means you will have to take index '4'

diego bertotti

  • New Member
  • *
  • Posts: 41
Re: stm32f103 dma problem
« Reply #3 on: July 07, 2020, 10:17:19 pm »
thanks for replys

i try with index 4 (you are right). same problem.

remember, i have the same problem, using the DMA_deinit function. in this case is not important the index value, is just an initilization, and hangs too.

i fix index form 0 to 6 because this code

Code: Pascal  [Select][+][-]
  1. procedure DMA_DeInit(var DMAy_Channelx: TDMAChannel);
  2.  
  3. begin
  4.    DMAy_Channelx.CCR:= DMAy_Channelx.CCR and (not(CCR_ENABLE_SET));
  5.    DMAy_Channelx.CCR:=0;
  6.    DMAy_Channelx.CNDTR:=0;
  7.    DMAy_Channelx.CPAR:=0;
  8.    DMAy_Channelx.CMAR:=0;
  9.    if @DMAy_Channelx = @DMA1.Channel[0] then
  10.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel1_IT_Mask
  11.    else if @DMAy_Channelx = @DMA1.Channel[1] then
  12.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel2_IT_Mask
  13.    else if @DMAy_Channelx = @DMA1.Channel[2] then
  14.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel3_IT_Mask
  15.    else if @DMAy_Channelx = @DMA1.Channel[3] then
  16.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel4_IT_Mask
  17.    else if @DMAy_Channelx = @DMA1.Channel[4] then
  18.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel5_IT_Mask
  19.    else if @DMAy_Channelx = @DMA1.Channel[5] then
  20.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel6_IT_Mask
  21.    else if @DMAy_Channelx = @DMA1.Channel[6] then
  22.       DMA1.IFCR := DMA1.IFCR or DMA1_Channel7_IT_Mask
  23.    else if @DMAy_Channelx = @DMA2.Channel[0] then
  24.       DMA2.IFCR := DMA2.IFCR or DMA2_Channel1_IT_Mask
  25.    else if @DMAy_Channelx = @DMA2.Channel[1] then
  26.       DMA2.IFCR := DMA2.IFCR or DMA2_Channel2_IT_Mask
  27.    else if @DMAy_Channelx = @DMA2.Channel[2] then
  28.       DMA2.IFCR := DMA2.IFCR or DMA2_Channel3_IT_Mask
  29.    else if @DMAy_Channelx = @DMA2.Channel[3] then
  30.       DMA2.IFCR := DMA2.IFCR or DMA2_Channel4_IT_Mask
  31.    else if @DMAy_Channelx = @DMA2.Channel[4] then
  32.       DMA2.IFCR := DMA2.IFCR or DMA2_Channel5_IT_Mask
  33. end;    
  34.  

look for example channel 1 use index 0!

MiR

  • Jr. Member
  • **
  • Posts: 96
Re: stm32f103 dma problem
« Reply #4 on: July 07, 2020, 10:32:49 pm »
Have you tried running your deinit code in a debugger?

When I compare your De-Init Code to the original code in the C-Library it looks like a 1:1 translation so there does not seem to be an issue with the code itself.

In the debugger you will see easily if some interrupt triggers or you get some other exception

diego bertotti

  • New Member
  • *
  • Posts: 41
Re: stm32f103 dma problem
« Reply #5 on: July 07, 2020, 10:39:33 pm »
sorry, dont have debugger
wich one?

MiR

  • Jr. Member
  • **
  • Posts: 96
Re: stm32f103 dma problem
« Reply #6 on: July 07, 2020, 10:53:46 pm »
There's a moster long thread here in the forum on debugging.
You can use a 2nd bluepill flashed with either original stlink firmware (google is your friend) or use the very good Black Magic Probe which also fits on a bluepill.

Also found reset code in libopencm3 (which I use sometimes) looks pretty much the same...

Is the peripheral clock for DMA enabled?

void dma_channel_reset(uint32_t dma, uint8_t channel)
{
   /* Disable channel and reset config bits. */
   DMA_CCR(dma, channel) = 0;
   /* Reset data transfer number. */
   DMA_CNDTR(dma, channel) = 0;
   /* Reset peripheral address. */
   DMA_CPAR(dma, channel) = 0;
   /* Reset memory address. */
   DMA_CMAR(dma, channel) = 0;
   /* Reset interrupt flags. */
   DMA_IFCR(dma) |= DMA_IFCR_CIF(channel);
}

diego bertotti

  • New Member
  • *
  • Posts: 41
Re: stm32f103 dma problem
« Reply #7 on: July 07, 2020, 11:24:18 pm »
look this!!!!

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.   PDMARegisters : ^LongWord;
  4.  
  5.  
  6.   PDMARegisters := @DMA1 + $58;   //CCR5
  7.   PDMARegisters^:= %000000010100001;
  8.   PDMARegisters := @DMA1 + $5C;   //CNDTR5
  9.   PDMARegisters^:= 64;  
  10.   PDMARegisters := @DMA1 + $60;   //CPAR5
  11.   PDMARegisters^:= LongWord(@Usart1.DR);
  12.   PDMARegisters := @DMA1 + $64;   //CMAR5
  13.   PDMARegisters^:= LongWord(@RXBuffer1);
  14.  
  15.  

i still dont know if dma working, but now dont hangs

and dma clock is enabled


Code: Pascal  [Select][+][-]
  1.  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1 or RCC_AHBPeriph_DMA2 or RCC_AHBPeriph_SRAM or RCC_AHBPeriph_FLITF, Enabled);
  2.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, Enabled);
  3.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, Enabled);
  4.  
  5.  
« Last Edit: July 07, 2020, 11:26:00 pm by diego bertotti »

 

TinyPortal © 2005-2018