DBG_PRINTF macro

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.
ViTi_1549261
Level 3
Level 3
First like received

Hello,

   

I am trying to make DBF_PRINTF macro working on my own project. This macro seems to be used in multiple example projects but I can't figure out all details how to make it working.

   

Attached is my example project. If someone could see what is missing. It should print "Hello World!" from uart but it is printing nothing and program execution seem to hang on this line:

   

DBG_PRINTF("Hello World!\r\n");

0 Likes
1 Solution
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Common.h is missing in your program.  This is missing /***************************************
* Conditional Compilation Parameters
***************************************/
#define DEBUG_UART_ENABLED          ENABLED

   

This is missing

   

/***************************************
*        Macros
***************************************/
#if (DEBUG_UART_ENABLED == ENABLED)
    #define DBG_PRINTF(...)          (printf(__VA_ARGS__))
#else
    #define DBG_PRINTF(...)
#endif /* (DEBUG_UART_ENABLED == ENABLED) */

   

and this

   

#if (DEBUG_UART_ENABLED == ENABLED)

   

and this /* For GCC compiler revise _write() function for printf functionality */
int _write(int file, char *ptr, int len)
{
    int i;
    file = file;
    for (i = 0; i < len; i++)
    {
        UART_DEB_UartPutChar(*ptr++);
    }
    return len;
}

   

and this

   

#endif /* DEBUG_UART_ENABLED == ENABLED */

   


void ShowValue(CYBLE_GATT_VALUE_T *value)
{
    int16 i;
    
    for(i = 0; i < value->len; i++)
    {
        DBG_PRINTF("%2.2x ", value->val);
    }
    DBG_PRINTF("\r\n");
} there is probably other but I would take this program and then add your program in  it.

View solution in original post

0 Likes
21 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I fixed some issues in your program and I am sending it back to you.  I am not sure why you are debugging it the way you are.

0 Likes
ViTi_1549261
Level 3
Level 3
First like received

Hi Bobgoar,

   

 

   

Your fixes did not change the behavior of application. It is still printing nothing.

   

Reason why I would like to have like to have this is to simplify printing own text and variable values on same strings.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Can I ask why you are not using Cysmart to debug the program?  It works very well and you can read out all the variables with it.

0 Likes
ViTi_1549261
Level 3
Level 3
First like received

I use sometimes PSOC creator and Cysmart for debugging, but sometimes I would like to run application at full speed and see what is happening by looking a debug prints.

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Look at the program I am sending you it works with debug and is producing data on the debug channel.  Looking at this program and your program there appears to be a few parts missing like debug start ect.

0 Likes
ViTi_1549261
Level 3
Level 3
First like received

I know this technique is used in many examples, but despite of hard trying I haven't get it working on my application. If I look the source code files, it seems that I have all needed blocks.

   

I understand that it should work like this:

   

-fucntion "int _write(int file, char *ptr, int len)" should eventually write the data to debug channel, but is never called explicitly on any soucre. 

   

#define DBG_PRINTF(...)          (printf(__VA_ARGS__))      taking input parameter from DBG_PRINTF and if needed split it to formatting string + parameters for printf

   

-Then content of "printf" should be passed to "int _write(int file, char *ptr, int len)" Should I define this in some other place than source code? Looking the source codes of multiple example project looks like this linking is done automatically or defined elsewhere.

   

 

   

If you see some parts missing on my code, could you tell exactly what it is. I cannot see the missing parts.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received
        Compare the program I just sent you and,make your program just like it . For example your program is missing a .h file another issue your program is using the USB Dongle instead of the Pioneer Ble board and a psoc ble plug in . The example I sent uses the PSOC Ble module. The dongle is for the Cysmart connection with out using a phone.   
0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Common.h is missing in your program.  This is missing /***************************************
* Conditional Compilation Parameters
***************************************/
#define DEBUG_UART_ENABLED          ENABLED

   

This is missing

   

/***************************************
*        Macros
***************************************/
#if (DEBUG_UART_ENABLED == ENABLED)
    #define DBG_PRINTF(...)          (printf(__VA_ARGS__))
#else
    #define DBG_PRINTF(...)
#endif /* (DEBUG_UART_ENABLED == ENABLED) */

   

and this

   

#if (DEBUG_UART_ENABLED == ENABLED)

   

and this /* For GCC compiler revise _write() function for printf functionality */
int _write(int file, char *ptr, int len)
{
    int i;
    file = file;
    for (i = 0; i < len; i++)
    {
        UART_DEB_UartPutChar(*ptr++);
    }
    return len;
}

   

and this

   

#endif /* DEBUG_UART_ENABLED == ENABLED */

   


void ShowValue(CYBLE_GATT_VALUE_T *value)
{
    int16 i;
    
    for(i = 0; i < value->len; i++)
    {
        DBG_PRINTF("%2.2x ", value->val);
    }
    DBG_PRINTF("\r\n");
} there is probably other but I would take this program and then add your program in  it.

0 Likes
lock attach
Attachments are accessible only for community members.
ViTi_1549261
Level 3
Level 3
First like received

I use sometimes BLE dongle as my development environment if Pioneer board is attached to some other development kits. I do not see any issue there if I just configure IOs correctly.

   

And there was nothing relevant missing on the my codes. Of course I remove header files that are not anyhow related to issue, to make my point clear. Problem seems to be something that is not visible on source codes.

   

Attached two project are identical from source code point of view. Other prints debug messages correctly other does not print anything. The working one is made by shrinking some example codes containing DBG_PRINTF. Then the non-working one is started from scratch and all source code is copy pasted from working one.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Check the heap size, it is different between the projects.

   

 

   

Bob

lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I changed the heap size to 0x400 and your original program is working. Bob was right on the heap size.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

the program that doesn't work has a heap size of 080 and the one that works is 0400. So it is the heap size that is the issue,

0 Likes
ViTi_1549261
Level 3
Level 3
First like received

Hello Bobsies,

   

 

   

Chancing the heap size really seems to solve the problem. Why is it so? Is there a way to easily detect correct amount of heap and stack memory for my application?

0 Likes
Anonymous
Not applicable

I also met the same problem,thank you very much!!!

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

printf() needs some memory temporarily and allocates it using the standard methods as sbrk() man / or malloc().

   

The question is not "How big should be the heap", but "How big to set the stack". The room for global and static vars is reserved automatically, the heap should be set as required (more or less a guess) and the rest? You cannot do anything with the remaining sram but use it as the heap.

   

 

   

Bob

0 Likes
JeSy_1305731
Level 4
Level 4
First like received

just wondering if this was resolved, I now have the same issue.  I think I coppied, all the source files and code properly, I do a Uart_Start() at the begining of the main program to initialize the uart and when I do a printf, the program hangs as it appears to be missing something, but the compiler gives me no errors,  this is a very basic thing that should work, it is the most common debugging procedure ever used, run a uart out somewhere to do printf statements to check the status of your program, like status and state machine conditions.  where the BLE dongle and Cysmart are of no use.  meaning the problem is not with BLE but in your actual application not in bluetooth communications.   At this point in time it is unclear if there is a tool generated file missing, or some kind of manual code missing.   Is there a basic App Note for how this works?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Post your project with the uart not-working and please mention which development kit you use, I'll check it.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am facing similar problem . When  i am trying to print the statement using  

   

  UART_DEB_UartPutString("TEST"); 

   

I can see  " TEST" in my tera terminal .

   

DBG_PRINTF("TEST \r\n");

   

 

   

I cannot see anything in the terminal and program counter goes to 

   

CY_ISR(IntDefaultHandler)
{
    /***************************************************************************
    * We must not get here. If we do, a serious problem occurs, so go into
    * an infinite loop.
    ***************************************************************************/

   

    #ifdef CY_BOOT_INT_DEFAULT_HANDLER_EXCEPTION_ENTRY_CALLBACK
        CyBoot_IntDefaultHandler_Exception_EntryCallback();
    #endif /* CY_BOOT_INT_DEFAULT_HANDLER_EXCEPTION_ENTRY_CALLBACK */

   

    while(1)
    {

   

    }
}

   

 

   

 

   

Can U please let me what to do 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum.

   

I always use a combination of sprintf() and putstring. in your case it would be

   

char Buffer[50];

   

sprintf(Buffer,"Test\r\n");

   

UART_DEB_UartPutString(Buffer);

   

 

   

When printing float values, do not forget to allow for newlib nano float formatting (in project options) and setting the heap size to 0x0200 (in .cydwr view, system tab)

   

 

   

Bob

0 Likes
Anonymous
Not applicable

This solved my problem too... Thank you..

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Narayan!

   

Happy coding.

   

 

   

Bob

0 Likes