Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A How do I test firmware code for my embedded system that also controls hardware peripherals?

The first thing to do is to create a test program on the PC. Actually, that should have been created along with implementation of the command set in the microcontroller. My usual workflow is to s...

posted 1mo ago by Olin Lathrop‭

Answer
#1: Initial revision by user avatar Olin Lathrop‭ · 2026-08-13T23:59:31Z (about 1 month ago)
The first thing to do is to create a test program on the PC.  Actually, that should have been created along with implementation of the command set in the microcontroller.

My usual workflow is to set up the command processor in the micro, create a template test program on the PC, and start the firmware doc file.  Then to add each new command:<ol>

<li>Think out the command, then add its description (which includes the protocol) to the firmware doc file.  This then becomes the reference for what the command should do and what the interface at each end of the communication line should look like.

<li>Add the command to the list of commands, with opcode, to the firmware.

<li>Add the command routine to the firmware, and of course any supporting facilities it may need in the firmware.

<li>Build the firmware, which also creates the include file of command and response opcode mnemonics in whatever language you are using for the PC test program.

<li>Add a suitable command to the PC test program.  Note that commands the user enters into the test program are distinct from the binary commands the PC sends to the micro.  In your case, I might add two commands to the test program called ON and OFF.  Each would be followed by a number for the particular relay to be switched on or off.  When the test program gets these commands, it emits whatever commands are required to the micro to get it to perform the specified action.

<li>Carefully test the remote system by controlling it from the test program, making sure what you expect to happen actually happens.  Try to break it.  Try all the corner cases you can think of.  Send it out of range values.  Make sure everything is handled correctly.

</ol>

Having a test program that can cause specific commands to be sent to the micro is also very useful in debugging.  You can set a breakpoint in the firmware at the command in question, then see why it doesn't get executed properly.  Set the breakpoint after the command routine has gotten all parameters from the UART, but before it does anything with that data.  Once you single step, the UART won't work anymore.

My test programs are basically command interpreters.  When run, they prompt the user for a command to enter.  I always have the three commands "?", "HELP", and "Q", at minimum, in addition to commands that cause communication with the firmware.  "?" and "HELP" do the same thing, which is to list the available commands with brief descriptions, one line each.  "Q" quits the test program.