Skip to content

Commit fcb34c8

Browse files
GPIO test bugfixes, implement open drain and pullup/pulldown tests
1 parent 806a592 commit fcb34c8

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

CI-Shield-Tests/DigitalIOTest.cpp

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,56 @@ void DigitalIO_StackAllocated_Test()
6666
TEST_ASSERT_MESSAGE(0 == din,"Expected value to be 0, read value was not zero");
6767
}
6868

69+
// Test of pull up and pull down mode
70+
template <PinName dout_pin, PinName din_pin>
71+
void DigitalIO_PullUpPullDown_Test()
72+
{
73+
DigitalIn dout(dout_pin);
74+
DigitalIn din(din_pin, PullNone); // Make sure no pullup/pulldown is active on this pin as some targets have this by default.
75+
76+
// test 0
77+
dout.mode(PullDown);
78+
wait_us(GPIO_PROPAGATION_TIME);
79+
TEST_ASSERT_MESSAGE(0 == din.read(),"Expected value to be 0, read value was not zero");
80+
81+
// test 1
82+
dout.mode(PullUp);
83+
wait_us(GPIO_PROPAGATION_TIME);
84+
TEST_ASSERT_MESSAGE(1 == din.read(),"Expected value to be 1, read value was not one");
85+
}
86+
87+
// Test that open-drain mode works as expected
88+
template <PinName dout_pin, PinName din_pin>
89+
void DigitalIO_OpenDrain_Test()
90+
{
91+
DigitalInOut openDrain(dout_pin, PIN_OUTPUT, OpenDrain, 1);
92+
DigitalInOut connectedPin(din_pin, PIN_INPUT, PullUp, 0);
93+
94+
// With the open drain pin not outputting anything, we should see both pins reading high
95+
wait_us(GPIO_PROPAGATION_TIME);
96+
TEST_ASSERT_MESSAGE(1 == openDrain.read(), "openDrain was low!");
97+
TEST_ASSERT_MESSAGE(1 == connectedPin.read(), "connectedPin was low!");
98+
99+
// Outputting a low on the open drain pin should bring both pins low
100+
openDrain = 0;
101+
wait_us(GPIO_PROPAGATION_TIME);
102+
TEST_ASSERT_MESSAGE(0 == openDrain.read(), "openDrain was high!");
103+
TEST_ASSERT_MESSAGE(0 == connectedPin.read(), "connectedPin was high!");
104+
105+
// Outputting a high should cause both pins to go high again
106+
openDrain = 1;
107+
wait_us(GPIO_PROPAGATION_TIME);
108+
TEST_ASSERT_MESSAGE(1 == openDrain.read(), "openDrain was low!");
109+
TEST_ASSERT_MESSAGE(1 == connectedPin.read(), "connectedPin was low!");
110+
111+
// If we output a logic low with the other pin, this should be detectable with the open drain pin
112+
connectedPin.output();
113+
connectedPin.write(0);
114+
wait_us(GPIO_PROPAGATION_TIME);
115+
TEST_ASSERT_MESSAGE(0 == openDrain.read(), "openDrain was high!");
116+
TEST_ASSERT_MESSAGE(0 == connectedPin.read(), "connectedPin was high!");
117+
}
118+
69119
utest::v1::status_t test_setup(const size_t number_of_cases) {
70120
// Setup Greentea using a reasonable timeout in seconds
71121
GREENTEA_SETUP(30, "default_auto");
@@ -80,10 +130,12 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
80130

81131
// Test cases
82132
Case cases[] = {
83-
Case("Digital I/O GPOUT_0 -> GPIN_0", DigitalIO_Global_Test<GPOUT_0, GPIN_0, 0>),
84-
Case("Digital I/O GPOUT_1 -> GPIN_1", DigitalIO_Global_Test<GPOUT_1, GPIN_1, 1>),
85-
Case("Digital I/O GPIN_2 -> GPOUT_2", DigitalIO_StackAllocated_Test<PIN_GPOUT_2, PIN_GPIN_2>),
86-
Case("Digital I/O GPOUT_2 -> GPIN_2", DigitalIO_StackAllocated_Test<PIN_GPIN_2, PIN_GPOUT_2>),
133+
Case("Digital I/O GPOUT_0 -> GPIN_0 (Global)", DigitalIO_Global_Test<GPOUT_0, GPIN_0, 0>),
134+
Case("Digital I/O GPOUT_1 -> GPIN_1 (Global)", DigitalIO_Global_Test<GPOUT_1, GPIN_1, 1>),
135+
Case("Digital I/O GPIN_2 -> GPOUT_2 (Stack Allocated)", DigitalIO_StackAllocated_Test<PIN_GPOUT_2, PIN_GPIN_2>),
136+
Case("Digital I/O GPOUT_2 -> GPIN_2 (Stack Allocated)", DigitalIO_StackAllocated_Test<PIN_GPIN_2, PIN_GPOUT_2>),
137+
Case("Digital I/O Pull-Up and Pull-Down Mode", DigitalIO_PullUpPullDown_Test<PIN_GPIN_2, PIN_GPOUT_2>),
138+
Case("Digital I/O Open Drain Mode", DigitalIO_OpenDrain_Test<PIN_GPIN_2, PIN_GPOUT_2>)
87139
};
88140

89141
Specification specification(test_setup, cases, greentea_continue_handlers);

CI-Shield-Tests/InterruptInTest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void InterruptInTest()
4444
callbackCounts = 0;
4545
InterruptIn intin(int_pin);
4646
DigitalOut dout(dout_pin, 0);
47+
wait_us(GPIO_PROPAGATION_TIME);
4748

4849
// Test Rising Edge InterruptIn
4950
DEBUG_PRINTF("***** Rising Edge Test \n");
@@ -174,7 +175,10 @@ Case cases[] = {
174175
Case("Interrupt from GPOUT_2 -> GPIN_2", InterruptInTest<PIN_GPIN_2,PIN_GPOUT_2>,greentea_failure_handler),
175176
Case("Interrupt from GPIN_2 -> GPOUT_2", InterruptInTest<PIN_GPOUT_2,PIN_GPIN_2>,greentea_failure_handler),
176177
Case("Interrupt from GPOUT_1 -> GPIN_1", InterruptInTest<PIN_GPIN_1,PIN_GPOUT_1_PWM>,greentea_failure_handler),
177-
Case("Interrupt from GPIN_1 -> GPOUT_1", InterruptInTest<PIN_GPOUT_1_PWM,PIN_GPIN_1>,greentea_failure_handler),
178+
179+
// Note: Don't do GPIN_1 -> GPOUT_1 because the R-C filter attached to GPOUT_1 plus the resistor between GPOUT_1 and GPIN_1
180+
// can cause the logic level on GPOUT_1 to be between 1 and 0 for a millisecond or more after GPOUT_1 changes state.
181+
178182
Case("Interrupt from GPOUT_0 -> GPIN_0", InterruptInTest<PIN_GPIN_0,PIN_GPOUT_0>,greentea_failure_handler),
179183
Case("Interrupt from GPIN_0 -> GPOUT_0", InterruptInTest<PIN_GPOUT_0,PIN_GPIN_0>,greentea_failure_handler),
180184

CI-Shield-Tests/host_tests/uart_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _callback_verify_repeated_test_string(self, key: str, value: str, timestamp)
5959
if rx_data == expected_rx_data:
6060
self.send_kv('verify_repeated_test_string', 'complete')
6161
else:
62-
self.logger.prn_err(f"Expected '{expected_rx_data}', got '{rx_data}'!")
62+
self.logger.prn_err(f"Expected {expected_rx_data!r}, got {rx_data!r}!")
6363
self.send_kv('verify_repeated_test_string', 'failed')
6464

6565
def _callback_send_test_string(self, key: str, value: str, timestamp):

0 commit comments

Comments
 (0)