Skip to content

Commit d1938eb

Browse files
committed
[test] Add SAMV71 I2C unit test for Xplained Ultra board
1 parent 0689b05 commit d1938eb

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023, 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 "i2c_platform_test.hpp"
13+
14+
#include <modm/platform.hpp>
15+
#include <modm/board.hpp>
16+
#include <modm/driver/storage/at24mac402.hpp>
17+
18+
using namespace modm::platform;
19+
using namespace Board;
20+
21+
namespace
22+
{
23+
modm::At24Mac402<I2c> eeprom{0x57};
24+
}
25+
26+
void
27+
I2cPlatformTest::setUp()
28+
{
29+
I2c::connect<Sda::Twd, Scl::Twck>();
30+
I2c::initialize<SystemClock, 400_kHz>();
31+
}
32+
33+
void
34+
I2cPlatformTest::testPing()
35+
{
36+
// ping at wrong address
37+
for (uint8_t address = 0x50; address <= 0x56; ++address) {
38+
eeprom.setAddress(address);
39+
const bool response = RF_CALL_BLOCKING(eeprom.ping());
40+
TEST_ASSERT_FALSE(response);
41+
}
42+
// set correct address 0x57
43+
eeprom.setAddress(0x57);
44+
// ping at correct address
45+
for (int i = 0; i < 20; ++i) {
46+
const bool response = RF_CALL_BLOCKING(eeprom.ping());
47+
TEST_ASSERT_TRUE(response);
48+
}
49+
}
50+
51+
void
52+
I2cPlatformTest::testDataRead()
53+
{
54+
std::array<uint8_t, 6> buffer{};
55+
56+
// read pre-programmed MAC address
57+
58+
// read at wrong address
59+
eeprom.setAddress(0x55);
60+
bool readSuccess = RF_CALL_BLOCKING(eeprom.readMac(buffer));
61+
TEST_ASSERT_FALSE(readSuccess);
62+
63+
// read at correct address
64+
eeprom.setAddress(0x57);
65+
readSuccess = RF_CALL_BLOCKING(eeprom.readMac(buffer));
66+
TEST_ASSERT_TRUE(readSuccess);
67+
68+
TEST_ASSERT_EQUALS(buffer[0], 0xfc);
69+
TEST_ASSERT_EQUALS(buffer[1], 0xc2);
70+
TEST_ASSERT_EQUALS(buffer[2], 0x3d);
71+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2023, 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_i2c
15+
class I2cPlatformTest : public unittest::TestSuite
16+
{
17+
public:
18+
void
19+
setUp() override;
20+
21+
void
22+
testPing();
23+
24+
void
25+
testDataRead();
26+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2023, 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:i2c"
15+
module.description = "Tests for SAMx7x I2C"
16+
17+
def prepare(module, options):
18+
target = options[":target"]
19+
20+
identifier = target.identifier
21+
if identifier.platform != "sam" or identifier.family != "e7x/s7x/v7x":
22+
return False
23+
24+
module.depends(":platform:i2c:0")
25+
module.depends(":driver:at24mac402")
26+
return True
27+
28+
def build(env):
29+
if not env.has_module(":board:samv71-xplained-ultra"):
30+
env.log.warn("The test requires an AT24MAC402 EEPROM to be connected to specific pins."
31+
"Only the SAMV71 Xplained Ultra board is supported for now.")
32+
return
33+
34+
env.outbasepath = "modm-test/src/modm-test/platform/i2c_test"
35+
env.copy("i2c_platform_test.hpp")
36+
env.copy("i2c_platform_test.cpp")

0 commit comments

Comments
 (0)