Skip to content

Commit

Permalink
[test] Add STM32H7 BDMA and SPI6 hardware unit test
Browse files Browse the repository at this point in the history
Only runs on Nucleo-H723ZG
  • Loading branch information
chris-durand committed Jan 2, 2024
1 parent 65c6b1f commit 3b20146
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/modm/platform/spi/stm32h7/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024, Christopher Durand
#
# 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/.


def init(module):
module.name = ":test:platform:spi"
module.description = "STM32H7 SPI BDMA test"

def prepare(module, options):
target = options[":target"]

identifier = target.identifier
if identifier.platform != "stm32" or identifier.family != "h7":
return False

module.depends(":platform:bdma", ":platform:dma", ":platform:spi:6")
return True

def build(env):
if not env.has_module(":board:nucleo-h723zg"):
env.log.warn("The SPI test uses hardcoded GPIO pins."
"Please make sure the pins are safe to use on other hardware.")
return

env.outbasepath = "modm-test/src/modm-test/platform/spi_test"
env.copy("spi_bdma_test.hpp")
env.copy("spi_bdma_test.cpp")
54 changes: 54 additions & 0 deletions test/modm/platform/spi/stm32h7/spi_bdma_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2024, Christopher Durand
*
* 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 "spi_bdma_test.hpp"

#include <modm/platform.hpp>
#include <modm/board.hpp>

using namespace modm::platform;

using Spi = SpiMaster6_Dma<Bdma::Channel0, Bdma::Channel1>;
using Miso = GpioA6;
using Sck = GpioC12;

void
SpiBdmaTest::setUp()
{
Bdma::enable();
Spi::connect<Miso::Miso, Sck::Sck>();
Spi::initialize<Board::SystemClock, 16_MHz, 10_pct>();
}

void
SpiBdmaTest::testReceive()
{
constexpr std::array<uint8_t, 4> ones{0xff, 0xff, 0xff, 0xff};
constexpr std::array<uint8_t, 4> zeros{};
modm_section(".data_d3_sram") static std::array<uint8_t, 4> buffer{};

Miso::configure(Miso::InputType::PullUp);
modm::delay_ns(500);
Spi::transferBlocking(nullptr, buffer.data(), buffer.size());
TEST_ASSERT_TRUE(buffer == ones);

Miso::configure(Miso::InputType::PullDown);
modm::delay_ns(500);
Spi::transferBlocking(nullptr, buffer.data(), buffer.size());
TEST_ASSERT_TRUE(buffer == zeros);

Miso::configure(Miso::InputType::PullUp);
modm::delay_ns(500);
Spi::transferBlocking(nullptr, buffer.data(), buffer.size());
TEST_ASSERT_TRUE(buffer == ones);

Miso::configure(Miso::InputType::Floating);
}
23 changes: 23 additions & 0 deletions test/modm/platform/spi/stm32h7/spi_bdma_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024, Christopher Durand
*
* 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 <unittest/testsuite.hpp>

/// @ingroup modm_test_test_platform_spi
class SpiBdmaTest : public unittest::TestSuite
{
public:
void
setUp() override;

void
testReceive();
};

0 comments on commit 3b20146

Please sign in to comment.