Note: this is a "howto" question and answer rather than a real question, given because it may be helpful to others.
Description of the Problem: printf("%f", 2.0) doesn't print anything, nor does it give any errors.
Solved! Go to Solution.
Note: this is a "howto" response rather than a genuine question, given because it may be helpful to others.
Disclaimer: The information here has been cobbled together from several sources and experimentation. It works for my environment (KDS 3.2.0 running under Mac OSX 10.12.2, Cross ARM C compiler), but details may be different for your environment.
Description of the Problem: printf("%f", 2.0) doesn't print anything.
Reason: The Cross ARM C compiler (and linker) do not provide support for printing and scanning floating point numbers by default.
Solution: You can add support to the Cross ARM C compiler for printing and scanning floating point numbers (and doubles) as follows.
You can test that printf() works with floats by creating a project based on the "Hello World" demo application and modifying it as follows:
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
int main(void) {
char ch;
double val;
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
val = 0.01;
for (int i=0; i<5; i++) {
PRINTF("val = %f\n", val);
val *= 10.0;
}
while (1) {
ch = GETCHAR();
PUTCHAR(ch);
}
}
If all goes well, you should see this printed on the console:
val = 0.010000
val = 0.100000
val = 1.000000
val = 10.000000
val = 100.000000
Note: this is a "howto" response rather than a genuine question, given because it may be helpful to others.
Disclaimer: The information here has been cobbled together from several sources and experimentation. It works for my environment (KDS 3.2.0 running under Mac OSX 10.12.2, Cross ARM C compiler), but details may be different for your environment.
Description of the Problem: printf("%f", 2.0) doesn't print anything.
Reason: The Cross ARM C compiler (and linker) do not provide support for printing and scanning floating point numbers by default.
Solution: You can add support to the Cross ARM C compiler for printing and scanning floating point numbers (and doubles) as follows.
You can test that printf() works with floats by creating a project based on the "Hello World" demo application and modifying it as follows:
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
int main(void) {
char ch;
double val;
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
val = 0.01;
for (int i=0; i<5; i++) {
PRINTF("val = %f\n", val);
val *= 10.0;
}
while (1) {
ch = GETCHAR();
PUTCHAR(ch);
}
}
If all goes well, you should see this printed on the console:
val = 0.010000
val = 0.100000
val = 1.000000
val = 10.000000
val = 100.000000