FreeRTOS / FreeRTOS-Cellular-Interface

FreeRTOS Cellular Interface implementation of the 3GPP TS v27.007 standard.
MIT License
85 stars 59 forks source link

Add configs for log format #152

Closed chinglee-iot closed 1 year ago

chinglee-iot commented 1 year ago

Description

Log format is different for different compiler. For example, the following code can be compiled with GCC 32 bits and 64 bits.

uint32_t sentLen = 0;
LogDebug( ( "PktioSendData sent %u bytes", sentLen ) );

However, there will be format warning with GNU arm compiler.

FreeRTOS-Cellular-Interface/source/cellular_pktio.c:1430:17: error: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
 1430 |     LogDebug( ( "PktioSendData sent %u bytes", sentLen ) );
      |                 ^~~~~~~~~~~~~~~~~~~~~~         ~~~~~~~
      |                                                |
      |                                                uint32_t {aka long unsigned int}

Although C99 defines inttypes.h for this problem, this library doesn't reply on inttypes.h.

In this PR,

User with GNU ARM compiler can define the following in celllular_config.h

#define CELLULAR_LOG_FMT_SIZE "u"
#define CELLULAR_LOG_FMT_UINT32 "lu"
#define CELLULAR_LOG_FMT_INT32 "ld"

Or using PRIx macros if inttypes.h is preferred

#include <inttypes.h>

#define CELLULAR_LOG_FMT_SIZE PRIu16
#define CELLULAR_LOG_FMT_UINT32 PRIu32
#define CELLULAR_LOG_FMT_INT32 PRIi32

Test Steps

Reference this branch https://github.com/chinglee-iot/FreeRTOS-Cellular-Interface/tree/add-compiler-warning-check GCC Build with the following command.

cmake -S test -B build -DCMAKE_C_COMPILER_WORKS=1
cd build
make compilation_test

GNU arm Add the following config in test/unit-test/configs/compilation-test/cellular_config.h

#define CELLULAR_LOG_FMT_SIZE "u"
#define CELLULAR_LOG_FMT_UINT32 "lu"
#define CELLULAR_LOG_FMT_INT32 "ld"

Build with the following command.

CC=arm-none-eabi-gcc cmake -B build -S test -DCMAKE_C_COMPILER_WORKS=1
cd build
make compilation_test

Checklist:

Related Issue

151

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.