Cyble-212006-01 printf issue

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

cross mob
MaPo_2163411
Level 1
Level 1
First like given

Hello,

it looks simple but didnt work. I want to add printf for debuging.
I used a sample code from a "BLE_Battery_Level" example project.

I have a debug.c file with the following code.

#include <project.h>

#include <stdio.h>

#include "main.h"

/* 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_PutChar(*ptr++);

    }

    return len;

}

And in my main.h the following

#include <project.h>

#include <stdio.h>

#if (DEBUG_UART_ENABLED == ENABLED)

    #define DBG_PRINTF(...)          (printf(__VA_ARGS__))

#else

    #define DBG_PRINTF(...)

#endif /* (DEBUG_UART_ENABLED == ENABLED) */

I cant find any different setting in the project build settings. But it will not work.

Any idea?

Thanks a lot

Max

0 Likes
1 Solution
SrikanthD_56
Employee
Employee
25 sign-ins First question asked First comment on blog

Hi

Hope you are using the UART Component in your design to print Debug messages.

Increase the Heap size to 0x200 (under Design-Wide Resources System tab) and see if that resolves the issue.

if you are trying to print floating-point variables, then in project Build Settings -> Linker set "Use newlib-nano Float Formatting" to True.

View solution in original post

3 Replies
SrikanthD_56
Employee
Employee
25 sign-ins First question asked First comment on blog

Hi

Hope you are using the UART Component in your design to print Debug messages.

Increase the Heap size to 0x200 (under Design-Wide Resources System tab) and see if that resolves the issue.

if you are trying to print floating-point variables, then in project Build Settings -> Linker set "Use newlib-nano Float Formatting" to True.

Great thank you very much!!
It works.

0 Likes
Anonymous
Not applicable

Hi,

Also remember to do this first:

// Disable IO buffering in libc to avoid putchar() bug

// See: https://bugs.launchpad.net/gcc-arm-embedded/+bug/1380268

setvbuf(stdout, NULL, _IONBF, 0);

Regards,

Pieter