SW Feature - Assert, exceptionhandler, Logging, printf etc

SW Feature - Assert, exceptionhandler, Logging, printf etc

<I have all the code ... just needing to apply this for this site.>

Most of the many system I now work with has more or less one or more of each feature here below. To some extent suppliers has supplied the nessesary features – at least in some limited libraries.

I have build and copiled these in a singe easy to use unit – so you with these modules/functions do not need to have many other lib’s include.

Further more will this system give you the exception handling and logging functionality, which I think you will apprecieate a lot when you start understanding the power and useability on them.

Again – its stuff for the hardcore embedded systems – not those people alreading having a full on-board target and debugger with +100 nice to have features. So hardcore embedded … starting (lmost) from scratch!


What is it?


Assert we all know from the many more advanced systems. Normally assert triggers on a value equal NULL. I have made this assert so you an added this macro at any spot on you code, you can add any check you’d like – and hence get the assert if you trigger-condition is hit.

Nice feature is that you can decide if you want this only to be active when running ‘debug’ mode – or you would like to have it in your release too!

The assert module also contains a very small printf/sprint/esprintf function only handling the few most important printing (processing for the assert’s.  The functions interface makes it possible to handle a variable count of parameters on the input to the function.

Like print/processing:

  • a string,
  • print an integer,
  • printing hex,
  • char,
  • and a few more.


Furthermore it possible to have several output routines, streaming out the printed data. You can route this to a variety of your own implemented output’s  – An uart, an SPI port, into a specified memory part (ring buffer), or ... You only need to add the function for writing a single byte .. that’s it!

void OS_printf_target(void (*f_ptr) (U8_INT chr),   const charptr ctrl_in, ...);


short esp_printf (const func_ptr,  const char *ctrl, ...);




  • Assert is implemented to a true condition gives the assert() ...
    normally traditional asserts is for pointers and these will give an assert if == NULL

  • Generally ASSERTn will print filename, function name and line number ...



Example on usage ...

Example-1: Make an assert ... if pointer size does not match ...

ASSERT (sizeof(unsigned long) >= sizeof(void *), "pointer size problem");


Example-2:    make a assert ... if 'OSReturnErr' is <> zero

ASSERT (OSReturnErr);


Example-3:    make an assert ... if 'var1!=0' .. also print out 'Counter' 

 ASSERT1 ((var1!=0),  Counter);



If assert_on is defined the macro will be realized in the code.

  • ASSERT(A)                    check on A - prints A
  • ASSERT1(A,B)               check on A – print A and B
  • ASSERT1(A,B,C)                        check on A – print A, B and C
  • ASSERT_STR(A,B)          check on A – print as string B
  • ASSERT_PTR(A,B)          check on A – print B as a pointer
  • ILLEGAL_MSG_ID(A)      no check – print “Illegal Msg Id” A
  • ILLEGAL_VALUE(A)         no check – print “Illegal Value” A



The macro is like this ..

So the following on a single line … though here split-up in several to explain …

  1. #define ASSERT(A)
  2. {if ((U8_INT)A)
  3. {OS_printf_target(
  4. &output_char, MSG_PRE_DATA
  5. "Assert:(%s=%d) %s [%d]", #A, (int)(A),
  6. __FILE__, __LINE__);}}


Description on the code here above

1)    The macro definition

2)    The question part – looking at the A parameter
This is only active if compilation/definitions allows this!

3)    Either for target or for os_printf

4)    &output_char is the function pointer pointing at the output driver for printf() to use. Actually functionality used by the OS_printf_target()

5)    This is a custom out text

6)    Print out filename, and line number of the assert.



Exception handler

Article Images: prj_assertexceptionhandling-1.png


Log handler





Other ’features’ combining and increasing the usability on these modules.

  • Pre/Post definitions in printout
    These are typically module name you can apply in your code. Per file, per module .. or as you like …
  • In the code is used - OS_Printf which is mapped to one of the following:
    • OS_printf_target is for printing when running on your target
    • Printf as normally (on your PC, or if you have this in your target)


No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Articles Panel

  Article Posted By Date Reads
System-Of-Systems Ingineering
Process & Methods
31-10-2017 23:03488
IoT Start up
25-10-2017 10:25588
Unittesting - CPPUNIT
24-10-2017 20:26483
Things on the radar
24-10-2017 20:06547
WCET - Worst Case Execution Timings Calculator
28-06-2015 19:2914679
16-03-2015 18:222690
NuttX - Step-By-Step
30-12-2013 17:187578
Tools used
27-10-2013 12:134043
List of my robots
My robots
19-07-2013 08:443645
JoKaBot - Home build from scratch
My robots
19-07-2013 08:047044
C-Sharp (references and projects)
18-07-2013 19:194178
Home communications
18-07-2013 18:234312
Various links
My Collection
17-07-2013 09:048324
ARM - ARM7/9/11 + Cortex
17-07-2013 08:494257
17-07-2013 08:414474

Total Articles: 58 :: Total Article Categories: 16


My Collection (1) My robots (2)
Oldies (5)
Old Projects - very old
Process & Methods (8)
Projects (12) Robotics (1)
Technology (7) Testing (1)
Tools (14) Working on ... (7)
Projects Im currently working on
Render time: 0.04 seconds
874,022 unique visits