Is DMA2 not supported on the STM32F103Cx?

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
User avatar
rana
Posts: 11
Joined: Wed Sep 06, 2017 4:55 pm
Location: India-UK

Is DMA2 not supported on the STM32F103Cx?

Post by rana » Wed Sep 13, 2017 10:57 pm

Hello
Does the STM32F103 Blue Pill not supporting DMA2 ?
because i get an error error: 'DMA2' was not declared in this scope

basically from the 3 SPI TX pins PA7 , PB15 , PB5 i have to use the PB5 because the other ones are occupied.

#define SPI1_DMA_CH DMA_CH3// DMA chan for SPI1 DMA_CH3 PA7
#define SPI2_DMA_CH DMA_CH5 // DMA chan for SPI 2 DMA_CH5 PB15
#define SPI3_DMA_CH DMA2_CH2 // DMA chan for SPI 3 DMA_CH2 PB5

#define SPI_DMA DMA1 // DMA for SPI
#define SPI_DMA2 DMA2 // DMA for SPI

I get the above error in declaration of DMA2 error: 'DMA2' was not declared in this scope

So i want to call the dma_attach_interrupt for the PB5
dma_attach_interrupt(DMA2, SPI3_DMA_CH, &DMA_DO_SOMETHING);

PS i include the #include <SPI.h>

victor_pv
Posts: 1599
Joined: Mon Apr 27, 2015 12:12 pm

Re: DMA2 not supported?

Post by victor_pv » Thu Sep 14, 2017 5:21 am

The bluepill MCU, or any of that FLASH size (64/128KB) does not have DMA2.
Please check the reference manual for details. Basically the MCU does not have the peripherals that would use DMA2, so I guess it didn't make sense for STM to include a DMA controller only for M2M

User avatar
rana
Posts: 11
Joined: Wed Sep 06, 2017 4:55 pm
Location: India-UK

Re: DMA2 not supported?

Post by rana » Thu Sep 14, 2017 6:36 am

OK that makes sense

i am trying to Data output using DMA SPI , can i change pin for DMA channel for SPI1 DMA_CH3
Not the PA7 because is occupied but with the PB5 or something else, is there any other way to map to a different pin?

We do have 3 spi correct?
Image

User avatar
RogerClark
Posts: 6675
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: DMA2 not supported?

Post by RogerClark » Thu Sep 14, 2017 6:55 am

AFIK there are only 2 SPI devices on the F103Cx

The diagram only shows 2 SPI devices, but it shows SPI1 on both its normal pins PA5,PS6 and PA7 and its alternative pins e.g. PB5

By default SPI1 is on PA5,6,7

Note. NSS (hardware device select) is very buggy in the STM32 hardware, so its not enabled by the libmaple core.

I'm not sure why you are messing around with DMA channels, you would need to read STM's own 1000+ page reference manual to get the full details of DMA channels

http://www.st.com/content/ccc/resource/ ... 171190.pdf

User avatar
rana
Posts: 11
Joined: Wed Sep 06, 2017 4:55 pm
Location: India-UK

Re: Is DMA2 not supported on the STM32F103Cx?

Post by rana » Thu Sep 14, 2017 7:33 am

i found a project that serve my needs
the project Data outputs using DMA SPI

  dma_setup_transfer
  dma_set_num_transfers
  dma_enable
  SPI_dmaSend
   dma_attach_interrupt

all those functions are fed with spiDmaDev (DMA1) , DmaChannel ( DMA_CH3,DMA_CH5,DMA_CH2)

When i use the DMA_CH3 my TX pin is PA7
When i use the DMA_CH5 my TX pin is PB15
but
When i use the DMA_CH2 Normally my TX pin is PB5(i want this particular pin) but it doesnt work because belongs to DMA2


My problem is that PA7 & PB15 are occupied by something else in my project



inside the Arduino_STM32/blob/master/STM32F1/libraries/SPI/src/SPI.cpp i see this part of the code

// Init things specific to each SPI device
// clock divider setup is a bit of hack, and needs to be improved at a later date.
_settings[0].spi_d = SPI1;
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
_settings[0].spiDmaDev = DMA1;
_settings[0].spiTxDmaChannel = DMA_CH3;
_settings[0].spiRxDmaChannel = DMA_CH2;
_settings[1].spi_d = SPI2;
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
_settings[1].spiDmaDev = DMA1;
_settings[1].spiTxDmaChannel = DMA_CH5;
_settings[1].spiRxDmaChannel = DMA_CH4;
#if BOARD_NR_SPI >= 3
_settings[2].spi_d = SPI3;
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
_settings[2].spiDmaDev = DMA2;
_settings[2].spiTxDmaChannel = DMA_CH2;
_settings[2].spiRxDmaChannel = DMA_CH1;
#endif



i also found those DMA examples , that using DMA2
http://www.stm32duino.com/viewtopic.php ... 9&start=30

User avatar
RogerClark
Posts: 6675
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Is DMA2 not supported on the STM32F103Cx?

Post by RogerClark » Thu Sep 14, 2017 7:46 am

rana wrote:
Thu Sep 14, 2017 7:33 am

....


i also found those DMA examples , that using DMA2
http://www.stm32duino.com/viewtopic.php ... 9&start=30
BTW.

You mean DMA1 Channel 2.

User avatar
rana
Posts: 11
Joined: Wed Sep 06, 2017 4:55 pm
Location: India-UK

Re: Is DMA2 not supported on the STM32F103Cx?

Post by rana » Thu Sep 14, 2017 7:58 am

http://www.stm32duino.com/viewtopic.php ... t=30#p5548

Code: Select all

 dma_init(DMA2);
  spi_tx_dma_enable(SPI3);
      dma_attach_interrupt(DMA2, DMA_CH2, DMAEvent);  

User avatar
RogerClark
Posts: 6675
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Is DMA2 not supported on the STM32F103Cx?

Post by RogerClark » Thu Sep 14, 2017 8:15 am

That code relates to I2S which is not supported on the F103Cx

victor_pv
Posts: 1599
Joined: Mon Apr 27, 2015 12:12 pm

Re: Is DMA2 not supported on the STM32F103Cx?

Post by victor_pv » Thu Sep 14, 2017 12:57 pm

Rana I would advice you to spend some time checking the reference manual to know what's available in the MCU and how it works. The STM32F103 series include many different versions with some hardware differences between not, not just memory size.
You don't need to read completely every page of every section, but at least the sections that relate to peripherals you want to use so you understand them. It will save you a lot of time versus just trying to find and test code that may or may not work in the exact version of the MCU you are using.
DMA controller and channels have nothing to do with the pins. They are hardwired internally to different peripherals. Some peripherals pins can be remapped to different GPIO pins in the MCU, but when you remap a peripheral, it's still connected to the same DMA controller and channel.
Of course all this is explained much better and in more detail in the reference manual, so there is no point trying to explain the whole subject in a post.

User avatar
rana
Posts: 11
Joined: Wed Sep 06, 2017 4:55 pm
Location: India-UK

Re: Is DMA2 not supported on the STM32F103Cx?

Post by rana » Fri Sep 15, 2017 9:10 pm

After lots of reading i finally found the solution

Code: Select all

afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY); // release PB3 and PB5
afio_remap(AFIO_REMAP_SPI1); // remap SPI1
gpio_set_mode(GPIOB, 5, GPIO_AF_OUTPUT_PP);
This remaps to the alternative pin of PA7 into pin PB5 and project works.
BUT
i have also in my project a OLED SSD1306
SDA PB7
SCL PB6
the library of SSD1306 with the latest Wire library uses the HardWire HWIRE(1,I2C_FAST_MODE); // I2c2 and works just fine.
as long as i initialise the oled and starts to print graphics i lose the first part with my IC on PB5
Anyway i have to start reading again

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests