Skip to content

Commit 5b114b2

Browse files
committed
[examples] STM32F030F4P6-demo: SPI-DMA example
1 parent 88016a4 commit 5b114b2

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2020, Mike Wolfram
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
#include <modm/board.hpp>
13+
14+
using Mosi = GpioOutputA7;
15+
using Miso = GpioInputA6;
16+
using Sck = GpioOutputA5;
17+
using DmaRx = Dma1::Channel2;
18+
using DmaTx = Dma1::Channel3;
19+
using Spi = SpiMaster1_Dma<DmaRx, DmaTx>;
20+
21+
int main()
22+
{
23+
Board::initialize();
24+
25+
// Enable DMA1 controller
26+
Dma1::enable();
27+
// Enable SPI1
28+
Spi::connect<Mosi::Mosi, Miso::Miso, Sck::Sck>();
29+
Spi::initialize<Board::SystemClock, 12_MHz>();
30+
31+
while (true)
32+
{
33+
uint8_t sendBuffer[13] { "data to send" };
34+
uint8_t receiveBuffer[13];
35+
36+
// send out 12 bytes, don't care about response
37+
Spi::transferBlocking(sendBuffer, nullptr, 12);
38+
39+
// send out 12 bytes, read in 12 bytes
40+
Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
41+
}
42+
43+
return 0;
44+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Replace this with your custom programmer
2+
source [find interface/stlink-v2.cfg]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<library>
2+
<extends>modm:stm32f030_demo</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/stm32f030_demo/spi_dma</option>
5+
<option name="modm:build:openocd.cfg">openocd.cfg</option>
6+
</options>
7+
<modules>
8+
<module>modm:platform:gpio</module>
9+
<module>modm:platform:dma</module>
10+
<module>modm:platform:spi:1</module>
11+
<module>modm:build:scons</module>
12+
</modules>
13+
</library>

0 commit comments

Comments
 (0)