WICED Sense debug with UART

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Yes, you can debug with UART !

Several people have asked: "Can I have debug trace?" "Can I use anything for debug?" For instance: "Can I use UART LOG and my messages for debug?" on WICED Sense - YES, you can !

Two lines of code and it works !

WICEDSense_UART_Debug.jpg

What to do?:

  • Add to your WICED Sense FW such code:

void wiced_sense_connection_up(void)

{

    //initialize the UART: here just when connection is established

    puart_init();

    puart_print("WICED: Connected\r\n");


  • Open TeraTerm (or any other UART terminal on PC, WICED Sense connected via USB to it, using VCP (find devices on Windows Device Manager, e.g. which COM port is assigned for the terminal program later):
    Baudrate: 115200, 8 bit, no Parity, no Flow Control, 1 Stop bit
    Make sure, the TeraTerm is just started if USB connection is there and remains there and not interrupted. If a new power cycle, USB was down in between - you have to restart TeraTerm.

What to know?:

  • The puart_print() does NOT translate "\n" into "\r\n" on UART. You have to code strings as "something\r\n".
  • When you will configure UART (e.g on wiced_sense_connection_up() ) - it is up to you. I do not know when MCU is on, UART init persistent or lost (see more questions below). I have assumed: if connection is established - MCU remains on (see also below).
    If UART is initialized, e.g. in startup - no idea what happens: it might be that MCU goes to Deep Sleep and UART is lost when back.
  • And: if you have rebooted device, e.g. battery removed - you must close and restart TeraTerm: a lost connection is not realized on TeraTerm. Maybe you have to be a bit quick: when LED is On on  \WICED Sense: start TeraTerm, establish connection, see the message. But then it should be fine. I guess: if WICED Sense goes to sleep but you have not yet established connection and UART does not work - start over.

How to use?:

I have attached here my "wiced_sense.c" file which uses this feature. UART is enabled on "connection_up". I use a static variable to make sure the UART is not used if not initialized.

And: you and me, we want to print also variables, values, like a regular printf. Here it is - define a macro which you will use in your code:

static int sUARTInitialized = 0;        //UART will be initialized on BLE connection established

//define a macro for a debug print similar function

static char sUARTBuf[80];               //a buffer for the UART output, used by Tprintf

#define Tprintf(fmt, ...)               do { \

                                            if (sUARTInitialized) { \

                                                sprintf(sUARTBuf, fmt, __VA_ARGS__): \

                                                puart_print(sUARTBuf); \

                                            } \

                                        } while (0);


Please, do no forget to set sUARTInitiazed when init was done.

So, later in your code you can use:

puart_print("WICED: Connected\r\n");  //use directly, as simple string

or:

Tprintf("WICED: Disconnected\r\n", 0);  //OK, a bit strange, see below why do we need a parameter


You can print simple strings, you can print strings with variable content etc., like a regular printf.


Remarks

  • The dummy parameter is needed on Tprintf in case just a formant string w/o any parameter needed:
    The WICED Sense SDK does NOT use the latest GNU ARM compiler. It has a bug or does not support really the C99 language version. Even __VA_ARGS__ on macro seems to work - I have never seen this problem (using without the ", 0" -  you will get a compiler error).
  • Bear in mind that puart_print() does not translate "\n" into "\r\n" (not as a regular C-string processed): add "\r" to all your strings.
0 Likes
1 Solution

Here's a good thread which discusses why the traces were encoded in ROM: Re: How do I interpret the extra tracing data ?

This thread addresses the ability to disable traces: Disabling BLE trace in patches

View solution in original post

3 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

The modification of the state on the HCI UART Rx was required to enable traces (as pointed out in the Quick Start Guide).

0 Likes
Anonymous
Not applicable

Trace is a different issue: yes, I assume the debug trace there will be based on an encoded protocol.
But I use just as a simple terminal, ASCII mode here.

Works for me. Just to use external TeraTerm, not the Eclipse integrated trace tool.

0 Likes

Here's a good thread which discusses why the traces were encoded in ROM: Re: How do I interpret the extra tracing data ?

This thread addresses the ability to disable traces: Disabling BLE trace in patches