[sdiy] Resources on embedded programming good practices?

sleepy_dog at gmx.de sleepy_dog at gmx.de
Tue Apr 21 21:38:27 CEST 2020


*if* you want to do C++, here are some pointers:
https://www.artima.com/shop/effective_cpp_in_an_embedded_environment

I once found those presentation slides freely downloadable somewhere,
and it didn't seem fishy... (maybe this offer is fishy, or terms changed)
perhaps you might, too.
(Scott Meyers... knows C++)


If you want to "make stuff", soon, and you learned C, 10 years ago, and
will almost exclusively program things for STM32 and similar,
then perhaps you might want to try a while gaining/refreshing some
experience with C programming first, though.

C++ always was a complex beast with lots of opportunities, even subtle
ones, to really dig yourself into the dirt.
But this hasn't exactly improved, in that regard, in recent years. The
amount of stuff you need to understand, and think about next to your
actual task at hand, to get anything done is not small - especially if
one of your aims is to do it "properly".
While some of C++ newer versions' aspects can also help for embedded
development (off the top of my mind, you can do complex stuff at compile
time more easily, elegantly, understandably - and what's done at compile
time doesn't need to be done at run-time),
I'd say the majority of additions help make C++ more competitive with
newer, higher level languages to do stuff on embedded platforms.

There are some nice things about even the "procedural" subset of C++
doing things differently that C in some ways that annoy be about C.
Then again, in C99 and C11 has some things that make some typical
embedded stuff nicer (look for free documents explaining what C99/11 got
new vs. C89 / ANSI, to get an idea.)
E.g. assigning of const arrays in an explicitly indexed way, or in
similar vein, assigning structs (or arrays of such) qualified with
member names.
So if you want to make const data structures that get put into program
memory, which is usually much more plentiful than RAM on such devices,
you can do so, right in the code, without any external fumblings (or
ugly macro trickery) assign things in a manner that's very readable and
not so likely to be wrong - like it can get if your initialization
depends on the order of something else and must remain in sync with it
during development/maintenance, to avoid making more complex/wasteful
structures that would also prevent this problem.

I will now list some not free resources, i.e. books.
You might be able to get them used and cheaper than the listed prices here.

If you (also) want to use C:

One way to get an idea of how to craft programs which are not an
infinitely intertwined mess is - to keep things *testable*.
Here is one book that demonstrates how to do that in C.
Although it promotes the "write tests first, then the implementation"
way, which weirds out some people - nobody forces you to do that. May
still be interesting.
https://www.amazon.com/Driven-Development-Embedded-Pragmatic-Programmers-ebook/dp/B01D3TWF5M


A more general classic:
https://www.amazon.com/Code-Complete-Developer-Best-Practices-ebook/dp/B00JDMPOSY


This might be useful if you're not very experienced. Just in case.
https://www.amazon.com/Debug-Repair-Prevent-Pragmatic-Programmers/dp/193435628X


----------
I saw this while looking for the links - don't know this one, but
ratings look good?
(note that libopencm3 has GPL license, IIRC, in case that matters)
https://www.amazon.com/Beginning-STM32-Developing-FreeRTOS-libopencm3-ebook/dp/B07DGGHZN6


- Steve


Spiros Makris wrote:
> Hello list,
> I  want to improve my coding habits so that my results will stay
> maintainable and easy to mod/reuse in the future. The scope of my
> applications (thus far) is sequencing and other similar low frequency
> control/real time devices. I use the arduino platform a lot for it's
> incredible simplicity and driver availability (I love you Teensy) but
> I'm trying to transition to STM32 eventually, seeing it as a more
> "serious" and professional platform. In both cases I use C/C++.
> I was officially taught C while studying in the university but that
> was 10 years ago and I've only picked up programming again in the past
> two or three. I understand digital hardware and the core C concepts,
> however, I don't have the opportunity to work alongside an experienced
> colleague to learn how I should write my code to be up to "industry
> standards" (= not be an unmaintainable mess etc) and I'm looking for
> something to refer to, other than my own trial and error.
> Example topics include anything from structuring headers to using
> globals or structuring function calls- especially under the prism of
> embedded applications. I would appreciate any suggestions on online
> resources or books.
>
> Regards,
> Spiros
>
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at synth-diy.org
> http://synth-diy.org/mailman/listinfo/synth-diy


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20200421/ed990e27/attachment.htm>


More information about the Synth-diy mailing list