Просмотр исходного кода

Merge pull request #214 from spacefisch/mueller/nano-nosys-float-handling-pr-upstream

added floating scan and print support for newlib nano and allow combining nosys and nano specs
Hish15 4 лет назад
Родитель
Сommit
b9963c3df7
2 измененных файлов с 29 добавлено и 15 удалено
  1. 15 7
      README.md
  2. 14 8
      cmake/stm32/common.cmake

+ 15 - 7
README.md

@@ -82,12 +82,21 @@ CMSIS creates the following targets:
 
 So, if you don't need linker script, you can link only `CMSIS::STM32::<TYPE>` library and provide your own script using `stm32_add_linker_script` function
 
-***Note**: For H7 family, because of it's multi-core architecture, all H7 targets also have a suffix (::M7 or ::M4).
-For example, targets created for STM32H747BI will look like `CMSIS::STM32::H7::M7`, `CMSIS::STM32::H7::M4`, `CMSIS::STM32::H747BI::M7`, `CMSIS::STM32::H747BI::M4`, etc.*
-
-The GCC C/C++ standard libraries are added by linking the library `STM32::NoSys`. This will add the `--specs=nosys.specs` to compiler and linker flags.
-If you want to use C++ on MCUs with little flash, you might instead want to link the newlib-nano to reduce the code size. You can do so by linking `STM32::Nano`, which will add the `--specs=nano.specs` flags to both compiler and linker.
-Keep in mind that when using `STM32::Nano`, by default you cannot use floats in printf/scanf calls, and you have to provide implementations for several OS interfacing functions (_sbrk, _close, _fstat, and others).
+***Note**: For H7 family, because of it multi-cores architecture, all H7 targets also have a suffix (::M7 or ::M4).
+For example, targets created for STM32H747BI will look like `CMSIS::STM32::H7::M7`,
+`CMSIS::STM32::H7::M4`, `CMSIS::STM32::H747BI::M7`, `CMSIS::STM32::H747BI::M4`, etc.*
+
+The GCC C/C++ standard libraries are added by linking the library `STM32::NoSys`. This will add
+the `--specs=nosys.specs` to compiler and linker flags.
+If you want to use C++ on MCUs with little flash, you might instead want to link the newlib-nano to
+reduce the code size. You can do so by linking `STM32::Nano`, which will add the
+`--specs=nano.specs` flags to both compiler and linker.
+Keep in mind that when using `STM32::Nano`, by default you cannot use floats in printf/scanf calls,
+and you have to provide implementations for several OS interfacing
+functions (`_sbrk`, `_close`, `_fstat`, and others). You can enable printf/scanf floating point support with
+newlib-nano by linking against `STM32::Nano::FloatPrint` and/or `STM32::Nano::FloatScan`.
+It is also possible to combine `STM32::Nano` and `STM32::NoSys`
+to have the benefits of reduced code size while not being forced to implement system calls.
 
 ## HAL
 
@@ -166,4 +175,3 @@ Other FreeRTOS libraries:
 * `FreeRTOS::StreamBuffer` - stream buffer (`stream_buffer.c`)
 * `FreeRTOS::Timers` - timers (`timers.c`)
 * `FreeRTOS::Heap::<N>` - heap implementation (`heap_<N>.c`), `<N>`: [1-5]
-

+ 14 - 8
cmake/stm32/common.cmake

@@ -277,20 +277,26 @@ if(NOT (TARGET STM32::NoSys))
     add_library(STM32::NoSys INTERFACE IMPORTED)
     target_compile_options(STM32::NoSys INTERFACE $<$<C_COMPILER_ID:GNU>:--specs=nosys.specs>)
     target_link_options(STM32::NoSys INTERFACE $<$<C_COMPILER_ID:GNU>:--specs=nosys.specs>)
-    #This custom property is used to check that specs is not set yet on a target linking to this one
-    set_property(TARGET STM32::NoSys PROPERTY INTERFACE_CUSTOM_GCC_SPECS "NOSYS")
-    set_property(TARGET STM32::NoSys APPEND PROPERTY
-        COMPATIBLE_INTERFACE_STRING CUSTOM_GCC_SPECS)
 endif()
 
 if(NOT (TARGET STM32::Nano))
     add_library(STM32::Nano INTERFACE IMPORTED)
     target_compile_options(STM32::Nano INTERFACE $<$<C_COMPILER_ID:GNU>:--specs=nano.specs>)
     target_link_options(STM32::Nano INTERFACE $<$<C_COMPILER_ID:GNU>:--specs=nano.specs>)
-    #This custom property is used to check that specs is not set yet on a target linking to this one
-    set_property(TARGET STM32::Nano PROPERTY INTERFACE_CUSTOM_GCC_SPECS "NANO")
-    set_property(TARGET STM32::Nano APPEND PROPERTY
-        COMPATIBLE_INTERFACE_STRING CUSTOM_GCC_SPECS)
+endif()
+
+if(NOT (TARGET STM32::Nano::FloatPrint))
+    add_library(STM32::Nano::FloatPrint INTERFACE IMPORTED)
+    target_link_options(STM32::Nano::FloatPrint INTERFACE
+        $<$<C_COMPILER_ID:GNU>:-Wl,--undefined,_printf_float>
+    )
+endif()
+
+if(NOT (TARGET STM32::Nano::FloatScan))
+    add_library(STM32::Nano::FloatScan INTERFACE IMPORTED)
+    target_link_options(STM32::Nano::FloatPrint INTERFACE
+        $<$<C_COMPILER_ID:GNU>:-Wl,--undefined,_scanf_float>
+    )
 endif()
 
 include(stm32/utilities)