assert_param()

The objective of the above function is to check if critical condition is met. If not it would use a standard function to print out where assertion fail. This is very useful.
You can turn the assertion off after thorough testing.

1. Uncomment USE_FULL_ASSERT in stm32f10x_conf.h

/* Uncomment the line below to expanse the "assert_param" macro in the 
   Standard Peripheral Library drivers code */
#define USE_FULL_ASSERT    1

Remember to re-build your project so that this change is seen by all your source files.
After you have thoroughly tested your program, you may comment it again to improve your program efficiency.

2. Implement assert_failed()

void assert_failed(uint8_t* file, uint32_t line) {
      printf("Assert fail at File %s Line %d", file, (int)line);
      while(1);   // hang here (behavior is our your choice)
}

3. Use assert_param() and when it fails

When you want to ensure that a condition is true, put the desired condition as input parameter to assert_param(). E.g.

assert_param(uInitialized[uid] == UINITCODE);

If it is evaluated to be false assert_failed() would be called. In our codes above it gives a message as below.

Assert fail at File ../lib2src/libsiuart.c Line 250

You can go to the file and look up line 250 to see where exactly the assertion fail.

4. Turn it off after thorough testing

In the above example, the program hang when assertion fails.
After you have thoroughly tested your program, you may want to turn this feature off.

This would also improve your program efficiency in term of code size (as the assertion is not implemented) and speed.

Related Posts