Skip to content

Commit ebcffdf

Browse files
committed
[examples] Nucleo-F303RE: SPI-DMA example
1 parent 0a507aa commit ebcffdf

File tree

2 files changed

+55
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)