Skip to content

Commit

Permalink
DMA for STM32F4/F7, not working yet...
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Oct 24, 2021
1 parent 4dec359 commit c0e36f4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/nucleo_f429zi/spi_dma/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020, Mike Wolfram
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>

using Mosi = GpioOutputB5;
using Miso = GpioInputB4;
using Sck = GpioOutputB3;
using DmaRx = Dma2::Channel0;
using DmaTx = Dma2::Channel3;
using Spi = SpiMaster1_Dma<DmaRx, DmaTx>;
//using Spi = SpiMaster1;

uint8_t sendBuffer[13] { "data to send" };
uint8_t receiveBuffer[13];

int main()
{
Board::initialize();

MODM_LOG_INFO << "Hello from SPI-DMA example on Nucleo-F429ZI!" << modm::endl;

// Enable DMA1 controller
Dma2::enable();
// Enable SPI1
Spi::connect<Mosi::Mosi, Miso::Miso, Sck::Sck>();
Spi::initialize<Board::SystemClock, 10_MHz>();

while (true)
{
MODM_LOG_INFO << "sendBuffer adress: " << modm::hex << sendBuffer << modm::endl;
MODM_LOG_INFO << "receiveBuffer adress: " << modm::hex << receiveBuffer << modm::endl;
MODM_LOG_INFO << "Info: 0x20000000 is start of SRAM1" << modm::endl;

MODM_LOG_INFO << "Before first transfer" << modm::endl;

// send out 12 bytes, don't care about response
Spi::transferBlocking(sendBuffer, nullptr, 12);

MODM_LOG_INFO << "After first transfer" << modm::endl;

// send out 12 bytes, read in 12 bytes
Spi::transferBlocking(sendBuffer, receiveBuffer, 12);

MODM_LOG_INFO << "After second transfer" << modm::endl;
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/nucleo_f429zi/spi_dma/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:nucleo-f429zi</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f429zi/spi_dma</option>
</options>
<modules>
<module>modm:platform:gpio</module>
<module>modm:platform:dma</module>
<module>modm:platform:spi:1</module>
<module>modm:build:scons</module>
</modules>
</library>

0 comments on commit c0e36f4

Please sign in to comment.