Skip to content

Commit

Permalink
arm/newlib: Add pseudomodule to enable floating point printf support
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Mar 21, 2016
1 parent b46b9d9 commit e1fcee6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.pseudomodules
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PSEUDOMODULES += schedstatistics
PSEUDOMODULES += netif
PSEUDOMODULES += saul_default
PSEUDOMODULES += saul_gpio
PSEUDOMODULES += printf_float

# include variants of the AT86RF2xx drivers as pseudo modules
PSEUDOMODULES += at86rf23%
Expand Down
1 change: 1 addition & 0 deletions cpu/Makefile.include.cortexm_common
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ include $(RIOTCPU)/cortexm_common/Makefile.include

# use the nano-specs of Newlib when available
USEMODULE += newlib_nano
export USE_NANO_SPECS = 1

# Avoid overriding the default rule:
all:
Expand Down
6 changes: 6 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ ifneq (,$(filter arduino,$(USEMODULE)))
include $(RIOTBASE)/sys/arduino/Makefile.include
endif

ifneq (,$(filter printf_float,$(USEMODULE)))
ifeq (1,$(USE_NANO_SPECS))
export LINKFLAGS += -u _printf_float
endif
endif

INCLUDES += -I$(RIOTBASE)/sys/libc/include
6 changes: 6 additions & 0 deletions tests/printf_float/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APPLICATION = test_printf_float
include ../Makefile.tests_common

USEMODULE += printf_float

include $(RIOTBASE)/Makefile.include
51 changes: 51 additions & 0 deletions tests/printf_float/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2016 Alexandre Abadie <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup tests
* @{
*
* @file
* @brief print floating point values test application
*
* This test is supposed to check that floating point values can be
* displayed with printf function.
*
* @author Alexandre Abadie <[email protected]>
*
* @}
*/

#include <stdio.h>
#include <string.h>
#include <inttypes.h>

static const char * expected_result = "2016.0";
static const double floating_point_value = 2016.0317;

int main(void)
{
const uint8_t str_len = strlen(expected_result);
char result[str_len];
snprintf(result, str_len + 1,
"%.f", floating_point_value);

printf("Value displayed: %s\n", result);

if (strcmp(result, expected_result) == 0) {
printf("[OK]\n");
}
else {
printf("[FAILED] Values are not equal:\n"
"actual: %s\n"
"expected: %s\n", result, expected_result);
return 1;
}

return 0;
}

0 comments on commit e1fcee6

Please sign in to comment.