From 056ea905dd15374d6857559062cb47306d25e5ad Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 8 Dec 2023 16:03:47 +0100 Subject: [PATCH 1/7] Improve docs and CMake configure_file --- CMakeLists.txt | 1 + docs/get-started/index.rst | 10 +++++++++- lwprintf/CMakeLists.txt | 12 +++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e977349..46e7c78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ else() ) # Add subdir with lwprintf and link to the project + set(LWPRINTF_OPTS_DIR ${CMAKE_CURRENT_LIST_DIR}/dev) add_subdirectory(lwprintf) target_link_libraries(${PROJECT_NAME} lwprintf) endif() diff --git a/docs/get-started/index.rst b/docs/get-started/index.rst index 5e8cead..87d6843 100644 --- a/docs/get-started/index.rst +++ b/docs/get-started/index.rst @@ -66,6 +66,10 @@ Next step is to add the library to the project, by means of source files to comp * Copy ``lwprintf/src/include/lwprintf/lwprintf_opts_template.h`` to project folder and rename it to ``lwprintf_opts.h`` * Build the project +.. tip:: + If you are using *CMake* build system, you can add the library to the project by adding the *library's folder* + directory with ``add_directory()`` CMake command, followed by linking the target with ``target_link_libraries()`` + Configuration file ^^^^^^^^^^^^^^^^^^ @@ -78,7 +82,11 @@ and it should be copied (or simply renamed in-place) and named ``lwprintf_opts.h File must be renamed to ``lwprintf_opts.h`` first and then copied to the project directory where compiler include paths have access to it by using ``#include "lwprintf_opts.h"``. -List of configuration options are available in the :ref:`api_lwprintf_opt` section. +.. tip:: + If you are using *CMake* build system, define the variable ``LWPRINTF_OPTS_DIR`` before adding library's directory to the *CMake* project. + Variable must set the output directory path. CMake will copy the template file there, and name it as required. + +Configuration options list is available available in the :ref:`api_lwprintf_opt` section. If any option is about to be modified, it should be done in configuration file .. literalinclude:: ../../lwprintf/src/include/lwprintf/lwprintf_opts_template.h diff --git a/lwprintf/CMakeLists.txt b/lwprintf/CMakeLists.txt index fa33ed4..0402345 100644 --- a/lwprintf/CMakeLists.txt +++ b/lwprintf/CMakeLists.txt @@ -5,7 +5,13 @@ add_library(lwprintf INTERFACE) target_sources(lwprintf PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwprintf/lwprintf.c) target_include_directories(lwprintf INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) -if (DEFINED LWPRINTF_SYS_PORT) -target_sources(lwprintf PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c) +# Add system port +if(DEFINED LWPRINTF_SYS_PORT) + target_sources(lwprintf PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c) endif() + +# Create config file +if(DEFINED LWPRINTF_OPTS_DIR AND NOT EXISTS ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h) + configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwprintf/lwprintf_opts_template.h ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h COPYONLY) +endif() \ No newline at end of file From b6fabdcfee3265800c62ffca317dcd3d469b8390 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 9 Dec 2023 11:10:20 +0100 Subject: [PATCH 2/7] Create .cmake file to allow higher flexibility of end user --- lwprintf/CMakeLists.txt | 16 +--------------- lwprintf/library.cmake | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 lwprintf/library.cmake diff --git a/lwprintf/CMakeLists.txt b/lwprintf/CMakeLists.txt index 0402345..f05f91d 100644 --- a/lwprintf/CMakeLists.txt +++ b/lwprintf/CMakeLists.txt @@ -1,17 +1,3 @@ cmake_minimum_required(VERSION 3.22) -# Register core library -add_library(lwprintf INTERFACE) -target_sources(lwprintf PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwprintf/lwprintf.c) -target_include_directories(lwprintf INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include) - -# Add system port -if(DEFINED LWPRINTF_SYS_PORT) - target_sources(lwprintf PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c) -endif() - -# Create config file -if(DEFINED LWPRINTF_OPTS_DIR AND NOT EXISTS ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h) - configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwprintf/lwprintf_opts_template.h ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h COPYONLY) -endif() \ No newline at end of file +include(${CMAKE_CURRENT_LIST_DIR}/library.cmake) \ No newline at end of file diff --git a/lwprintf/library.cmake b/lwprintf/library.cmake new file mode 100644 index 0000000..724c444 --- /dev/null +++ b/lwprintf/library.cmake @@ -0,0 +1,29 @@ +# Library core sources +set(lwprintf_core_SRCS + ${CMAKE_CURRENT_LIST_DIR}/src/lwprintf/lwprintf.c +) + +# Add system port +if(DEFINED LWPRINTF_SYS_PORT) + set(lwprintf_core_SRCS + ${lwprintf_core_SRCS} + ${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c + ) +endif() + +# Setup include directories +set(lwprintf_include_DIRS + ${CMAKE_CURRENT_LIST_DIR}/src/include +) + +# Register library to the system +add_library(lwprintf INTERFACE) +target_sources(lwprintf INTERFACE ${lwprintf_core_SRCS}) +target_include_directories(lwprintf INTERFACE ${lwprintf_include_DIRS}) +target_compile_options(lwprintf PRIVATE ${LWPRINTF_COMPILE_OPTIONS}) +target_compile_definitions(lwprintf PRIVATE ${LWPRINTF_COMPILE_DEFINITIONS}) + +# Create config file +if(DEFINED LWPRINTF_OPTS_DIR AND NOT EXISTS ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h) + configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwprintf/lwprintf_opts_template.h ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h COPYONLY) +endif() \ No newline at end of file From 79977b8f50baa1f3c41218f921a98741be0bedc7 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 9 Dec 2023 16:49:23 +0100 Subject: [PATCH 3/7] Improve the cmake documentation --- docs/get-started/index.rst | 16 +++++++++++----- lwprintf/library.cmake | 12 ++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/get-started/index.rst b/docs/get-started/index.rst index 87d6843..b6c07d0 100644 --- a/docs/get-started/index.rst +++ b/docs/get-started/index.rst @@ -58,7 +58,17 @@ Add library to project ^^^^^^^^^^^^^^^^^^^^^^ At this point it is assumed that you have successfully download library, either cloned it or from releases page. -Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path +Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path. + +*CMake* is the main supported build system. Package comes with the ``CMakeLists.txt`` and ``library.cmake`` files, both located in the ``lwprintf`` directory: + +* ``CMakeLists.txt``: Is a wrapper and only includes ``library.cmake`` file. It is used if target application uses ``add_subdirectory`` and then uses ``target_link_libraries`` to include the library in the project +* ``library.cmake``: It is a fully configured set of variables. User must use ``include(path/to/library.cmake)`` to include the library and must manually add files/includes to the final target + +.. tip:: + Open ``library.cmake`` file and manually analyze all the possible variables you can set for full functionality. + +If you do not use the *CMake*, you can do the following: * Copy ``lwprintf`` folder to your project, it contains library files * Add ``lwprintf/src/include`` folder to `include path` of your toolchain. This is where `C/C++` compiler can find the files during compilation process. Usually using ``-I`` flag @@ -66,10 +76,6 @@ Next step is to add the library to the project, by means of source files to comp * Copy ``lwprintf/src/include/lwprintf/lwprintf_opts_template.h`` to project folder and rename it to ``lwprintf_opts.h`` * Build the project -.. tip:: - If you are using *CMake* build system, you can add the library to the project by adding the *library's folder* - directory with ``add_directory()`` CMake command, followed by linking the target with ``target_link_libraries()`` - Configuration file ^^^^^^^^^^^^^^^^^^ diff --git a/lwprintf/library.cmake b/lwprintf/library.cmake index 724c444..5be9023 100644 --- a/lwprintf/library.cmake +++ b/lwprintf/library.cmake @@ -1,3 +1,15 @@ +# +# This file provides set of variables for end user +# and also generates one (or more) libraries, that can be added to the project using target_link_libraries(...) +# +# Before this file is included to the root CMakeLists file (using include() function), user can set some variables: +# +# LWPRINTF_SYS_PORT: If defined, it will include port source file from the library. +# LWPRINTF_OPTS_DIR: If defined, it should set the folder path where options file shall be generated. +# LWPRINTF_COMPILE_OPTIONS: If defined, it provide compiler options for generated library. +# LWPRINTF_COMPILE_DEFINITIONS: If defined, it provides "-D" definitions to the library build +# + # Library core sources set(lwprintf_core_SRCS ${CMAKE_CURRENT_LIST_DIR}/src/lwprintf/lwprintf.c From cacb98e599f37b93a70cae51679b0eb8b0af33cc Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 9 Dec 2023 17:06:40 +0100 Subject: [PATCH 4/7] Add AUTHORS file --- AUTHORS | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..46c3766 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,4 @@ +Tilen Majerle +Tilen Majerle +Brian +Peter Maxwell Warasila \ No newline at end of file From a0403d5173334e405ef0e2f0c4f730c547970580 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sat, 9 Dec 2023 17:13:47 +0100 Subject: [PATCH 5/7] Add authors in the docs file --- docs/authors/index.rst | 8 ++++++++ docs/index.rst | 1 + 2 files changed, 9 insertions(+) create mode 100644 docs/authors/index.rst diff --git a/docs/authors/index.rst b/docs/authors/index.rst new file mode 100644 index 0000000..4031a8c --- /dev/null +++ b/docs/authors/index.rst @@ -0,0 +1,8 @@ +.. _authors: + +Authors +======= + +List of authors and contributors to the library + +.. literalinclude:: ../../AUTHORS \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index 54ce149..d56cbbe 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -67,6 +67,7 @@ Table of contents test-results/index examples/index changelog/index + authors/index .. toctree:: :maxdepth: 2 From 1a5f5537e3bb90c3286ddfca392188ec4f3f0b95 Mon Sep 17 00:00:00 2001 From: Dmitry Karasev Date: Sun, 10 Dec 2023 23:00:38 +0300 Subject: [PATCH 6/7] Fix building with RTOS and without manual protection --- CHANGELOG.md | 2 ++ lwprintf/src/lwprintf/lwprintf.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f4639..f81150d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Develop +- Fix building the library with `LWPRINTF_CFG_OS=1` and `LWPRINTF_CFG_OS_MANUAL_PROTECT=0` options + ## v1.0.4 - Fix calculation for NULL terminated string and precision with 0 as an input diff --git a/lwprintf/src/lwprintf/lwprintf.c b/lwprintf/src/lwprintf/lwprintf.c index 4d64d8d..380c14c 100644 --- a/lwprintf/src/lwprintf/lwprintf.c +++ b/lwprintf/src/lwprintf/lwprintf.c @@ -838,7 +838,7 @@ prv_format(lwprintf_int_t* lwi, va_list arg) { const char* fmt = lwi->fmt; #if LWPRINTF_CFG_OS && !LWPRINTF_CFG_OS_MANUAL_PROTECT - if (IS_PRINT_MODE(p) && /* OS protection only for print */ + if (IS_PRINT_MODE(lwi) && /* OS protection only for print */ (!lwprintf_sys_mutex_isvalid(&lwi->lwobj->mutex) /* Invalid mutex handle */ || !lwprintf_sys_mutex_wait(&lwi->lwobj->mutex))) { /* Cannot acquire mutex */ return 0; @@ -1112,7 +1112,7 @@ prv_format(lwprintf_int_t* lwi, va_list arg) { } lwi->out_fn(lwi, '\0'); /* Output last zero number */ #if LWPRINTF_CFG_OS && !LWPRINTF_CFG_OS_MANUAL_PROTECT - if (IS_PRINT_MODE(p)) { /* Mutex only for print operation */ + if (IS_PRINT_MODE(lwi)) { /* Mutex only for print operation */ lwprintf_sys_mutex_release(&lwi->lwobj->mutex); } #endif /* LWPRINTF_CFG_OS && !LWPRINTF_CFG_OS_MANUAL_PROTECT */ From 497dfd985cdc99edbdd45ca0be0b2a8351b00cac Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Sun, 10 Dec 2023 21:20:03 +0100 Subject: [PATCH 7/7] Set version to 1.0.5 --- CHANGELOG.md | 2 ++ dev/lwprintf_opts.h | 10 +++++----- .../Core/Inc/lwprintf_opts.h | 2 +- library.json | 2 +- lwprintf/src/include/lwprintf/lwprintf.h | 2 +- lwprintf/src/include/lwprintf/lwprintf_opt.h | 2 +- lwprintf/src/include/lwprintf/lwprintf_opts_template.h | 2 +- lwprintf/src/include/system/lwprintf_sys.h | 2 +- lwprintf/src/lwprintf/lwprintf.c | 2 +- lwprintf/src/system/lwprintf_sys_cmsis_os.c | 2 +- lwprintf/src/system/lwprintf_sys_threadx.c | 2 +- lwprintf/src/system/lwprintf_sys_win32.c | 2 +- 12 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f81150d..ce9f236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Develop +## v1.0.5 + - Fix building the library with `LWPRINTF_CFG_OS=1` and `LWPRINTF_CFG_OS_MANUAL_PROTECT=0` options ## v1.0.4 diff --git a/dev/lwprintf_opts.h b/dev/lwprintf_opts.h index 7b370e9..7a563f3 100644 --- a/dev/lwprintf_opts.h +++ b/dev/lwprintf_opts.h @@ -29,7 +29,7 @@ * This file is part of Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #ifndef LWPRINTF_HDR_OPTS_H #define LWPRINTF_HDR_OPTS_H @@ -42,10 +42,10 @@ * Open "include/lwprintf/lwprintf_opt.h" and * copy & replace here settings you want to change values */ -#define LWPRINTF_CFG_OS 1 -#define LWPRINTF_CFG_OS_MUTEX_HANDLE HANDLE +#define LWPRINTF_CFG_OS 1 +#define LWPRINTF_CFG_OS_MUTEX_HANDLE HANDLE -#define LWPRINTF_CFG_SUPPORT_LONG_LONG 1 -#define LWPRINTF_CFG_OS_MANUAL_PROTECT 1 +#define LWPRINTF_CFG_SUPPORT_LONG_LONG 1 +#define LWPRINTF_CFG_OS_MANUAL_PROTECT 1 #endif /* OW_HDR_OPTS_H */ diff --git a/examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/lwprintf_opts.h b/examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/lwprintf_opts.h index a6d5d2d..3427d08 100644 --- a/examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/lwprintf_opts.h +++ b/examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/lwprintf_opts.h @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #ifndef LWPRINTF_HDR_OPTS_H #define LWPRINTF_HDR_OPTS_H diff --git a/library.json b/library.json index e3f9727..3546559 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "LwPRINTF", - "version": "1.0.4", + "version": "1.0.5", "description": "Lightweight printf and sprintf library for embedded systems", "keywords": "printf, lightweight, lwprintf, sprintf, snprintf, embedded, stdio, manager, library", "repository": { diff --git a/lwprintf/src/include/lwprintf/lwprintf.h b/lwprintf/src/include/lwprintf/lwprintf.h index 1d002fb..477c8e9 100644 --- a/lwprintf/src/include/lwprintf/lwprintf.h +++ b/lwprintf/src/include/lwprintf/lwprintf.h @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #ifndef LWPRINTF_HDR_H #define LWPRINTF_HDR_H diff --git a/lwprintf/src/include/lwprintf/lwprintf_opt.h b/lwprintf/src/include/lwprintf/lwprintf_opt.h index cc0b79a..a67628e 100644 --- a/lwprintf/src/include/lwprintf/lwprintf_opt.h +++ b/lwprintf/src/include/lwprintf/lwprintf_opt.h @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #ifndef LWPRINTF_OPT_HDR_H #define LWPRINTF_OPT_HDR_H diff --git a/lwprintf/src/include/lwprintf/lwprintf_opts_template.h b/lwprintf/src/include/lwprintf/lwprintf_opts_template.h index 6237e50..b609c5d 100644 --- a/lwprintf/src/include/lwprintf/lwprintf_opts_template.h +++ b/lwprintf/src/include/lwprintf/lwprintf_opts_template.h @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #ifndef LWPRINTF_OPTS_HDR_H #define LWPRINTF_OPTS_HDR_H diff --git a/lwprintf/src/include/system/lwprintf_sys.h b/lwprintf/src/include/system/lwprintf_sys.h index d087b5f..9b55206 100644 --- a/lwprintf/src/include/system/lwprintf_sys.h +++ b/lwprintf/src/include/system/lwprintf_sys.h @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #ifndef LWPRINTF_SYS_HDR_H #define LWPRINTF_SYS_HDR_H diff --git a/lwprintf/src/lwprintf/lwprintf.c b/lwprintf/src/lwprintf/lwprintf.c index 380c14c..6435f03 100644 --- a/lwprintf/src/lwprintf/lwprintf.c +++ b/lwprintf/src/lwprintf/lwprintf.c @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #include "lwprintf/lwprintf.h" #include diff --git a/lwprintf/src/system/lwprintf_sys_cmsis_os.c b/lwprintf/src/system/lwprintf_sys_cmsis_os.c index fffe721..e85735c 100644 --- a/lwprintf/src/system/lwprintf_sys_cmsis_os.c +++ b/lwprintf/src/system/lwprintf_sys_cmsis_os.c @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #include "system/lwprintf_sys.h" diff --git a/lwprintf/src/system/lwprintf_sys_threadx.c b/lwprintf/src/system/lwprintf_sys_threadx.c index 3c40224..191afad 100644 --- a/lwprintf/src/system/lwprintf_sys_threadx.c +++ b/lwprintf/src/system/lwprintf_sys_threadx.c @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #include "system/lwprintf_sys.h" diff --git a/lwprintf/src/system/lwprintf_sys_win32.c b/lwprintf/src/system/lwprintf_sys_win32.c index 547fccc..50a7195 100644 --- a/lwprintf/src/system/lwprintf_sys_win32.c +++ b/lwprintf/src/system/lwprintf_sys_win32.c @@ -29,7 +29,7 @@ * This file is part of LwPRINTF - Lightweight stdio manager library. * * Author: Tilen MAJERLE - * Version: v1.0.4 + * Version: v1.0.5 */ #include "system/lwprintf_sys.h"