cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with assert_param

litus0801
Associate II
Posted on March 24, 2010 at 20:39

Problem with assert_param

19 REPLIES 19
Tomas DRESLER
Senior II
Posted on May 17, 2011 at 13:44

Change the #ifdef USE_FULL_ASSERT to #ifdef DEBUG, like in good old library 2.0, or simply #define USE_FULL_ASSERT yourself or put USE_FULL_ASSERT in the C/C++ preprocessor macro definitions.

litus0801
Associate II
Posted on May 17, 2011 at 13:44

That was what I did but the error still persist... 

I don't know what more can I do...

I tried defining

DEBUG

instead of

USE_FULL_ASSERT

as you suggested and I also tried to define it in C/C++ compiler macros but no way...

Why you said ''like in good old library 2.0''? 3.2.0 is not a good one?

Thanks for replying edison!

Anyone can suggest something? I'm really lost...

Andrew Neil
Chief II
Posted on May 17, 2011 at 13:44

This is where it pays to understand how the whole preprocessor-compiler-linker process works.

If the Linker is giving you this error, it means that the Compiler has generated calls to assert_param as if it were a function.

This means that your macro definition is not working properly!

To sort out preprocessor problems like this, find out (in the Compiler Manual) how to view the preprocessor output...
litus0801
Associate II
Posted on May 17, 2011 at 13:44

Hi again,

Ok, I did what Neil said and now I can view the preprocessor files (.i). What should I check? How can I know if a macro is working properly?

Thanks!!

Andrew Neil
Chief II
Posted on May 17, 2011 at 13:44

''How can I know if a macro is working properly?''

 

 

You do understand what macros are supposed to do, don't you?

So, if they do that, then we say that they are ''working'' !!

😉

 

 

To recap, a macro is a text substitution - so, instead of seeing ''assert_param'' in the pre-processed text, you should see its expansion.

If you are still seeing ''assert_param'' in the pre-processed text, then the preprocessor has not expanded it; ie, it has not worked as a macro!
litus0801
Associate II
Posted on May 17, 2011 at 13:44

Ooooook!!!

Thanks, Neil. I think I am still a noob on C programming. Ok, now I know what the problem exactly is. I can see

assert_param

in the preprocessor files so that means whant Neil said, the macro ''is not working''. Now the problem is how to fix it. 

I'm going to find whether it is possible to disable/enable macros in EWARM. Maybe is a configuration parameter I forgot... Any other idea?

Thanks again Neil!

Andrew Neil
Chief II
Posted on May 17, 2011 at 13:44

''I think I am still a noob on C programming''

 

 

Note that this is standard 'C' stuff - nothing specifically to do with STM32, IAR, or embedded.

Therefore any 'C' textbook should help...

''I'm going to find whether it is possible to disable/enable macros in EWARM.''

No, that is not the correct approach!

What you need to do is to find out how to correctly configure your Project so that the macro works!

Note that the macro definition is contained within

#ifdef  USE_FULL_ASSERT

This means that the definition is effective only if the symbol USE_FULL_ASSERT is defined...

Andrew Neil
Chief II
Posted on May 17, 2011 at 13:44

Note that there is also a #else which should create a ''null'' definition when USE_FULL_ASSERT is not defined.

The fact that you're getting neither the ''full'' definition nor the ''null'' definition - so that the compiler thinks it's a function call - suggests that you are not actually including this at all...
litus0801
Associate II
Posted on May 17, 2011 at 13:44

What I did now is that:

/* Exported macro ------------------------------------------------------------*/

#ifdef  USE_FULL_ASSERT

  #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))

#error ----------------------------------------------------- assert full def.

/* Exported functions ------------------------------------------------------- */

  void assert_failed(uint8_t* file, uint32_t line);

#else

  #define assert_param(expr) ((void)0)

#error ----------------------------------------------------- assert null def.

#endif /* USE_FULL_ASSERT */

The compiler return first error, so that means that I am including it (maybe I'm wrong?) 

Thaaaaaanks!!