snprintf error (PIC32MZ2048EFM064)

Hello, When I use this code (before to create tasks): ~~~ char dgbbuf[30]; snprintf(dgbbuf, sizeof(dgbbuf), “%u”, 123); printf(“dgbbuf1 : %srn”, dgbbuf); snprintf(dgbbuf, sizeof(dgbbuf), “%f”, 1.23); printf(“dgbbuf2 : %srn”, dgbbuf); snprintf(dgbbuf, sizeof(dgbbuf), “%s”, “yolo”); printf(“dgbbuf3 : %srn”, dgbbuf); printf(“dgbbuf1b : %urn”, 123); printf(“dgb_buf2b : %frn”, 1.23); ~~~ It is displayed :
dgbbuf1 : dgbbuf2 : dgbbuf3 : yolo dgbbuf1b : 123 dgb_buf2b : 1.230000
How can I do to resolve this problem ? I use FreeRTOS V10.1.1 and XC32 compileur v2.10 with the FreeRTOS PIC32MZ demo project. I use this configuration : ~~~ #pragma config FMIIEN = OFF, FETHIO = ON, PGL1WAY = ON, PMDL1WAY = ON, IOL1WAY = ON, FUSBIDIO = OFF #pragma config FNOSC = SPLL, FSOSCEN = OFF, IESO = OFF, POSCMOD = OFF #pragma config OSCIOFNC = OFF, FCKSM = CSECME, FWDTEN = OFF, FDMTEN = OFF #pragma config DMTINTV = WIN127128, WDTSPGM = STOP, WINDIS = NORMAL #pragma config WDTPS = PS1048576, FWDTWINSZ = WINSZ25, DMTCNT = DMT31 #pragma config FPLLIDIV = DIV1, FPLLRNG = RANGE510MHZ, FPLLICLK = PLLFRC #pragma config FPLLMULT = MUL50, FPLLODIV = DIV2, UPLLFSEL = FREQ24MHZ #pragma config EJTAGBEN = NORMAL, DBGPER = PGALL, FSLEEP = OFF, FECCCON = OFFUNLOCKED #pragma config BOOTISA = MIPS32, TRCEN = OFF, ICESEL = ICSPGx1, JTAGEN = OFF
//#pragma config DEBUG = ON
#pragma config CP = OFF  

#pragma config USERID = 0xFFFF
#pragma config SMCLR = MCLR_NORM
#pragma config SOSCGAIN = GAIN_2X
#pragma config SOSCBOOST = ON
#pragma config POSCGAIN = GAIN_2X
#pragma config POSCBOOST = ON ~~~

snprintf error (PIC32MZ2048EFM064)

Also, I change heap siaze (0 -> 20000) and min stack size (0 -> 10000) : I have the same problem

snprintf error (PIC32MZ2048EFM064)

This is a forum for FreeRTOS. What makes you think that this problem is related to FreeRTOS? The function snprintf() is normally provided by the compiler makers, unless you’re using one of the variants of printf-stdarg.c. That module would overwrite the sprintf() functions with a version that is simpler and less stack-hungry.

snprintf error (PIC32MZ2048EFM064)

When I use snprintf() in a new project without FreeRTOS, this function operates. Perhaps problem come from configuration of the FreeRTOS PIC32MZ demo project ? I don’t have a printf-stdarg.c file in my project

snprintf error (PIC32MZ2048EFM064)

…. I don’t understand why printf operates but not sprintf and snprintf (with and without legacy libc)

snprintf error (PIC32MZ2048EFM064)

I’d suggest you ask this question on the microchip forums, either the PIC32 or Harmony. I agree with Tibosch that this isn’t a FreeRTOS related issue, and you will get much better response there.

snprintf error (PIC32MZ2048EFM064)

ok I thank you

snprintf error (PIC32MZ2048EFM064)

For the moment, nobody in microchip forum find a solution : https://www.microchip.com/forums/m1073229.aspx After some tests, problem appears only when project integrate FreeRTOS : it isn’t a problem of project configuration. If I don’t create task, I have the problem.

snprintf error (PIC32MZ2048EFM064)

Sorry for delay – somehow missed the email notification of your post. Can you check that your stack is 8-byte aligned. You can do that by putting break point on the call to the print formatting function and checking the stack pointer value in the debugger. If it is not 8-byte aligned then try placing a break point on the opening bracket of a function that implements a task entry point to see if it is aligned there.

snprintf error (PIC32MZ2048EFM064)

Hello, Me too, I missed notification. When I set a break point to snprintf call, PC = 0x9D00CDDC

snprintf error (PIC32MZ2048EFM064)

Most likely the problem is FreeRTOS is using dynamic memory allocator and it’s clashing with the standard memory allocator. Usually the C memory system positions the heap based on something like a marker in the linker file like _end. It’s likely your FreeRTOS allocator is using the same or an overlapping marker. It is quite normal in many implementations for Printf , snprintf and all the variants to malloc a small buffer. Option 1: Find out what in the linker file is used to mark the heap in both systems and then change it in FreeRTOS and make the allocators avoid each other. Option2: Make FreeRTOS use the C system malloc functions.

snprintf error (PIC32MZ2048EFM064)

Option 1: I don’t have a custom linker file Option 2 : There are same results with heap3.c and heap4.c

snprintf error (PIC32MZ2048EFM064)

So use heap_2.c and make sure you follow the instructions are below, it’s a simply array you put in your main c file and set the flag configAPPLICATIONALLOCATEDHEAP = 1 You need to set configTOTALHEAPSIZE with some suitable size for the array that is all the memory your allocator has so make sure you make it big enough (AKA what are you allocating for each of your tasks) and add some reasonable overhead. If that doesn’t work then there is something a lot deeper at play. ~~~ configAPPLICATIONALLOCATEDHEAP By default the FreeRTOS heap is declared by FreeRTOS and placed in memory by the linker. Setting configAPPLICATIONALLOCATEDHEAP to 1 allows the heap to instead be declared by the application writer, which allows the application writer to place the heap wherever they like in memory. If heap1.c, heap2.c or heap4.c is used, and configAPPLICATIONALLOCATEDHEAP is set to 1, then the application writer must provide a uint8t array with the exact name and dimension as shown below. The array will be used as the FreeRTOS heap. How the array is placed at a specific memory location is dependent on the compiler being used – refer to your compiler’s documentation. uint8t ucHeap[ configTOTALHEAP_SIZE ]; ~~~

snprintf error (PIC32MZ2048EFM064)

it doesn’t operate T_T. My configuration : configAPPLICATIONALLOCATEDHEAP = 1 configTOTALHEAPSIZE = 60000 heap_2.c is loaded

snprintf error (PIC32MZ2048EFM064)

Hello, Microchip support found the solution : problem come from fputc() in debug.c, it must replace this function by : ~~~ void attribute((externallyvisible)) _monputc (char c){ //Wait for the transmitter to be ready while(U2STA & U2STAUTXBFMASK); //Send character U2TXREG = c; //Wait for the transfer to complete while(!(U2STA & _U2STATRMT_MASK)); } ~~~