Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Better hardware unit tests using simple on-device logic analyzer #96

Merged
merged 5 commits into from
Jul 31, 2020

Conversation

salkinium
Copy link
Member

@salkinium salkinium commented Oct 5, 2018

This adds the generic modm::GpioSampler driver which uses the hardware edge detection features of the Input to generate a EXTI interrupt, which writes the DWT->CYCCNT value into the sample array. The CYCCNT value is truncated to 31-bits and cast into a signed integer, with the sign bit encoding the Gpio::read() value of the edge event (ie. positive is modm::Gpio::High, negative is Low).

This should make it easier to write hwut style tests with the current unittest framework, and most importantly without any external instrumentation.

Note, this approach will not work well on AVRs, since the exti interrupts need to be nested and high-priority to be able to interrupt the HAL interrupt handlers.
This may also not work if the input buffer is disconnected by the Alternate Function (only for Analog mode I believe).

cc @strongly-typed @rleh @chris-durand

@salkinium
Copy link
Member Author

Related: https://blog.janestreet.com/using-ascii-waveforms-to-test-hardware-designs/

@salkinium salkinium force-pushed the feature/hwut-lite branch 2 times, most recently from 45a9d6d to a7d096e Compare July 31, 2020 18:51
@salkinium
Copy link
Member Author

I'm merging this as is, since the GpioSampler won't get any better than this performance and API wise, and while the LogicAnalyzer isn't super useful, it is functional and can already be used to write tests.

@salkinium salkinium merged commit 9ab15d2 into modm-io:develop Jul 31, 2020
@salkinium
Copy link
Member Author

cc @henrikssn this is somewhat related to your SAMD EXTI work, but with a focus on on-device unit testing, ie. having the logic analyzer on the same device as the test.
In my tests the entire interrupt was between 100-150 cycles with two pins, so at 100MHz, you could sample a ~1MHz SPI signal. That's pretty good for no extra hardware (not even external wires).

@salkinium salkinium deleted the feature/hwut-lite branch July 31, 2020 20:27
@salkinium
Copy link
Member Author

The CYCCNT value is truncated to 31-bits and cast into a signed integer, with the sign bit encoding the Gpio::read() value of the edge event (ie. positive is modm::Gpio::High, negative is Low).

I should've probably used the lowest bit for encoding the edge event, since the interrupt latency already masks the lowest 5-7 bits or anyways. A well…

@henrikssn
Copy link
Contributor

Very cool! The only suggestion I have here for API is to support tuple-style getters in the Handler to make it more clear in the unit tests which pin you are asserting on.

TEST_ASSERT_EQUALS(get<Sck>(r).size(), 1u);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants