LWIP debug configuration, cc.h defines

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
inca
Posts: 37
Joined: Mon Apr 22, 2013 12:08 am

LWIP debug configuration, cc.h defines

Post by inca »

Thanks to Mabl for helping me get this file to the next level of usability. The pre-processor "(...)" and "__VA_ARGS__" were just what the doctor ordered for mapping chprintf -> printf input args. This cc.h works flawlessly with many more debug options enabled within lwipopts.h than the newlib or nanolib printf due to less memory usage in chprintf.

This cc.h requires you to declare a global Mutex called "SD1mtx", which you can do in your main file. It also assumes you are using SD1 for the debug console, which is easy enough to tailor to your needs.

cc.h (just the meat):

Code: Select all

#include <ch.h>
#include <inttypes.h>
#include <chprintf.h>
#include <hal.h>

... snip...

extern Mutex SD1mtx;

/* Define (sn)printf formatters for these lwIP types */
#define U16_F PRIu16
#define S16_F PRIu16
#define X16_F PRIx16
#define U32_F PRIu32
#define S32_F PRId32
#define X32_F PRIx32

#define PRINTFREPLACEMENT(...) chprintf((BaseSequentialStream*) &SD1, __VA_ARGS__)

#define LWIP_PLATFORM_DIAG(x) do { while(!chMtxTryLock(&SD1mtx)) {}; \
                              PRINTFREPLACEMENT x; chMtxUnlock(); } while (0)

#define LWIP_PLATFORM_ASSERT(x) do { chprintf((BaseSequentialStream*) &SD1, \
                              "Assertion \"%s\" failed at line %d in %s\n", \
                                x, __LINE__, __FILE__); chSysHalt(); } while(0)
Post Reply