I'm not able to use macro PRIu32 with KDS 3.0.0 toolchain

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm not able to use macro PRIu32 with KDS 3.0.0 toolchain

789 Views
denisdantas
Contributor II

Hello,

 

I'm trying to build the following code for a K22F family processor:

#include <inttypes.h> #include <stdint.h> #include <stdio.h>  char myBuffer[20]; uint32_t myVar = 1234; uint16_t size;  void foo (void) {     size = sprintf(myBuffer, "%"PRIu32, myVar); }

 

but I get the error "format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t'". If I switch "%"PRIu32 for "%ul" I can build with the regular KDS Cross ARM gcc compiler, though.

 

The thing is that we have a testing environment that builds our platform using Cygwin's gcc, which complains if I use %ul passing a uint32_t argument. The alternative would be to use PRIu32 - it's a preciser way of specifying the type of argument, since the size of %u or %ul may change between compilers.

 

The solution I found was switching my KDS's toolchain for Cross ARM gcc latest toolchain. However, using the new toolchain is giving giving issuing an error when I try to debug my project using KDS.

 

Is there anyway I can use the latest Cross ARM gcc toolchain without breaking my KDS debugger?

 

Best Regards,

 

Denis Dantas

Labels (1)
7 Replies

306 Views
denisdantas
Contributor II

Hello Jennie,

I found out that what is causing the compiler error in my project is because I'm using the flag -ffreestanding in my Cross ARM compilation (Properties > C/C++ Build > Settings > Tool Settings > Cross ARM C Compiler > Miscellaneous > Other compiler flags). My projects are generated using KSDK Project Generator 2.0, and was set by default after generation. I also set all warnings to be considered as errors in my project. That's because I cannot compile.

Apparently this flag is used to tell the GCC compiler that I want to have a "freestanding implementation", which means that the compiler should expect that some standard libraries are going to be implemented in a different way, and that the beginning of the program may not be at main (in our cause it's in the startup file). (Using the GNU Compiler Collection (GCC) ).

Again, if I use the latest version of the Cross ARM GCC Compiler, I get to compile the code with the freestanding flag. However, OpenOCD gives me an error when I try to debug my code.

I think I will give up on using PRIu32, otherwise there are too many changes associated. I hope next version of KSDK supports the newest Cross ARM GCC Compiler.

Best Regards,

Denis

0 Kudos

306 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Denis,

Good! Thanks for your clarification.

Best Regards,

Jennie Zhang

306 Views
denisdantas
Contributor II

Hey there ZhangJennie,

I'm using KDS 3.2, but I still get the error. Do you have any idea what may be the problem?

PRIu32 error.jpg

0 Kudos

306 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Denis,

as the demo code and video I attached in my first response. PRlu32 works normal from my side. did you download my demo code to test it on your side? how does it work?

could you upload your demo code to me thus I can check the problem directly from my side? thanks!


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

306 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Denis Dantas.

macro PRIu32 is defined in inttyypes.h. so it's necessary to include inttypes.h to the source.

here is my testing code, there is no problem to build it under KDS3.2 Cross ARM GCC. I also attach the demo code and video.Can this help you?

#include "MK22F12810.h"

#include "inttypes.h"

static int i = 0;

char myBuffer[20];

uint32_t myVar = 1234;

uint16_t size;

void foo (void)

{

    size = sprintf(myBuffer, "%"PRIu32, myVar);

}

int main(void)

{

    /* Write your code here */

    foo();

    /* This for loop should be replaced. By default this loop allows a single stepping. */

    for (;;) {

        i++;

    }

    /* Never leave main */

    return 0;

}


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

306 Views
denisdantas
Contributor II

Hello Jennie,

I installed KDS 3.2, but now I am having an error when trying to compile my project. The header file of some KSDK files cannot be found now. Do you have any idea what could be causing that?

KDS3v2_failure.jpg

0 Kudos

306 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Denis,

Is this compile error a new question? if yes, to separate different subject, could you please create a new thread for it?

Best Regards,

Jennie

0 Kudos