-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add FDCAN hardware unit test for Nucleo G474RE
- Loading branch information
1 parent
d8977ad
commit 2d2199b
Showing
5 changed files
with
178 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
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,12 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<library> | ||
<extends>modm:nucleo-g474re</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../build/generated-unittest/nucleo-g474/</option> | ||
<option name="modm:build:unittest.source">../../build/generated-unittest/nucleo-g474/modm-test</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:heap</module> | ||
<module>modm-test:test:**</module> | ||
</modules> | ||
</library> |
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,101 @@ | ||
/* | ||
* Copyright (c) 2021, 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 "fdcan_test.hpp" | ||
|
||
#include <modm/platform.hpp> | ||
#include <modm/board.hpp> | ||
|
||
using namespace modm::platform; | ||
|
||
void | ||
FdcanTest::setUp() | ||
{ | ||
Fdcan1::initialize<Board::SystemClock, 500_kbps, 1_pct>(9, Fdcan1::Mode::TestInternalLoopback); | ||
|
||
// receive all extended messages | ||
Fdcan1::setExtendedFilter(0, Fdcan1::FilterConfig::Fifo1, | ||
modm::can::ExtendedIdentifier(0), | ||
modm::can::ExtendedMask(0)); | ||
} | ||
|
||
void | ||
FdcanTest::testSendReceive() | ||
{ | ||
modm::can::Message message{0x12345678, 7}; | ||
constexpr std::string_view data = "\xDE\xAD\xBE\xEF\x12\x34\x56"; | ||
std::copy(std::begin(data), std::begin(data) + 7, message.data); | ||
|
||
TEST_ASSERT_FALSE(Fdcan1::isMessageAvailable()); | ||
TEST_ASSERT_TRUE(Fdcan1::sendMessage(message)); | ||
|
||
modm::delay_ms(1); | ||
|
||
modm::can::Message receivedMessage; | ||
TEST_ASSERT_TRUE(Fdcan1::getMessage(receivedMessage)); | ||
TEST_ASSERT_EQUALS(receivedMessage.getIdentifier(), 0x12345678u); | ||
TEST_ASSERT_EQUALS(receivedMessage.getLength(), 7); | ||
TEST_ASSERT_TRUE(receivedMessage.isExtended()); | ||
TEST_ASSERT_FALSE(receivedMessage.isRemoteTransmitRequest()); | ||
TEST_ASSERT_TRUE(std::equal(std::begin(data), std::begin(data) + 7, message.data)); | ||
} | ||
|
||
void | ||
FdcanTest::testFilters() | ||
{ | ||
Fdcan1::setStandardFilter(27, Fdcan1::FilterConfig::Fifo0, | ||
modm::can::StandardIdentifier(0x108), | ||
modm::can::StandardMask(0x1F8)); | ||
|
||
modm::can::Message message{0x188, 0}; | ||
message.setExtended(false); | ||
Fdcan1::sendMessage(message); | ||
modm::delay_ms(1); | ||
TEST_ASSERT_FALSE(Fdcan1::isMessageAvailable()); | ||
|
||
message.setIdentifier(0xF09); | ||
Fdcan1::sendMessage(message); | ||
modm::delay_ms(1); | ||
TEST_ASSERT_TRUE(Fdcan1::isMessageAvailable()); | ||
TEST_ASSERT_TRUE(Fdcan1::getMessage(message)); | ||
TEST_ASSERT_FALSE(message.isExtended()); | ||
} | ||
|
||
void | ||
FdcanTest::testBuffers() | ||
{ | ||
modm::can::Message message{0x4711, 0}; | ||
// send 8 messages, exceeds internal peripheral queue size | ||
for (uint_fast8_t i = 0; i <= 8; ++i) { | ||
message.setLength(i); | ||
for (uint_fast8_t dataIndex = 0; dataIndex < i; ++dataIndex) { | ||
message.data[dataIndex] = i; | ||
} | ||
Fdcan1::sendMessage(message); | ||
} | ||
|
||
modm::delay_ms(10); | ||
|
||
// try to receive same messages | ||
modm::can::Message receivedMessage; | ||
for (uint_fast8_t i = 0; i <= 8; ++i) { | ||
TEST_ASSERT_TRUE(Fdcan1::getMessage(receivedMessage)); | ||
|
||
TEST_ASSERT_EQUALS(receivedMessage.getIdentifier(), 0x4711u); | ||
TEST_ASSERT_EQUALS(receivedMessage.getLength(), i); | ||
|
||
for (uint_fast8_t dataIndex = 0; dataIndex < i; ++dataIndex) { | ||
TEST_ASSERT_EQUALS(receivedMessage.data[dataIndex], i); | ||
} | ||
} | ||
TEST_ASSERT_FALSE(Fdcan1::isMessageAvailable()); | ||
TEST_ASSERT_FALSE(Fdcan1::getMessage(message)); | ||
} |
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,29 @@ | ||
/* | ||
* Copyright (c) 2021, 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_fdcan | ||
class FdcanTest : public unittest::TestSuite | ||
{ | ||
public: | ||
void | ||
setUp() override; | ||
|
||
void | ||
testSendReceive(); | ||
|
||
void | ||
testFilters(); | ||
|
||
void | ||
testBuffers(); | ||
}; |
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,30 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2021, 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:fdcan" | ||
|
||
def prepare(module, options): | ||
target = options[":target"] | ||
|
||
identifier = target.identifier | ||
if identifier.platform != "stm32" or identifier.family != "g4": | ||
return False | ||
|
||
module.depends(":architecture:delay", ":platform:can:1") | ||
return True | ||
|
||
def build(env): | ||
# env.substitutions = properties | ||
env.outbasepath = "modm-test/src/modm-test/platform/fdcan_test" | ||
env.copy("fdcan_test.hpp") | ||
env.copy("fdcan_test.cpp") |