Asserts in MQX/CW10

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

Asserts in MQX/CW10

2,558 Views
mykepredko
Contributor IV
I want to implement Asserts in my code and and I'm following the guidelines in the "CodeWarrior Development Tools EWL C Reference" to implement them, namely:
 
#define NDEBUG
#include <assert.h>
 
int i = 7;
 
    assert(7 != i);
 
and execution does stop, but I don't get an assert message sent through the serial port (UART0).   I'm running on an M52223EVB. 
 
Any ideas?  I would just like to get a message because otherwise the software just stops (which is correct but not very helpful). 
 
Thanx,
 
myke
0 Kudos
Reply
8 Replies

1,138 Views
amithergass
Contributor I

Hi David,

I am currently working with MK60DN512 micro under CodeWarrior 10.6 and GNU compiler. I am not using the stdlib and hence getting the error :

DescriptionResourcePathLocationType
ARM_GCC_Support/ewl/EWL_C/src/stdio/printf.c undefined reference to `__pformatter'marble_Tacho5_k60n512line 44C/C++ Problem

To be able to compile my code I used your solution that requires changing and recompiling the EWL, the solution got it to work, thanks.

My question is, is it possible to redefine the assert locally in a way that will leave the EWL as it is now and will allow the code to be compiled on other machine without having to compile the EWL.

I tried to undefine and redefine the assert in user_config.h but still getting the error.

Thanks.

0 Kudos
Reply

1,138 Views
mykepredko
Contributor IV

Ooops.  I copied down the code incorrectly.  The "#define NDEBUG" should be "#undef NDEBUG" and the code is:

 

#undef NDEBUG
#include <assert.h>
 
int i = 7;
 
    assert(7 != i);
 

The same problem exists, execution halts but I don't get a message out telling me where the Assert took place and what are the conditions. 

 

Thanx,

 

myke

0 Kudos
Reply

1,138 Views
DavidS
NXP Employee
NXP Employee

Hi Myke,

I tried the assert() with CW7.2.1, FSLMQX3.6, and M52259EVB, and it too did not work.  I dug into source and have a workaround and will also mention this to our FSLMQX development team.

The assert() is part of the EWL library in the CodeWarrior path.  At some point it calls a printf() but instead of calling the FSLMQX printf() it calls the EWL printf().  I had to modify a couple EWL "C" source files and re-compile the library.

 

Here are the modifications and steps I made:

- open CodeWarrior for ColdFire V7.2\ColdFire_Support\ewl\EWL_C\EWL_C.CF.mcp

 

- open ansi_prefix.CF.h (NOTE: not certain this change needed) and change as follows:

#ifndef _EWL_ASSERT_DISPLAYS_FUNC
//DES #define _EWL_ASSERT_DISPLAYS_FUNC  0 // Assert will not display function name, non-c99 behavior (7.2.1.1)
 #define _EWL_ASSERT_DISPLAYS_FUNC  1 //DES was 0 // Assert will not display function name, non-c99 behavior (7.2.1.1)
#endif

 

- open assert.c and change as follows:

extern int _io_printf(const char * , ... );  //DES

MISRA_QUIET(715, "ununsed arg")
void __ewl_assertion_failed(char_t const *condition, char_t const *filename, char_t const *funcname, int_t lineno)
{
#if !_EWL_ASSERT_DISPLAYS_FUNC
#pragma unused(funcname)
#endif
#if _EWL_OS_DISK_FILE_SUPPORT
 #if _EWL_ASSERT_DISPLAYS_FUNC
  (void)fprintf(stderr, "Assertion (%s) failed in \"%s\", function \"%s\", line %d\n", condition, filename, funcname, lineno);
 #else
  (void)fprintf(stderr, "Assertion (%s) failed in \"%s\", line %d\n", condition, filename, lineno);
 #endif
#elif (_EWL_CONSOLE_SUPPORT)
  #if _EWL_ASSERT_DISPLAYS_FUNC
   (void)_io_printf("Assertion (%s) failed in \"%s\", function \"%s\", line %d\n", condition, filename, funcname, lineno);
//DES   (void)printf("Assertion (%s) failed in \"%s\", function \"%s\", line %d\n", condition, filename, funcname, lineno);
  #else
   (void)printf("Assertion (%s) failed in \"%s\", line %d\n", condition, filename, lineno);
 #endif
 #else
 #pragma unused(condition, filename, funcname, lineno)
 /* Use some other form of assertion since there is no disk or console I/O */
#endif

 

- Now build/make the Build All target to update the EWL library

- I used the ~mqx/examples/hello project as a file to add your code.  I got an error during build and had to change the target configuration dialog box Linker->Librarian fields as follows:

Print and Scan formatter from "in_FP" to "int" and Console IO from "buffer" to"raw".

- Now re-build your project and run .

 

Regards,

David

PS

I've added the source files in a ZIP if you don't want to cut&paste.

 

PSS

Please note that these mods to make assert() work with FSLMQX make it not work for non-FSLMQX (raw) applications.  So what I've done is a workaround for FSLMQX only and I'm sure our FSLMQX and CodeWarrior developers will have proper long-term solution.

 

0 Kudos
Reply

1,138 Views
mykepredko
Contributor IV

Hi David,

 

Thank you for the reply.  Unfortunately, I don't seem to be able to find the "assert.c" that is referenced.  I'm running CW10 (you referenced 7.2) and I was able to find "ansi_prefix.CF.h" and I can compare your changes to the original and they make sense. 

 

Unfortunately, I can't find an "assert.c" (there are four) that matches the one that you started with and I can't find EWL_C.CF.mcp - although I can find C:\Program Files\Freescale\CW MCU v10.0\MCU\ColdFire_Support\ewl\EWL_C which seems to be the correct one BUT the assert.c file in this folder has a different date in the comments (2010/03/26 13:38:00) than the file you seemed to start with (2009/12/21 12:33::27) and the contents are really quite a bit different. 

 

This is surprising to me as I would have thought the EWL C tools would be identical to the two versions of CW. 

 

Sorry for being a pain - do you have any ideas as to what I should look for next? 

 

Thanx,

 

myke

0 Kudos
Reply

1,138 Views
DavidS
NXP Employee
NXP Employee

Hi Myke,

Sorry for the delay....I had to inquire to many people to ultimately find that we do not have a simple CW10 project to aid in the re-building process.  Good news is it is now on the to-do list for the CodeWarrior team.

For CW10 I had to install Cygwin on my PC and modify EWL make files to enable a manual re-build of the EWL Libraries.
I have both workarounds included in the attached ZIP.

Regards,

David

0 Kudos
Reply

1,138 Views
mykepredko
Contributor IV

Hi David,

 

Thank you for providing the information.  A quick comment for others that are trying this and a couple of questions regarding the file (before I "clean" and then rebuild "all"). 

 

You should put the Cygwin path in double quotes to get the correct folder which has spaces in the label, ie:

cd "/cygdrive/c/Program Files/Freescale/CW MCU v10.0/MCU/ColdFire_Support/ewl"

 

Questions:

1.  There are a number of make files in the "AssertIssueCW10Workaround" zip file which end in .CF and do not have the full extensions of .CF.mak.  I can find matching .CF.mak files - when copying them over, should I add the ".mak" to the extension? 

2.  When I look at "makefile" in the ".../ewl" folder, it looks like the target processor ("CF" in our case) should be included in the make statement? 

3.  Is there a list of folders for copying in your files into?  The reason why I'm asking is because the "assert.c" in C:\Program Files\Freescale\CW MCU v10.0\MCU\ColdFire_Support\ewl\EWL_C\src is substantially different from the assert.c in the CW10 .zip file. 

 

Sorry for all the questions, I just want to make sure that I can get this to go smoothly - your instructions were very clear to getting to this point, I just want to make sure I nail it first time.

 

Thanx,

 

myke

0 Kudos
Reply

1,138 Views
DavidS
NXP Employee
NXP Employee

Hi Myke,

Sorry that the file extensions were not preserved fully.  I did work on one machine and copied to another and then zipped. 

 

A1) The ".mak" should be added and they should be place in the respective EWL_C/EWL_C++/EWL_Runtime and EWL_Runtime/Runtime_ColdFire/Projects.

 

A2) The CF is defined in the make files that needs them.

 

A3) When I search the ewl folder structure I only get one assert.c file in ~/ewl/EWL_C/src

 

CW10 production release just came out...maybe you should upgrade to it.  Here is info for it:

The production release of CodeWarrior for Microcontrollers v10.0 is now available! The Special Edition and Professional Evaluation Edition are available for download at www.freescale.com/cwmcu10.

 

Lastly...before I tried to do make clean and make all, I made a backup copy of the ~ewl/lib folder just so I would have a restore point.  Having done this I didn't then have a problem...but if I hadn't I'm sure I would have :smileywink:

Regards,

David

0 Kudos
Reply

1,138 Views
mykepredko
Contributor IV

Hi David,

 

Well, a step forwards but the make command doesn't seem to work. 

 

A couple of things:

 

1.  The assert.c that you have modified has a different date code than the one that comes with the system.  The one that you are using has a date code of 2009/12/21 whereas the assert.c that comes with CW has a date code of 2010/03/26. 

 

Because of this, I decided to modify the version of the code that comes with CW (and this is the attached zip file).  I've called it "assert.myke.c" to make sure it doesn't get confused.  Could you please review and let me know if I made the changes correctly (look for "//DES & MAP")? 

 

2.  When I attempt to perform the make in cygwin, I get the response below:

 

Myke@Myke-Laptop /cygdrive/c/Program Files/Freescale/CW MCU v10.0/MCU/Coldfire_Support/ewl
$ make -f makefile clean
make -f EWL_C..mak -C EWL_C clean
make[1]: Entering directory `/cygdrive/c/Program Files/Freescale/CW MCU v10.0/MCU/Coldfire_Support/ewl/EWL_C'
make[1]: EWL_C..mak: No such file or directory
make[1]: *** No rule to make target `EWL_C..mak'.  Stop.
make[1]: Leaving directory `/cygdrive/c/Program Files/Freescale/CW MCU v10.0/MCU/Coldfire_Support/ewl/EWL_C'
make: *** [clean] Error 2

 

It looks like to me (with the EWL_C..mak) that the CF specification is not getting included - I have copied the files that you sent (and was able to find a single location for each one) so I am wondering if I have missed something. 

 

I did create a backup folder of ewl and everything in it. 

 

Thanx and sorry for being a pain,

 

myke

 

 

0 Kudos
Reply