diff --git a/test/modm/platform/spi/stm32h7/module.lb b/test/modm/platform/spi/stm32h7/module.lb new file mode 100644 index 0000000000..4c19887b36 --- /dev/null +++ b/test/modm/platform/spi/stm32h7/module.lb @@ -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") diff --git a/test/modm/platform/spi/stm32h7/spi_bdma_test.cpp b/test/modm/platform/spi/stm32h7/spi_bdma_test.cpp new file mode 100644 index 0000000000..b177057401 --- /dev/null +++ b/test/modm/platform/spi/stm32h7/spi_bdma_test.cpp @@ -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 +#include + +using namespace modm::platform; + +using Spi = SpiMaster6_Dma; +using Miso = GpioA6; +using Sck = GpioC12; + +void +SpiBdmaTest::setUp() +{ + Bdma::enable(); + Spi::connect(); + Spi::initialize(); +} + +void +SpiBdmaTest::testReceive() +{ + constexpr std::array ones{0xff, 0xff, 0xff, 0xff}; + constexpr std::array zeros{}; + modm_section(".data_d3_sram") static std::array 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); +} diff --git a/test/modm/platform/spi/stm32h7/spi_bdma_test.hpp b/test/modm/platform/spi/stm32h7/spi_bdma_test.hpp new file mode 100644 index 0000000000..4e8d3894a4 --- /dev/null +++ b/test/modm/platform/spi/stm32h7/spi_bdma_test.hpp @@ -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 + +/// @ingroup modm_test_test_platform_spi +class SpiBdmaTest : public unittest::TestSuite +{ +public: + void + setUp() override; + + void + testReceive(); +};