Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Regarding the problem of strings in embedded, I once did a pretty nifty thing in a logging framework I built for an embedded system in an elevator (Cortex M0 I think it was) with very little flash for the binary and for logging. I had a logging macro which took in a string to log together with some arguments (like printf). The macro expanded to add an attribute to the string constant to put it in a special section I created with a linker script. Then in the macro what it actually logged was the memory offset in the section together with the arguments. So that way the log was extremely slim. As an extra bonus, I then stripped the special section with the strings from the binary and had an offline script translate the logged memory offsets and attributes to strings.


Google's embedded library Pigweed [1] industrializes exactly this approach and has some unholy macro nonsense to make the string hashing work in pure C as well.

[1]: https://pigweed.dev/pw_log_tokenized/


Out of curiosity, why would you have to be so efficient in an elevator?

An elevator I imagine costs big $$$, has no lack of power, and plenty room for electronics.


Same reason a top of the line PC tower still has crappy stamped metal frame and crappy injection molded plastic trims.

The main contractor of the elevator unit is a mechanical engineering company, they contract out the control unit to the lowest bidder.


Nope. This was all in house. But we are talking at home lifts for the rich and lazy (and sometimes elderly). And there was quite a bit of electronics in it with processors at each floor, on the control panel and for the motor controller and so on. So the cost added up. But yeah, I agree, some more flash would have been worth it.


Defmt is a rust library that does exactly this. This has become almost a standard in embedded rust.

There is even a c++ client-side implementation: https://github.com/Javier-varez/Postform/

...which uses macros for logging ;)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: