Skip to content

Commit 2e40ab4

Browse files
committed
[test] Add STM32H7 BDMA and SPI6 hardware unit test
Only runs on Nucleo-H723ZG
1 parent e6ffb1d commit 2e40ab4

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2024, Christopher Durand
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
12+
13+
def init(module):
14+
module.name = ":test:platform:spi"
15+
module.description = "STM32H7 SPI BDMA test"
16+
17+
def prepare(module, options):
18+
target = options[":target"]
19+
20+
identifier = target.identifier
21+
if identifier.platform != "stm32" or identifier.family != "h7":
22+
return False
23+
24+
module.depends(":platform:bdma", ":platform:dma", ":platform:spi:6")
25+
return True
26+
27+
def build(env):
28+
if not env.has_module(":board:nucleo-h723zg"):
29+
env.log.warn("The SPI test uses hardcoded GPIO pins."
30+
"Please make sure the pins are safe to use on other hardware.")
31+
return
32+
33+
env.outbasepath = "modm-test/src/modm-test/platform/spi_test"
34+
env.copy("spi_bdma_test.hpp")
35+
env.copy("spi_bdma_test.cpp")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2024, Christopher Durand
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 "spi_bdma_test.hpp"
13+
14+
#include <modm/platform.hpp>
15+
#include <modm/board.hpp>
16+
17+
using namespace modm::platform;
18+
19+
using Spi = SpiMaster6_Dma<Bdma::Channel0, Bdma::Channel1>;
20+
using Miso = GpioA6;
21+
using Sck = GpioC12;
22+
23+
void
24+
SpiBdmaTest::setUp()
25+
{
26+
Bdma::enable();
27+
Spi::connect<Miso::Miso, Sck::Sck>();
28+
Spi::initialize<Board::SystemClock, 16_MHz, 10_pct>();
29+
}
30+
31+
void
32+
SpiBdmaTest::testReceive()
33+
{
34+
constexpr std::array<uint8_t, 4> ones{0xff, 0xff, 0xff, 0xff};
35+
constexpr std::array<uint8_t, 4> zeros{};
36+
modm_section(".data_d3_sram") static std::array<uint8_t, 4> buffer{};
37+
38+
Miso::configure(Miso::InputType::PullUp);
39+
modm::delay_ns(500);
40+
Spi::transferBlocking(nullptr, buffer.data(), buffer.size());
41+
TEST_ASSERT_TRUE(buffer == ones);
42+
43+
Miso::configure(Miso::InputType::PullDown);
44+
modm::delay_ns(500);
45+
Spi::transferBlocking(nullptr, buffer.data(), buffer.size());
46+
TEST_ASSERT_TRUE(buffer == zeros);
47+
48+
Miso::configure(Miso::InputType::PullUp);
49+
modm::delay_ns(500);
50+
Spi::transferBlocking(nullptr, buffer.data(), buffer.size());
51+
TEST_ASSERT_TRUE(buffer == ones);
52+
53+
Miso::configure(Miso::InputType::Floating);
54+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2024, Christopher Durand
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 <unittest/testsuite.hpp>
13+
14+
/// @ingroup modm_test_test_platform_spi
15+
class SpiBdmaTest : public unittest::TestSuite
16+
{
17+
public:
18+
void
19+
setUp() override;
20+
21+
void
22+
testReceive();
23+
};

0 commit comments

Comments
 (0)