It's super useful to write and test embedded software without the hardware... but hardware interfaces can be tough.
How do we write code that needs to access hardware, without it?
My best answer is to use a hardware abstraction layer (HAL) to isolate the application from the hardware... and then mock the HAL functions in the unit tests.
In this video you can watch me use Ceedling and CMock to test drive some logic that needs to control the hardware -- through a simple HAL built on-the-fly.
Hmm... although I wasn't necessarily trying to test this example exhaustively, can you spot an important test case that I missed? One that might detect a particular problem with this implementation?
And hey -- using CMock can be a little confusing. It can do a lot more than we looked at in this video.
You can find more examples of how to use CMock in a variety of different situations in my book.