assert() in SDK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

assert() in SDK

1,447 Views
mastupristi
Senior Contributor I

For the i.MX RT105x processor I downloaded the SDKs both in version 2.4.2 and 2.5.0.
In the driver sources (the fsl_* files) the assert() function is used in many points of the code.
I would like to use my own version of the assert() and not the one provided by the standard c library (either newlib nano, or redlib).
What is the correct way to do this?

I don't know if we should edit the fsl_* files. However, I have seen that the file fsl_common.h includes the standard header assert.h.

How "bad practice" is to edit this file to replace the inclusion of assert.h with my own file where I then redefine the assert function in the most convenient way?

best regards

Max

Labels (1)
Tags (2)
0 Kudos
2 Replies

1,210 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Massimiliano Cialdi

As you mentioned, it is not the optimal practice to replace the assert.h from a common file, but if you consider necessary to use your own driver, then yes, you can use this.

Best regards

Jorge Alcala

0 Kudos

1,210 Views
mastupristi
Senior Contributor I

It's also a bad practice to use the assert provided by the libc used (*if* it is used one).

For example newlib provided assert calls printf(), that in turns calls malloc that it is a big problem. In the specific case we do not have heap for the malloc provided by newlib-nano (we use the allocator 4 provided by FreeRTOS). The malloc is very slow and indeterministic about the timing, and also is not thread safe and we should allocate a _reent structure of about 2KB for each task, because it is too much memory consuming. It's also very slow.

In general, I don't think it's a good practice that the HAL driver library (the fsl_*.[ch] files) relies on the library API (see the include list at the top of the fsl_common.h file).

best regards

Max