-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add STM32H7 BDMA and SPI6 hardware unit test
Only runs on Nucleo-H723ZG
- Loading branch information
1 parent
65c6b1f
commit 3b20146
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |