├── .clang-format ├── .clang-tidy ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── build-and-test.yml │ ├── codeql-buildscript.sh │ ├── codeql.yml │ ├── fail_on_error.py │ └── release.yml ├── .gitignore ├── .readthedocs.yaml ├── .vscode ├── c_cpp_properties.json ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── AUTHORS ├── CHANGELOG.md ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md ├── cmake ├── i686-w64-mingw32-gcc.cmake └── x86_64-w64-mingw32-gcc.cmake ├── dev ├── lwprintf_opts.h └── main.c ├── docs ├── Makefile ├── api-reference │ ├── index.rst │ ├── lwprintf.rst │ ├── lwprintf_opt.rst │ └── lwprintf_sys.rst ├── authors │ └── index.rst ├── changelog │ └── index.rst ├── conf.py ├── doxyfile.doxy ├── examples │ └── index.rst ├── examples_src │ ├── example_instance.c │ ├── example_instance_single_func.c │ ├── example_minimal.c │ └── example_multi_thread_corrupted_text.c ├── get-started │ └── index.rst ├── index.rst ├── make.bat ├── requirements.txt ├── static │ ├── css │ │ ├── common.css │ │ └── custom.css │ ├── dark-light │ │ ├── checked.svg │ │ ├── common-dark-light.css │ │ ├── dark-mode-toggle.mjs │ │ ├── dark.css │ │ ├── light.css │ │ ├── moon.png │ │ ├── moon.svg │ │ ├── sun.png │ │ ├── sun.svg │ │ └── unchecked.svg │ └── images │ │ ├── logo.drawio │ │ ├── logo.svg │ │ ├── logo_tm.png │ │ └── logo_tm_full.png ├── test-results │ └── index.rst └── user-manual │ ├── format-specifier.rst │ ├── how-it-works.rst │ ├── index.rst │ ├── instances.rst │ └── thread-safety.rst ├── examples ├── additional_format_specifiers.c └── stm32 │ └── lwprintf_stm32l432kc_nucleo │ ├── .cproject │ ├── .project │ ├── .vscode │ ├── c_cpp_properties.json │ ├── extensions.json │ ├── launch.json │ └── tasks.json │ ├── CMakeLists.txt │ ├── CMakePresets.json │ ├── Core │ ├── Inc │ │ ├── lwprintf_opts.h │ │ ├── main.h │ │ ├── stm32l4xx_hal_conf.h │ │ └── stm32l4xx_it.h │ ├── Src │ │ ├── main.c │ │ ├── stm32l4xx_hal_msp.c │ │ ├── stm32l4xx_it.c │ │ ├── syscalls.c │ │ ├── sysmem.c │ │ └── system_stm32l4xx.c │ └── Startup │ │ └── startup_stm32l412kbux.s │ ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32L4xx │ │ │ │ └── Include │ │ │ │ ├── stm32l412xx.h │ │ │ │ ├── stm32l4xx.h │ │ │ │ └── system_stm32l4xx.h │ │ └── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_armclang_ltm.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_cm4.h │ │ │ └── mpu_armv7.h │ └── STM32L4xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ ├── stm32l4xx_hal.h │ │ ├── stm32l4xx_hal_cortex.h │ │ ├── stm32l4xx_hal_def.h │ │ ├── stm32l4xx_hal_dma.h │ │ ├── stm32l4xx_hal_dma_ex.h │ │ ├── stm32l4xx_hal_exti.h │ │ ├── stm32l4xx_hal_flash.h │ │ ├── stm32l4xx_hal_flash_ex.h │ │ ├── stm32l4xx_hal_flash_ramfunc.h │ │ ├── stm32l4xx_hal_gpio.h │ │ ├── stm32l4xx_hal_gpio_ex.h │ │ ├── stm32l4xx_hal_i2c.h │ │ ├── stm32l4xx_hal_i2c_ex.h │ │ ├── stm32l4xx_hal_pwr.h │ │ ├── stm32l4xx_hal_pwr_ex.h │ │ ├── stm32l4xx_hal_rcc.h │ │ ├── stm32l4xx_hal_rcc_ex.h │ │ ├── stm32l4xx_hal_tim.h │ │ ├── stm32l4xx_hal_tim_ex.h │ │ ├── stm32l4xx_hal_uart.h │ │ └── stm32l4xx_hal_uart_ex.h │ │ └── Src │ │ ├── stm32l4xx_hal.c │ │ ├── stm32l4xx_hal_cortex.c │ │ ├── stm32l4xx_hal_dma.c │ │ ├── stm32l4xx_hal_dma_ex.c │ │ ├── stm32l4xx_hal_exti.c │ │ ├── stm32l4xx_hal_flash.c │ │ ├── stm32l4xx_hal_flash_ex.c │ │ ├── stm32l4xx_hal_flash_ramfunc.c │ │ ├── stm32l4xx_hal_gpio.c │ │ ├── stm32l4xx_hal_i2c.c │ │ ├── stm32l4xx_hal_i2c_ex.c │ │ ├── stm32l4xx_hal_pwr.c │ │ ├── stm32l4xx_hal_pwr_ex.c │ │ ├── stm32l4xx_hal_rcc.c │ │ ├── stm32l4xx_hal_rcc_ex.c │ │ ├── stm32l4xx_hal_tim.c │ │ ├── stm32l4xx_hal_tim_ex.c │ │ ├── stm32l4xx_hal_uart.c │ │ └── stm32l4xx_hal_uart_ex.c │ ├── STM32L412KBUX_FLASH.ld │ ├── cmake │ └── gcc-arm-none-eabi.cmake │ ├── lwprintf_stm32l432kc_nucleo Debug.launch │ └── lwprintf_stm32l432kc_nucleo.ioc ├── library.json ├── lwprintf ├── CMakeLists.txt ├── library.cmake └── src │ ├── include │ ├── lwprintf │ │ ├── lwprintf.h │ │ ├── lwprintf_opt.h │ │ └── lwprintf_opts_template.h │ └── system │ │ └── lwprintf_sys.h │ ├── lwprintf │ └── lwprintf.c │ └── system │ ├── lwprintf_sys_cmsis_os.c │ ├── lwprintf_sys_threadx.c │ └── lwprintf_sys_win32.c └── tests ├── test.c └── test_results.test /.clang-format: -------------------------------------------------------------------------------- 1 | # Language part removed. With clang-format >=20.1, the C and Cpp are separately handled, 2 | # so either there is no language at all, or we need to create 2 formats for C and Cpp, separately 3 | 4 | --- 5 | # Language: Cpp 6 | # BasedOnStyle: LLVM 7 | AccessModifierOffset: -2 8 | AlignAfterOpenBracket: Align 9 | AlignArrayOfStructures: None 10 | AlignConsecutiveMacros: 11 | Enabled: true 12 | AcrossEmptyLines: true 13 | AcrossComments: true 14 | AlignConsecutiveAssignments: None 15 | AlignConsecutiveBitFields: 16 | Enabled: true 17 | AcrossEmptyLines: true 18 | AcrossComments: true 19 | AlignConsecutiveDeclarations: None 20 | AlignEscapedNewlines: Right 21 | AlignOperands: Align 22 | SortIncludes: true 23 | InsertBraces: true # Control statements must have curly brackets 24 | AlignTrailingComments: true 25 | AllowAllArgumentsOnNextLine: true 26 | AllowAllParametersOfDeclarationOnNextLine: true 27 | AllowShortEnumsOnASingleLine: true 28 | AllowShortBlocksOnASingleLine: Empty 29 | AllowShortCaseLabelsOnASingleLine: true 30 | AllowShortFunctionsOnASingleLine: All 31 | AllowShortLambdasOnASingleLine: All 32 | AllowShortIfStatementsOnASingleLine: Never 33 | AllowShortLoopsOnASingleLine: false 34 | AlwaysBreakAfterDefinitionReturnType: None 35 | AlwaysBreakAfterReturnType: AllDefinitions 36 | AlwaysBreakBeforeMultilineStrings: false 37 | AlwaysBreakTemplateDeclarations: Yes 38 | AttributeMacros: 39 | - __capability 40 | BinPackArguments: true 41 | BinPackParameters: true 42 | BraceWrapping: 43 | AfterCaseLabel: false 44 | AfterClass: false 45 | AfterControlStatement: Never 46 | AfterEnum: false 47 | AfterFunction: false 48 | AfterNamespace: false 49 | AfterObjCDeclaration: false 50 | AfterStruct: false 51 | AfterUnion: false 52 | AfterExternBlock: false 53 | BeforeCatch: false 54 | BeforeElse: false 55 | BeforeLambdaBody: false 56 | BeforeWhile: false 57 | IndentBraces: false 58 | SplitEmptyFunction: true 59 | SplitEmptyRecord: true 60 | SplitEmptyNamespace: true 61 | BreakBeforeBinaryOperators: NonAssignment 62 | BreakBeforeConceptDeclarations: true 63 | BreakBeforeBraces: Attach 64 | BreakBeforeInheritanceComma: false 65 | BreakInheritanceList: BeforeColon 66 | BreakBeforeTernaryOperators: true 67 | BreakConstructorInitializersBeforeComma: false 68 | BreakConstructorInitializers: BeforeColon 69 | BreakAfterJavaFieldAnnotations: false 70 | BreakStringLiterals: true 71 | ColumnLimit: 120 72 | CommentPragmas: "^ IWYU pragma:" 73 | QualifierAlignment: Leave 74 | CompactNamespaces: false 75 | ConstructorInitializerIndentWidth: 4 76 | ContinuationIndentWidth: 4 77 | Cpp11BracedListStyle: true 78 | DeriveLineEnding: true 79 | DerivePointerAlignment: false 80 | DisableFormat: false 81 | EmptyLineAfterAccessModifier: Never 82 | EmptyLineBeforeAccessModifier: LogicalBlock 83 | ExperimentalAutoDetectBinPacking: false 84 | PackConstructorInitializers: BinPack 85 | BasedOnStyle: "" 86 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 87 | AllowAllConstructorInitializersOnNextLine: true 88 | FixNamespaceComments: true 89 | ForEachMacros: 90 | - foreach 91 | - Q_FOREACH 92 | - BOOST_FOREACH 93 | IfMacros: 94 | - KJ_IF_MAYBE 95 | IncludeBlocks: Preserve 96 | IncludeCategories: 97 | - Regex: "^<(.*)>" 98 | Priority: 0 99 | - Regex: '^"(.*)"' 100 | Priority: 1 101 | - Regex: "(.*)" 102 | Priority: 2 103 | IncludeIsMainRegex: "(Test)?$" 104 | IncludeIsMainSourceRegex: "" 105 | IndentAccessModifiers: false 106 | IndentCaseLabels: true 107 | IndentCaseBlocks: false 108 | IndentGotoLabels: true 109 | IndentPPDirectives: None 110 | IndentExternBlock: AfterExternBlock 111 | IndentRequires: true 112 | IndentWidth: 4 113 | IndentWrappedFunctionNames: false 114 | InsertTrailingCommas: None 115 | JavaScriptQuotes: Leave 116 | JavaScriptWrapImports: true 117 | KeepEmptyLinesAtTheStartOfBlocks: true 118 | LambdaBodyIndentation: Signature 119 | MacroBlockBegin: "" 120 | MacroBlockEnd: "" 121 | MaxEmptyLinesToKeep: 1 122 | NamespaceIndentation: None 123 | ObjCBinPackProtocolList: Auto 124 | ObjCBlockIndentWidth: 2 125 | ObjCBreakBeforeNestedBlockParam: true 126 | ObjCSpaceAfterProperty: false 127 | ObjCSpaceBeforeProtocolList: true 128 | PenaltyBreakAssignment: 2 129 | PenaltyBreakBeforeFirstCallParameter: 19 130 | PenaltyBreakComment: 300 131 | PenaltyBreakFirstLessLess: 120 132 | PenaltyBreakOpenParenthesis: 0 133 | PenaltyBreakString: 1000 134 | PenaltyBreakTemplateDeclaration: 10 135 | PenaltyExcessCharacter: 1000000 136 | PenaltyReturnTypeOnItsOwnLine: 60 137 | PenaltyIndentedWhitespace: 0 138 | PointerAlignment: Left 139 | PPIndentWidth: -1 140 | ReferenceAlignment: Pointer 141 | ReflowComments: false 142 | RemoveBracesLLVM: false 143 | SeparateDefinitionBlocks: Always 144 | ShortNamespaceLines: 1 145 | SortJavaStaticImport: Before 146 | SortUsingDeclarations: true 147 | SpaceAfterCStyleCast: false 148 | SpaceAfterLogicalNot: false 149 | SpaceAfterTemplateKeyword: true 150 | SpaceBeforeAssignmentOperators: true 151 | SpaceBeforeCaseColon: false 152 | SpaceBeforeParens: ControlStatements 153 | SpaceBeforeParensOptions: 154 | AfterControlStatements: true 155 | AfterForeachMacros: true 156 | AfterFunctionDefinitionName: false 157 | AfterFunctionDeclarationName: false 158 | AfterIfMacros: true 159 | AfterOverloadedOperator: false 160 | BeforeNonEmptyParentheses: false 161 | SpaceAroundPointerQualifiers: Default 162 | SpaceBeforeRangeBasedForLoopColon: true 163 | SpaceInEmptyBlock: false 164 | SpaceInEmptyParentheses: false 165 | SpacesBeforeTrailingComments: 1 166 | SpacesInAngles: Never 167 | SpacesInConditionalStatement: false 168 | SpacesInContainerLiterals: true 169 | SpacesInCStyleCastParentheses: false 170 | SpacesInLineCommentPrefix: 171 | Minimum: 1 172 | Maximum: -1 173 | SpacesInParentheses: false 174 | SpacesInSquareBrackets: false 175 | SpaceBeforeSquareBrackets: false 176 | BitFieldColonSpacing: Both 177 | Standard: Latest 178 | StatementAttributeLikeMacros: 179 | - Q_EMIT 180 | StatementMacros: 181 | - Q_UNUSED 182 | - QT_REQUIRE_VERSION 183 | TabWidth: 8 184 | UseCRLF: false 185 | UseTab: Never 186 | WhitespaceSensitiveMacros: 187 | - STRINGIZE 188 | - PP_STRINGIZE 189 | - BOOST_PP_STRINGIZE 190 | - NS_SWIFT_NAME 191 | - CF_SWIFT_NAME 192 | SpaceBeforeCpp11BracedList: false 193 | SpaceBeforeCtorInitializerColon: true 194 | SpaceBeforeInheritanceColon: true 195 | --- 196 | 197 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: "*, 3 | -abseil-*, 4 | -altera-*, 5 | -android-*, 6 | -fuchsia-*, 7 | -google-*, 8 | -llvm*, 9 | -modernize-use-trailing-return-type, 10 | -zircon-*, 11 | -readability-else-after-return, 12 | -readability-static-accessed-through-instance, 13 | -readability-avoid-const-params-in-decls, 14 | -cppcoreguidelines-non-private-member-variables-in-classes, 15 | -misc-non-private-member-variables-in-classes, 16 | " 17 | WarningsAsErrors: '' 18 | HeaderFilterRegex: '' 19 | FormatStyle: none -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: ['paypal.me/tilz0R'] 4 | -------------------------------------------------------------------------------- /.github/workflows/build-and-test.yml: -------------------------------------------------------------------------------- 1 | name: Windows CMake Build & Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | pull_request: 8 | branches: 9 | - develop 10 | 11 | jobs: 12 | build: 13 | runs-on: windows-latest 14 | 15 | steps: 16 | - name: Checkout Repository 17 | uses: actions/checkout@v4 18 | 19 | - name: Install MinGW 20 | run: | 21 | choco install mingw --version=12.2.0 -y 22 | echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" >> $GITHUB_PATH 23 | gcc --version 24 | 25 | - name: Build for 32-bit 26 | run: | 27 | mkdir __build__ 28 | cd __build__ 29 | cmake -S.. -T host=x86 -A Win32 30 | cmake --build . 31 | 32 | - name: Run Tests 33 | working-directory: __build__ 34 | run: | 35 | ctest . --output-on-failure -C Debug 36 | -------------------------------------------------------------------------------- /.github/workflows/codeql-buildscript.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd lwprintf 4 | mkdir build && cd build && cmake ../ 5 | make 6 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "main", "master" ] 17 | schedule: 18 | - cron: '0 0 * * *' 19 | pull_request: 20 | branches: '*' 21 | 22 | jobs: 23 | analyze: 24 | name: Analyze 25 | # Runner size impacts CodeQL analysis time. To learn more, please see: 26 | # - https://gh.io/recommended-hardware-resources-for-running-codeql 27 | # - https://gh.io/supported-runners-and-hardware-resources 28 | # - https://gh.io/using-larger-runners 29 | # Consider using larger runners for possible analysis time improvements. 30 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-20.04' }} 31 | timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} 32 | permissions: 33 | actions: read 34 | contents: read 35 | security-events: write 36 | 37 | strategy: 38 | fail-fast: false 39 | matrix: 40 | language: [ 'cpp' ] 41 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] 42 | # Use only 'java' to analyze code written in Java, Kotlin or both 43 | # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both 44 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 45 | 46 | steps: 47 | - name: Checkout repository 48 | uses: actions/checkout@v3 49 | with: 50 | submodules: recursive 51 | 52 | # Initializes the CodeQL tools for scanning. 53 | - name: Initialize CodeQL 54 | uses: github/codeql-action/init@v2 55 | with: 56 | languages: ${{ matrix.language }} 57 | # If you wish to specify custom queries, you can do so here or in a config file. 58 | # By default, queries listed here will override any specified in a config file. 59 | # Prefix the list here with "+" to use these queries and those in the config file. 60 | 61 | # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 62 | # queries: security-extended,security-and-quality 63 | queries: security-and-quality 64 | 65 | 66 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). 67 | # If this step fails, then you should remove it and run the build manually (see below) 68 | #- name: Autobuild 69 | # uses: github/codeql-action/autobuild@v2 70 | 71 | # ℹ️ Command-line programs to run using the OS shell. 72 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 73 | 74 | # If the Autobuild fails above, remove it and uncomment the following three lines. 75 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 76 | 77 | - run: | 78 | ./.github/workflows/codeql-buildscript.sh 79 | 80 | - name: Perform CodeQL Analysis 81 | uses: github/codeql-action/analyze@v2 82 | with: 83 | category: "/language:${{matrix.language}}" 84 | upload: false 85 | id: step1 86 | 87 | # Filter out rules with low severity or high false positve rate 88 | # Also filter out warnings in third-party code 89 | - name: Filter out unwanted errors and warnings 90 | uses: advanced-security/filter-sarif@v1 91 | with: 92 | patterns: | 93 | -**:cpp/path-injection 94 | -**:cpp/world-writable-file-creation 95 | -**:cpp/poorly-documented-function 96 | -**:cpp/potentially-dangerous-function 97 | -**:cpp/use-of-goto 98 | -**:cpp/integer-multiplication-cast-to-long 99 | -**:cpp/comparison-with-wider-type 100 | -**:cpp/leap-year/* 101 | -**:cpp/ambiguously-signed-bit-field 102 | -**:cpp/suspicious-pointer-scaling 103 | -**:cpp/suspicious-pointer-scaling-void 104 | -**:cpp/unsigned-comparison-zero 105 | -**/cmake*/Modules/** 106 | input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif 107 | output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif 108 | 109 | - name: Upload CodeQL results to code scanning 110 | uses: github/codeql-action/upload-sarif@v2 111 | with: 112 | sarif_file: ${{ steps.step1.outputs.sarif-output }} 113 | category: "/language:${{matrix.language}}" 114 | 115 | - name: Upload CodeQL results as an artifact 116 | if: success() || failure() 117 | uses: actions/upload-artifact@v3 118 | with: 119 | name: codeql-results 120 | path: ${{ steps.step1.outputs.sarif-output }} 121 | retention-days: 5 122 | 123 | - name: Fail if an error is found 124 | run: | 125 | ./.github/workflows/fail_on_error.py \ 126 | ${{ steps.step1.outputs.sarif-output }}/cpp.sarif 127 | -------------------------------------------------------------------------------- /.github/workflows/fail_on_error.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import json 4 | import sys 5 | 6 | # Return whether SARIF file contains error-level results 7 | def codeql_sarif_contain_error(filename): 8 | with open(filename, 'r') as f: 9 | s = json.load(f) 10 | 11 | for run in s.get('runs', []): 12 | rules_metadata = run['tool']['driver']['rules'] 13 | if not rules_metadata: 14 | rules_metadata = run['tool']['extensions'][0]['rules'] 15 | 16 | for res in run.get('results', []): 17 | if 'ruleIndex' in res: 18 | rule_index = res['ruleIndex'] 19 | elif 'rule' in res and 'index' in res['rule']: 20 | rule_index = res['rule']['index'] 21 | else: 22 | continue 23 | try: 24 | rule_level = rules_metadata[rule_index]['defaultConfiguration']['level'] 25 | except IndexError as e: 26 | print(e, rule_index, len(rules_metadata)) 27 | else: 28 | if rule_level == 'error': 29 | return True 30 | return False 31 | 32 | if __name__ == "__main__": 33 | if codeql_sarif_contain_error(sys.argv[1]): 34 | sys.exit(1) 35 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | # Sequence of patterns matched against refs/tags 4 | tags: 5 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 6 | 7 | name: Create Release 8 | 9 | jobs: 10 | build: 11 | name: Create Release 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v2 16 | - name: Create Release 17 | id: create_release 18 | uses: actions/create-release@v1 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token 21 | with: 22 | tag_name: ${{ github.ref }} 23 | release_name: Release ${{ github.ref }} 24 | body: | 25 | See the [CHANGELOG](CHANGELOG.md) 26 | draft: false 27 | prerelease: false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Build Keil files 2 | *.rar 3 | *.o 4 | *.d 5 | *.crf 6 | *.htm 7 | *.dep 8 | *.map 9 | *.bak 10 | *.axf 11 | *.lnp 12 | *.lst 13 | *.ini 14 | *.scvd 15 | *.iex 16 | *.sct 17 | *.MajerleT 18 | *.tjuln 19 | *.tilen 20 | *.dbgconf 21 | *.uvguix 22 | *.uvoptx 23 | *.__i 24 | *.i 25 | *.txt 26 | !docs/*.txt 27 | !CMakeLists.txt 28 | RTE/ 29 | 30 | *debug 31 | 32 | # IAR Settings 33 | **/settings/*.crun 34 | **/settings/*.dbgdt 35 | **/settings/*.cspy 36 | **/settings/*.cspy.* 37 | **/settings/*.xcl 38 | **/settings/*.dni 39 | **/settings/*.wsdt 40 | **/settings/*.wspos 41 | 42 | # IAR Debug Exe 43 | **/Exe/*.sim 44 | 45 | # IAR Debug Obj 46 | **/Obj/*.pbd 47 | **/Obj/*.pbd.* 48 | **/Obj/*.pbi 49 | **/Obj/*.pbi.* 50 | 51 | *.TMP 52 | /docs_src/x_Doxyfile.doxy 53 | 54 | .DS_Store 55 | 56 | ## Ignore Visual Studio temporary files, build results, and 57 | ## files generated by popular Visual Studio add-ons. 58 | ## 59 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 60 | 61 | # User-specific files 62 | *.suo 63 | *.user 64 | *.userosscache 65 | *.sln.docstates 66 | 67 | # User-specific files (MonoDevelop/Xamarin Studio) 68 | *.userprefs 69 | 70 | # Build results 71 | [Dd]ebug/ 72 | [Dd]ebugPublic/ 73 | [Rr]elease/ 74 | [Rr]eleases/ 75 | [Dd]ebug*/ 76 | x64/ 77 | x86/ 78 | bld/ 79 | [Bb]in/ 80 | [Oo]bj/ 81 | [Ll]og/ 82 | _build/ 83 | build/ 84 | __build__/ 85 | 86 | # Visual Studio 2015/2017 cache/options directory 87 | .vs/ 88 | # Uncomment if you have tasks that create the project's static files in wwwroot 89 | #wwwroot/ 90 | 91 | # Visual Studio 2017 auto generated files 92 | Generated\ Files/ 93 | 94 | # MSTest test Results 95 | [Tt]est[Rr]esult*/ 96 | [Bb]uild[Ll]og.* 97 | 98 | # NUNIT 99 | *.VisualState.xml 100 | TestResult.xml 101 | 102 | # Build Results of an ATL Project 103 | [Dd]ebugPS/ 104 | [Rr]eleasePS/ 105 | dlldata.c 106 | 107 | # Benchmark Results 108 | BenchmarkDotNet.Artifacts/ 109 | 110 | # .NET Core 111 | project.lock.json 112 | project.fragment.lock.json 113 | artifacts/ 114 | **/Properties/launchSettings.json 115 | 116 | # StyleCop 117 | StyleCopReport.xml 118 | 119 | # Files built by Visual Studio 120 | *_i.c 121 | *_p.c 122 | *_i.h 123 | *.ilk 124 | *.meta 125 | *.obj 126 | *.pch 127 | *.pdb 128 | *.pgc 129 | *.pgd 130 | *.rsp 131 | *.sbr 132 | *.tlb 133 | *.tli 134 | *.tlh 135 | *.tmp 136 | *.tmp_proj 137 | *.log 138 | *.vspscc 139 | *.vssscc 140 | .builds 141 | *.pidb 142 | *.svclog 143 | *.scc 144 | *.out 145 | *.sim 146 | 147 | # Chutzpah Test files 148 | _Chutzpah* 149 | 150 | # Visual C++ cache files 151 | ipch/ 152 | *.aps 153 | *.ncb 154 | *.opendb 155 | *.opensdf 156 | *.sdf 157 | *.cachefile 158 | *.VC.db 159 | *.VC.VC.opendb 160 | 161 | # Visual Studio profiler 162 | *.psess 163 | *.vsp 164 | *.vspx 165 | *.sap 166 | 167 | # Visual Studio Trace Files 168 | *.e2e 169 | 170 | # TFS 2012 Local Workspace 171 | $tf/ 172 | 173 | # Guidance Automation Toolkit 174 | *.gpState 175 | 176 | # ReSharper is a .NET coding add-in 177 | _ReSharper*/ 178 | *.[Rr]e[Ss]harper 179 | *.DotSettings.user 180 | 181 | # JustCode is a .NET coding add-in 182 | .JustCode 183 | 184 | # TeamCity is a build add-in 185 | _TeamCity* 186 | 187 | # DotCover is a Code Coverage Tool 188 | *.dotCover 189 | 190 | # AxoCover is a Code Coverage Tool 191 | .axoCover/* 192 | !.axoCover/settings.json 193 | 194 | # Visual Studio code coverage results 195 | *.coverage 196 | *.coveragexml 197 | 198 | # NCrunch 199 | _NCrunch_* 200 | .*crunch*.local.xml 201 | nCrunchTemp_* 202 | 203 | # MightyMoose 204 | *.mm.* 205 | AutoTest.Net/ 206 | 207 | # Web workbench (sass) 208 | .sass-cache/ 209 | 210 | # Installshield output folder 211 | [Ee]xpress/ 212 | 213 | # DocProject is a documentation generator add-in 214 | DocProject/buildhelp/ 215 | DocProject/Help/*.HxT 216 | DocProject/Help/*.HxC 217 | DocProject/Help/*.hhc 218 | DocProject/Help/*.hhk 219 | DocProject/Help/*.hhp 220 | DocProject/Help/Html2 221 | DocProject/Help/html 222 | 223 | # Click-Once directory 224 | publish/ 225 | 226 | # Publish Web Output 227 | *.[Pp]ublish.xml 228 | *.azurePubxml 229 | # Note: Comment the next line if you want to checkin your web deploy settings, 230 | # but database connection strings (with potential passwords) will be unencrypted 231 | *.pubxml 232 | *.publishproj 233 | 234 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 235 | # checkin your Azure Web App publish settings, but sensitive information contained 236 | # in these scripts will be unencrypted 237 | PublishScripts/ 238 | 239 | # NuGet Packages 240 | *.nupkg 241 | # The packages folder can be ignored because of Package Restore 242 | **/[Pp]ackages/* 243 | # except build/, which is used as an MSBuild target. 244 | !**/[Pp]ackages/build/ 245 | # Uncomment if necessary however generally it will be regenerated when needed 246 | #!**/[Pp]ackages/repositories.config 247 | # NuGet v3's project.json files produces more ignorable files 248 | *.nuget.props 249 | *.nuget.targets 250 | 251 | # Microsoft Azure Build Output 252 | csx/ 253 | *.build.csdef 254 | 255 | # Microsoft Azure Emulator 256 | ecf/ 257 | rcf/ 258 | 259 | # Windows Store app package directories and files 260 | AppPackages/ 261 | BundleArtifacts/ 262 | Package.StoreAssociation.xml 263 | _pkginfo.txt 264 | *.appx 265 | 266 | # Visual Studio cache files 267 | # files ending in .cache can be ignored 268 | *.[Cc]ache 269 | # but keep track of directories ending in .cache 270 | !*.[Cc]ache/ 271 | 272 | # Others 273 | ClientBin/ 274 | ~$* 275 | *~ 276 | *.dbmdl 277 | *.dbproj.schemaview 278 | *.jfm 279 | *.pfx 280 | *.publishsettings 281 | orleans.codegen.cs 282 | 283 | # Including strong name files can present a security risk 284 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 285 | #*.snk 286 | 287 | # Since there are multiple workflows, uncomment next line to ignore bower_components 288 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 289 | #bower_components/ 290 | 291 | # RIA/Silverlight projects 292 | Generated_Code/ 293 | 294 | # Backup & report files from converting an old project file 295 | # to a newer Visual Studio version. Backup files are not needed, 296 | # because we have git ;-) 297 | _UpgradeReport_Files/ 298 | Backup*/ 299 | UpgradeLog*.XML 300 | UpgradeLog*.htm 301 | 302 | # SQL Server files 303 | *.mdf 304 | *.ldf 305 | *.ndf 306 | 307 | # Business Intelligence projects 308 | *.rdl.data 309 | *.bim.layout 310 | *.bim_*.settings 311 | 312 | # Microsoft Fakes 313 | FakesAssemblies/ 314 | 315 | # GhostDoc plugin setting file 316 | *.GhostDoc.xml 317 | 318 | # Node.js Tools for Visual Studio 319 | .ntvs_analysis.dat 320 | node_modules/ 321 | 322 | # TypeScript v1 declaration files 323 | typings/ 324 | 325 | # Visual Studio 6 build log 326 | *.plg 327 | 328 | # Visual Studio 6 workspace options file 329 | *.opt 330 | 331 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 332 | *.vbw 333 | 334 | # Visual Studio LightSwitch build output 335 | **/*.HTMLClient/GeneratedArtifacts 336 | **/*.DesktopClient/GeneratedArtifacts 337 | **/*.DesktopClient/ModelManifest.xml 338 | **/*.Server/GeneratedArtifacts 339 | **/*.Server/ModelManifest.xml 340 | _Pvt_Extensions 341 | 342 | # Paket dependency manager 343 | .paket/paket.exe 344 | paket-files/ 345 | 346 | # FAKE - F# Make 347 | .fake/ 348 | 349 | # JetBrains Rider 350 | .idea/ 351 | *.sln.iml 352 | 353 | # CodeRush 354 | .cr/ 355 | 356 | # Python Tools for Visual Studio (PTVS) 357 | __pycache__/ 358 | *.pyc 359 | 360 | # Cake - Uncomment if you are using it 361 | # tools/** 362 | # !tools/packages.config 363 | 364 | # Tabs Studio 365 | *.tss 366 | 367 | # Telerik's JustMock configuration file 368 | *.jmconfig 369 | 370 | # BizTalk build output 371 | *.btp.cs 372 | *.btm.cs 373 | *.odx.cs 374 | *.xsd.cs 375 | 376 | # OpenCover UI analysis results 377 | OpenCover/ 378 | 379 | # Azure Stream Analytics local run output 380 | ASALocalRun/ 381 | 382 | # MSBuild Binary and Structured Log 383 | *.binlog 384 | 385 | log_file.txt 386 | .metadata/ 387 | .mxproject 388 | .settings/ 389 | project.ioc 390 | mx.scratch 391 | *.tilen majerle 392 | 393 | 394 | # Altium 395 | Project outputs* 396 | History/ 397 | *.SchDocPreview 398 | *.$$$Preview 399 | 400 | # VSCode projects 401 | project_vscode_compiled.exe -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | build: 3 | os: ubuntu-22.04 4 | tools: 5 | python: "3.11" 6 | 7 | # Build documentation in the docs/ directory with Sphinx 8 | sphinx: 9 | configuration: docs/conf.py 10 | 11 | # Python configuration 12 | python: 13 | install: 14 | - requirements: docs/requirements.txt 15 | 16 | formats: 17 | - pdf 18 | - epub 19 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 4, 3 | "configurations": [ 4 | { 5 | /* 6 | * Full configuration is provided by CMake plugin for vscode, 7 | * that shall be installed by user 8 | */ 9 | "name": "Win32", 10 | "intelliSenseMode": "${default}", 11 | "configurationProvider": "ms-vscode.cmake-tools" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-vscode.cpptools", 4 | "ms-vscode.cmake-tools", 5 | "twxs.cmake", 6 | ] 7 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | /* GDB must in be in the PATH environment */ 6 | "name": "(Windows) Launch", 7 | "type": "cppdbg", 8 | "request": "launch", 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [], 11 | "stopAtEntry": false, 12 | "cwd": "${fileDirname}", 13 | "environment": [] 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.lcdjson": "json", 4 | "lwevt_types.h": "c", 5 | "lwevt_type.h": "c", 6 | "lwevt.h": "c", 7 | "string.h": "c", 8 | "lwevt_opt.h": "c", 9 | "windows.h": "c", 10 | "lwprintf.h": "c" 11 | }, 12 | "esbonio.sphinx.confDir": "" 13 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "cppbuild", 6 | "label": "Build project", 7 | "command": "cmake", 8 | "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], 9 | "options": { 10 | "cwd": "${workspaceFolder}" 11 | }, 12 | "problemMatcher": ["$gcc"], 13 | "group": { 14 | "kind": "build", 15 | "isDefault": true 16 | } 17 | }, 18 | { 19 | "type": "shell", 20 | "label": "Re-build project", 21 | "command": "cmake", 22 | "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], 23 | "options": { 24 | "cwd": "${workspaceFolder}" 25 | }, 26 | "problemMatcher": ["$gcc"], 27 | }, 28 | { 29 | "type": "shell", 30 | "label": "Clean project", 31 | "command": "cmake", 32 | "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], 33 | "options": { 34 | "cwd": "${workspaceFolder}" 35 | }, 36 | "problemMatcher": [] 37 | }, 38 | { 39 | "type": "shell", 40 | "label": "Run application", 41 | "command": "${command:cmake.launchTargetPath}", 42 | "args": [], 43 | "problemMatcher": [], 44 | }, 45 | { 46 | "label": "Docs: Install python plugins from requirements.txt file", 47 | "type": "shell", 48 | "command": "python -m pip install -r requirements.txt", 49 | "options": { 50 | "cwd": "${workspaceFolder}/docs" 51 | }, 52 | "problemMatcher": [] 53 | }, 54 | { 55 | "label": "Docs: Generate html", 56 | "type": "shell", 57 | "command": ".\\make html", 58 | "options": { 59 | "cwd": "${workspaceFolder}/docs" 60 | }, 61 | "problemMatcher": [] 62 | }, 63 | { 64 | "label": "Docs: Clean build directory", 65 | "type": "shell", 66 | "command": ".\\make clean", 67 | "options": { 68 | "cwd": "${workspaceFolder}/docs" 69 | }, 70 | "problemMatcher": [] 71 | }, 72 | ] 73 | } -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Tilen Majerle 2 | Peter Maxwell Warasila 3 | Tilen Majerle 4 | Brian 5 | Dmitry Karasev 6 | Okarss <104319900+Okarss@users.noreply.github.com> -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## Develop 4 | 5 | - Rework library CMake with removed INTERFACE type 6 | 7 | ## v1.0.6 8 | 9 | - Add `lwprintf_debug` and `lwprintf_debug_cond` functions 10 | - Add single integral type with maximum parameter width for all shorter types 11 | - Fix `lwsnprintf` return type 12 | 13 | ## v1.0.5 14 | 15 | - Fix building the library with `LWPRINTF_CFG_OS=1` and `LWPRINTF_CFG_OS_MANUAL_PROTECT=0` options 16 | 17 | ## v1.0.4 18 | 19 | - Fix calculation for NULL terminated string and precision with 0 as an input 20 | - Split CMakeLists.txt files between library and executable 21 | - Fix missing break in switch statement 22 | - Add support for manual mutual-exclusion setup in OS mode 23 | - Change license year to 2022 24 | - Update code style with astyle 25 | - Add `.clang-format` draft 26 | - Fix protection functions for when print mode is not used 27 | 28 | ## v1.0.3 29 | 30 | - CMSIS-OS improvements for Kernel aware debuggers 31 | 32 | ## v1.0.2 33 | 34 | - Fixed `float` output when engineering mode is disabled 35 | 36 | ## v1.0.1 37 | 38 | - Fixed compiler error when engineering mode disabled but float enabled 39 | - Properly handled `zero` float inputs 40 | 41 | ## v1.0.0 42 | 43 | - First stable release 44 | - Embedded systems optimized library 45 | - Apply all modifiers except `%a` 46 | - Extensive docs available 47 | - Operating system ready with CMSIS-OS template 48 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | 3 | # Setup project 4 | project(LwLibPROJECT) 5 | 6 | if(NOT PROJECT_IS_TOP_LEVEL) 7 | add_subdirectory(lwprintf) 8 | else() 9 | # Set default compile flags for GCC 10 | if(CMAKE_COMPILER_IS_GNUCXX) 11 | message(STATUS "GCC detected, adding compile flags") 12 | set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra") 13 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra") 14 | endif(CMAKE_COMPILER_IS_GNUCXX) 15 | 16 | enable_testing() 17 | add_executable(${PROJECT_NAME}) 18 | target_sources(${PROJECT_NAME} PRIVATE 19 | ${CMAKE_CURRENT_LIST_DIR}/dev/main.c 20 | ${CMAKE_CURRENT_LIST_DIR}/lwprintf/src/system/lwprintf_sys_win32.c 21 | ${CMAKE_CURRENT_LIST_DIR}/tests/test.c 22 | ) 23 | target_include_directories(${PROJECT_NAME} PUBLIC 24 | ${CMAKE_CURRENT_LIST_DIR} 25 | ${CMAKE_CURRENT_LIST_DIR}/dev 26 | ) 27 | 28 | # Add subdir with lwprintf and link to the project 29 | set(LWPRINTF_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwprintf_opts.h) 30 | add_subdirectory(lwprintf) 31 | target_link_libraries(${PROJECT_NAME} lwprintf) 32 | 33 | # Add compile options to the library, which will propagate options to executable through public link 34 | target_compile_definitions(lwprintf PUBLIC WIN32 _DEBUG CONSOLE LWPRINTF_DEV) 35 | 36 | # Add test 37 | add_test(NAME Test COMMAND $) 38 | endif() 39 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "default", 6 | "hidden": true, 7 | "generator": "Ninja", 8 | "binaryDir": "${sourceDir}/build/${presetName}", 9 | "cacheVariables": { 10 | "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" 11 | } 12 | }, 13 | { 14 | "name": "Win32-Debug", 15 | "inherits": "default", 16 | "toolchainFile": "${sourceDir}/cmake/i686-w64-mingw32-gcc.cmake", 17 | "cacheVariables": { 18 | "CMAKE_BUILD_TYPE": "Debug" 19 | } 20 | }, 21 | { 22 | "name": "Win64-Debug", 23 | "inherits": "default", 24 | "toolchainFile": "${sourceDir}/cmake/x86_64-w64-mingw32-gcc.cmake", 25 | "cacheVariables": { 26 | "CMAKE_BUILD_TYPE": "Debug" 27 | } 28 | } 29 | ], 30 | "buildPresets": [ 31 | { 32 | "name": "Win32-Debug", 33 | "configurePreset": "Win32-Debug" 34 | }, 35 | { 36 | "name": "Win64-Debug", 37 | "configurePreset": "Win64-Debug" 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Tilen MAJERLE 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lightweight printf stdio manager 2 | 3 |

Read first: Documentation

4 | 5 | ## Features 6 | 7 | * Written in C (C11), compatible with ``size_t`` and ``uintmax_t`` types for some specifiers 8 | * Implements output functions compatible with ``printf``, ``vprintf``, ``snprintf``, ``sprintf`` and ``vsnprintf`` 9 | * Low-memory footprint, suitable for embedded systems 10 | * Reentrant access to all API functions 11 | * Operating-system ready 12 | * Requires single output function to be implemented by user for ``printf``-like API calls 13 | * With optional functions for operating systems to protect multiple threads printing to the same output stream 14 | * Allows multiple output stream functions (unlike standard ``printf`` which supports only one) to separate parts of application 15 | * Added additional specifiers vs original features 16 | * User friendly MIT license 17 | 18 | ## Contribute 19 | 20 | Fresh contributions are always welcome. Simple instructions to proceed: 21 | 22 | 1. Fork Github repository 23 | 2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project 24 | 3. Create a pull request to develop branch with new features or bug fixes 25 | 26 | Alternatively you may: 27 | 28 | 1. Report a bug 29 | 2. Ask for a feature request 30 | -------------------------------------------------------------------------------- /cmake/i686-w64-mingw32-gcc.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Windows) 2 | 3 | # Some default GCC settings 4 | set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) 5 | set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) 6 | 7 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 8 | -------------------------------------------------------------------------------- /cmake/x86_64-w64-mingw32-gcc.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Windows) 2 | 3 | # Some default GCC settings 4 | set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) 5 | set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) 6 | 7 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 8 | -------------------------------------------------------------------------------- /dev/lwprintf_opts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_opts.h 3 | * \brief LwPRINTF application options 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #ifndef LWPRINTF_HDR_OPTS_H 35 | #define LWPRINTF_HDR_OPTS_H 36 | 37 | /* Rename this file to "lwprintf_opts.h" for your application */ 38 | 39 | #include "windows.h" 40 | 41 | /* 42 | * Open "include/lwprintf/lwprintf_opt.h" and 43 | * copy & replace here settings you want to change values 44 | */ 45 | #define LWPRINTF_CFG_OS 1 46 | #define LWPRINTF_CFG_OS_MUTEX_HANDLE HANDLE 47 | 48 | #define LWPRINTF_CFG_SUPPORT_LONG_LONG 1 49 | #define LWPRINTF_CFG_OS_MANUAL_PROTECT 1 50 | 51 | #endif /* LWPRINTF_HDR_OPTS_H */ 52 | -------------------------------------------------------------------------------- /dev/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lwprintf/lwprintf.h" 5 | #include "windows.h" 6 | 7 | extern int test_printf(void); 8 | 9 | int 10 | main(void) { 11 | return test_printf(); 12 | } 13 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/api-reference/index.rst: -------------------------------------------------------------------------------- 1 | .. _api_reference: 2 | 3 | API reference 4 | ============= 5 | 6 | List of all the modules: 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | lwprintf 12 | lwprintf_opt 13 | lwprintf_sys -------------------------------------------------------------------------------- /docs/api-reference/lwprintf.rst: -------------------------------------------------------------------------------- 1 | .. _api_lwprintf: 2 | 3 | LwPRINTF 4 | ======== 5 | 6 | .. doxygengroup:: LWPRINTF -------------------------------------------------------------------------------- /docs/api-reference/lwprintf_opt.rst: -------------------------------------------------------------------------------- 1 | .. _api_lwprintf_opt: 2 | 3 | Configuration 4 | ============= 5 | 6 | This is the default configuration of the middleware. 7 | When any of the settings shall be modified, it shall be done in dedicated application config ``lwprintf_opts.h`` file. 8 | 9 | .. note:: 10 | Check :ref:`getting_started` to create configuration file. 11 | 12 | .. doxygengroup:: LWPRINTF_OPT 13 | :inner: -------------------------------------------------------------------------------- /docs/api-reference/lwprintf_sys.rst: -------------------------------------------------------------------------------- 1 | .. _api_lwprintf_sys: 2 | 3 | System functions 4 | ================ 5 | 6 | System function are used in conjunction with thread safety. 7 | Please check :ref:`thread_safety` section for more information 8 | 9 | .. doxygengroup:: LWPRINTF_SYS -------------------------------------------------------------------------------- /docs/authors/index.rst: -------------------------------------------------------------------------------- 1 | .. _authors: 2 | 3 | Authors 4 | ======= 5 | 6 | List of authors and contributors to the library 7 | 8 | .. literalinclude:: ../../AUTHORS -------------------------------------------------------------------------------- /docs/changelog/index.rst: -------------------------------------------------------------------------------- 1 | .. _changelof: 2 | 3 | Changelog 4 | ========= 5 | 6 | .. literalinclude:: ../../CHANGELOG.md 7 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | # import os 14 | # import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | from sphinx.builders.html import StandaloneHTMLBuilder 17 | import subprocess, os 18 | 19 | # Run doxygen first 20 | # read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True' 21 | # if read_the_docs_build: 22 | subprocess.call('doxygen doxyfile.doxy', shell=True) 23 | # -- Project information ----------------------------------------------------- 24 | 25 | project = 'LwPRINTF' 26 | copyright = '2023, Tilen MAJERLE' 27 | author = 'Tilen MAJERLE' 28 | 29 | # Try to get branch at which this is running 30 | # and try to determine which version to display in sphinx 31 | # Version is using git tag if on master/main or "latest-develop" if on develop branch 32 | version = '' 33 | git_branch = '' 34 | 35 | def cmd_exec_print(t): 36 | print("cmd > ", t, "\n", os.popen(t).read().strip(), "\n") 37 | 38 | # Print demo data here 39 | cmd_exec_print('git branch') 40 | cmd_exec_print('git describe') 41 | cmd_exec_print('git describe --tags') 42 | cmd_exec_print('git describe --tags --abbrev=0') 43 | cmd_exec_print('git describe --tags --abbrev=1') 44 | 45 | # Get current branch 46 | res = os.popen('git branch').read().strip() 47 | for line in res.split("\n"): 48 | if line[0] == '*': 49 | git_branch = line[1:].strip() 50 | 51 | # Decision for display version 52 | git_branch = git_branch.replace('(HEAD detached at ', '').replace(')', '') 53 | if git_branch.find('master') >= 0 or git_branch.find('main') >= 0: 54 | #version = os.popen('git describe --tags --abbrev=0').read().strip() 55 | version = 'latest-stable' 56 | elif git_branch.find('develop-') >= 0 or git_branch.find('develop/') >= 0: 57 | version = 'branch-' + git_branch 58 | elif git_branch == 'develop' or git_branch == 'origin/develop': 59 | version = 'latest-develop' 60 | else: 61 | version = os.popen('git describe --tags --abbrev=0').read().strip() 62 | 63 | # For debugging purpose only 64 | print("GIT BRANCH: " + git_branch) 65 | print("PROJ VERSION: " + version) 66 | 67 | # -- General configuration --------------------------------------------------- 68 | 69 | # Add any Sphinx extension module names here, as strings. They can be 70 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 71 | # ones. 72 | extensions = [ 73 | 'sphinx.ext.autodoc', 74 | 'sphinx.ext.intersphinx', 75 | 'sphinx.ext.autosectionlabel', 76 | 'sphinx.ext.todo', 77 | 'sphinx.ext.coverage', 78 | 'sphinx.ext.mathjax', 79 | 'sphinx.ext.ifconfig', 80 | 'sphinx.ext.viewcode', 81 | 'sphinx_sitemap', 82 | 83 | 'breathe', 84 | ] 85 | 86 | # Add any paths that contain templates here, relative to this directory. 87 | templates_path = ['templates'] 88 | 89 | # List of patterns, relative to source directory, that match files and 90 | # directories to ignore when looking for source files. 91 | # This pattern also affects html_static_path and html_extra_path. 92 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 93 | 94 | highlight_language = 'c' 95 | 96 | # -- Options for HTML output ------------------------------------------------- 97 | 98 | # The theme to use for HTML and HTML Help pages. See the documentation for 99 | # a list of builtin themes. 100 | # 101 | html_theme = 'sphinx_rtd_theme' 102 | html_theme_options = { 103 | 'canonical_url': '', 104 | 'analytics_id': '', # Provided by Google in your dashboard 105 | 'display_version': True, 106 | 'prev_next_buttons_location': 'bottom', 107 | 'style_external_links': False, 108 | 109 | 'logo_only': False, 110 | 111 | # Toc options 112 | 'collapse_navigation': True, 113 | 'sticky_navigation': True, 114 | 'navigation_depth': 4, 115 | 'includehidden': True, 116 | 'titles_only': False 117 | } 118 | html_logo = 'static/images/logo.svg' 119 | github_url = 'https://github.com/MaJerle/lwprintf' 120 | html_baseurl = 'https://docs.majerle.eu/projects/lwprintf/' 121 | 122 | # Add any paths that contain custom static files (such as style sheets) here, 123 | # relative to this directory. They are copied after the builtin static files, 124 | # so a file named "default.css" will overwrite the builtin "default.css". 125 | html_static_path = ['static'] 126 | html_css_files = [ 127 | 'css/common.css', 128 | 'css/custom.css', 129 | 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css', 130 | ] 131 | html_js_files = [ 132 | '' 133 | ] 134 | 135 | # Master index file 136 | master_doc = 'index' 137 | 138 | # --- Breathe configuration ----------------------------------------------------- 139 | breathe_projects = { 140 | "lwprintf": "_build/xml/" 141 | } 142 | breathe_default_project = "lwprintf" 143 | breathe_default_members = ('members', 'undoc-members') 144 | breathe_show_enumvalue_initializer = True -------------------------------------------------------------------------------- /docs/examples/index.rst: -------------------------------------------------------------------------------- 1 | .. _examples: 2 | 3 | Examples and demos 4 | ================== 5 | 6 | Various examples are provided for fast library evaluation on embedded systems. These are prepared and maintained for ``2`` platforms, but could be easily extended to more platforms: 7 | 8 | * WIN32 examples, prepared as `Visual Studio Community `_ projects 9 | * ARM Cortex-M examples for STM32, prepared as `STM32CubeIDE `_ GCC projects 10 | 11 | .. warning:: 12 | Library is platform independent and can be used on any platform. 13 | 14 | Debug for STM32L4 15 | ***************** 16 | 17 | Simple example is available, that runs on *STM32L432KC-Nucleo* board and shows basic confiuration for library. 18 | On-board *Virtual-COM-Port* through embedded ST-Link provides communication to MCU via UART peripheral. 19 | 20 | Output function writes data to PC using `USART2` hardware IP. 21 | 22 | .. toctree:: 23 | :maxdepth: 2 24 | -------------------------------------------------------------------------------- /docs/examples_src/example_instance.c: -------------------------------------------------------------------------------- 1 | #include "lwprintf/lwprintf.h" 2 | 3 | /* Define application custom instance */ 4 | lwprintf_t custom_instance; 5 | 6 | /* Define custom output function for print */ 7 | int 8 | custom_out(int ch, lwprintf_t* p) { 9 | /* Do whatever with this character */ 10 | if (ch == '\0') { 11 | /* This is end of string in current formatting */ 12 | /* Maybe time to start DMA transfer? */ 13 | } else { 14 | /* Print or send character */ 15 | } 16 | 17 | /* Return character to proceed */ 18 | return ch; 19 | } 20 | 21 | /* Define output function for default instance */ 22 | int 23 | default_out(int ch, lwprintf_t* p) { 24 | /* Print function for default instance */ 25 | 26 | /* See custom_out function for implementation details */ 27 | } 28 | 29 | int 30 | main(void) { 31 | /* Initialize default lwprintf instance with output function */ 32 | lwprintf_init(default_out); 33 | /* Initialize custom lwprintf instance with output function */ 34 | lwprintf_init_ex(&custom_instance, custom_out); 35 | 36 | /* Print first text over default output */ 37 | lwprintf_printf("Text: %d", 10); 38 | /* Print text over custom instance */ 39 | lwprintf_printf_ex(&custom_instance, "Custom: %f", 3.2f); 40 | } 41 | -------------------------------------------------------------------------------- /docs/examples_src/example_instance_single_func.c: -------------------------------------------------------------------------------- 1 | #include "lwprintf/lwprintf.h" 2 | 3 | /* Define application custom instance */ 4 | lwprintf_t custom_instance1; 5 | lwprintf_t custom_instance2; 6 | 7 | /* Define custom output function for print */ 8 | int 9 | my_out(int ch, lwprintf_t* p) { 10 | if (p == &custom_instance1) { 11 | /* This is custom instance 1 */ 12 | } else if (p == &custom_instance2) { 13 | /* This is custom instance 2 */ 14 | } else { 15 | /* This is default instance */ 16 | } 17 | return ch; 18 | } 19 | 20 | int 21 | main(void) { 22 | /* Initialize default lwprintf instance with output function */ 23 | lwprintf_init(my_out); 24 | lwprintf_init_ex(&custom_instance1, my_out); 25 | lwprintf_init_ex(&custom_instance2, my_out); 26 | 27 | /* Use print functions ... */ 28 | } 29 | -------------------------------------------------------------------------------- /docs/examples_src/example_minimal.c: -------------------------------------------------------------------------------- 1 | #include "lwprintf/lwprintf.h" 2 | 3 | /* Called for every character to be printed */ 4 | int 5 | lwprintf_out(int ch, lwprintf_t* lwp) { 6 | /* May use printf to output it for test */ 7 | if (ch != '\0') { 8 | printf("%c", (char)ch); 9 | } 10 | return ch; 11 | } 12 | 13 | int 14 | main(void) { 15 | /* Initialize default lwprintf instance with output function */ 16 | lwprintf_init(lwprintf_out); 17 | 18 | /* Print first text */ 19 | lwprintf_printf("Text: %d", 10); 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples_src/example_multi_thread_corrupted_text.c: -------------------------------------------------------------------------------- 1 | #include "lwprintf/lwprintf.h" 2 | 3 | /* Assuming LwPRINTF has been initialized before */ 4 | 5 | void 6 | task_1(void* arg) { 7 | lwprintf_printf("Hello world\r\n"); 8 | } 9 | 10 | void 11 | task_2(void* arg) { 12 | lwprintf_printf("This is Task 2\r\n"); 13 | } 14 | 15 | /* 16 | * If thread safety is not enabled, 17 | * running above example may print: 18 | * 19 | * "Hello This is Task 2\r\nworld\r\n" 20 | */ 21 | -------------------------------------------------------------------------------- /docs/get-started/index.rst: -------------------------------------------------------------------------------- 1 | .. _getting_started: 2 | 3 | Getting started 4 | =============== 5 | 6 | Getting started may be the most challenging part of every new library. 7 | This guide is describing how to start with the library quickly and effectively 8 | 9 | .. _download_library: 10 | 11 | Download library 12 | ^^^^^^^^^^^^^^^^ 13 | 14 | Library is primarly hosted on `Github `_. 15 | 16 | You can get it by: 17 | 18 | * Downloading latest release from `releases area `_ on Github 19 | * Cloning ``main`` branch for latest stable version 20 | * Cloning ``develop`` branch for latest development 21 | 22 | Download from releases 23 | ********************** 24 | 25 | All releases are available on Github `releases area `_. 26 | 27 | Clone from Github 28 | ***************** 29 | 30 | First-time clone 31 | """""""""""""""" 32 | 33 | This is used when you do not have yet local copy on your machine. 34 | 35 | * Make sure ``git`` is installed. 36 | * Open console and navigate to path in the system to clone repository to. Use command ``cd your_path`` 37 | * Clone repository with one of available options below 38 | 39 | * Run ``git clone --recurse-submodules https://github.com/MaJerle/lwprintf`` command to clone entire repository, including submodules 40 | * Run ``git clone --recurse-submodules --branch develop https://github.com/MaJerle/lwprintf`` to clone `development` branch, including submodules 41 | * Run ``git clone --recurse-submodules --branch main https://github.com/MaJerle/lwprintf`` to clone `latest stable` branch, including submodules 42 | 43 | * Navigate to ``examples`` directory and run favourite example 44 | 45 | Update cloned to latest version 46 | """"""""""""""""""""""""""""""" 47 | 48 | * Open console and navigate to path in the system where your repository is located. Use command ``cd your_path`` 49 | * Run ``git pull origin main`` command to get latest changes on ``main`` branch 50 | * Run ``git pull origin develop`` command to get latest changes on ``develop`` branch 51 | * Run ``git submodule update --init --remote`` to update submodules to latest version 52 | 53 | .. note:: 54 | This is preferred option to use when you want to evaluate library and run prepared examples. 55 | Repository consists of multiple submodules which can be automatically downloaded when cloning and pulling changes from root repository. 56 | 57 | Add library to project 58 | ^^^^^^^^^^^^^^^^^^^^^^ 59 | 60 | At this point it is assumed that you have successfully download library, either with ``git clone`` command or with manual download from the library releases page. 61 | Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path. 62 | 63 | *CMake* is the main supported build system. Package comes with the ``CMakeLists.txt`` and ``library.cmake`` files, both located in the ``lwprintf`` directory: 64 | 65 | * ``library.cmake``: It is a fully configured set of variables and with library definition. User can include this file to the project file with ``include(path/to/library.cmake)`` and then manually use the variables provided by the file, such as list of source files, include paths or necessary compiler definitions. It is up to the user to properly use the this file on its own. 66 | * ``CMakeLists.txt``: It is a wrapper-only file and includes ``library.cmake`` file. It is used for when user wants to include the library to the main project by simply calling *CMake* ``add_subdirectory`` command, followed by ``target_link_libraries`` to link external library to the final project. 67 | 68 | .. tip:: 69 | Open ``library.cmake`` and analyze the provided information. Among variables, you can also find list of all possible exposed libraries for the user. 70 | 71 | If you do not use the *CMake*, you can do the following: 72 | 73 | * Copy ``lwprintf`` folder to your project, it contains library files 74 | * 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 75 | * Add source files from ``lwprintf/src/`` folder to toolchain build. These files are built by `C/C++` compiler 76 | * Copy ``lwprintf/src/include/lwprintf/lwprintf_opts_template.h`` to project folder and rename it to ``lwprintf_opts.h`` 77 | * Build the project 78 | 79 | Configuration file 80 | ^^^^^^^^^^^^^^^^^^ 81 | 82 | Configuration file is used to overwrite default settings defined for the essential use case. 83 | Library comes with template config file, which can be modified according to the application needs. 84 | and it should be copied (or simply renamed in-place) and named ``lwprintf_opts.h`` 85 | 86 | .. note:: 87 | Default configuration template file location: ``lwprintf/src/include/lwprintf/lwprintf_opts_template.h``. 88 | File must be renamed to ``lwprintf_opts.h`` first and then copied to the project directory where compiler 89 | include paths have access to it by using ``#include "lwprintf_opts.h"``. 90 | 91 | .. tip:: 92 | If you are using *CMake* build system, define the variable ``LWPRINTF_OPTS_FILE`` before adding library's directory to the *CMake* project. 93 | Variable must contain the path to the user options file. If not provided and to avoid build error, one will be generated in the build directory. 94 | 95 | Configuration options list is available available in the :ref:`api_lwprintf_opt` section. 96 | If any option is about to be modified, it should be done in configuration file 97 | 98 | .. literalinclude:: ../../lwprintf/src/include/lwprintf/lwprintf_opts_template.h 99 | :language: c 100 | :linenos: 101 | :caption: Template configuration file 102 | 103 | .. note:: 104 | If you prefer to avoid using configuration file, application must define 105 | a global symbol ``LWPRINTF_IGNORE_USER_OPTS``, visible across entire application. 106 | This can be achieved with ``-D`` compiler option. 107 | 108 | Minimal example code 109 | ^^^^^^^^^^^^^^^^^^^^ 110 | 111 | To verify proper library setup, minimal example has been prepared. 112 | Run it in your main application file to verify its proper execution 113 | 114 | .. literalinclude:: ../examples_src/example_minimal.c 115 | :language: c 116 | :linenos: 117 | :caption: Absolute minimum example -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | LwPRINTF |version| documentation 2 | ================================ 3 | 4 | Welcome to the documentation for version |version|. 5 | 6 | LwPRINTF is lightweight stdio manager optimized for embedded systems. 7 | It includes implementation of standard output functions such as ``printf``, ``vprintf``, ``snprintf``, ``sprintf`` and ``vsnprintf`` in an embedded-systems optimized way. 8 | 9 | .. image:: static/images/logo.svg 10 | :align: center 11 | 12 | .. rst-class:: center 13 | .. rst-class:: index_links 14 | 15 | :ref:`download_library` :ref:`getting_started` `Open Github `_ `Donate `_ 16 | 17 | Features 18 | ^^^^^^^^ 19 | 20 | * Written in C (C11), compatible with ``size_t`` and ``uintmax_t`` types for some specifiers 21 | * Implements output functions compatible with ``printf``, ``vprintf``, ``snprintf``, ``sprintf`` and ``vsnprintf`` 22 | * Low-memory footprint, suitable for embedded systems 23 | * Reentrant access to all API functions 24 | * Operating-system ready 25 | * Requires single output function to be implemented by user for ``printf``-like API calls 26 | * With optional functions for operating systems to protect multiple threads printing to the same output stream 27 | * Allows multiple output stream functions (unlike standard ``printf`` which supports only one) to separate parts of application 28 | * Added additional specifiers vs original features 29 | * User friendly MIT license 30 | 31 | Requirements 32 | ^^^^^^^^^^^^ 33 | 34 | * C compiler 35 | * Few kB of non-volatile memory 36 | 37 | Contribute 38 | ^^^^^^^^^^ 39 | 40 | Fresh contributions are always welcome. Simple instructions to proceed: 41 | 42 | #. Fork Github repository 43 | #. Respect `C style & coding rules `_ used by the library 44 | #. Create a pull request to ``develop`` branch with new features or bug fixes 45 | 46 | Alternatively you may: 47 | 48 | #. Report a bug 49 | #. Ask for a feature request 50 | 51 | License 52 | ^^^^^^^ 53 | 54 | .. literalinclude:: ../LICENSE 55 | 56 | Table of contents 57 | ^^^^^^^^^^^^^^^^^ 58 | 59 | .. toctree:: 60 | :maxdepth: 2 61 | :caption: Contents 62 | 63 | self 64 | get-started/index 65 | user-manual/index 66 | api-reference/index 67 | test-results/index 68 | examples/index 69 | changelog/index 70 | authors/index 71 | 72 | .. toctree:: 73 | :maxdepth: 2 74 | :caption: Other projects 75 | :hidden: 76 | 77 | LwBTN - Button manager 78 | LwDTC - DateTimeCron 79 | LwESP - ESP-AT library 80 | LwEVT - Event manager 81 | LwGPS - GPS NMEA parser 82 | LwCELL - Cellular modem host AT library 83 | LwJSON - JSON parser 84 | LwMEM - Memory manager 85 | LwOW - OneWire with UART 86 | LwPKT - Packet protocol 87 | LwPRINTF - Printf 88 | LwRB - Ring buffer 89 | LwSHELL - Shell 90 | LwUTIL - Utility functions 91 | LwWDG - RTOS task watchdog 92 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx>=3.5.1 2 | breathe>=4.9.1 3 | urllib3==1.26.18 4 | docutils==0.16 5 | colorama 6 | sphinx_rtd_theme>=1.0.0 7 | sphinx-tabs 8 | sphinxcontrib-svg2pdfconverter 9 | sphinx-sitemap 10 | -------------------------------------------------------------------------------- /docs/static/css/common.css: -------------------------------------------------------------------------------- 1 | /* Center aligned text */ 2 | .center { 3 | text-align: center; 4 | } 5 | 6 | /* Paragraph with main links on index page */ 7 | .index-links { 8 | text-align: center; 9 | margin-top: 10px; 10 | } 11 | .index-links a { 12 | display: inline-block; 13 | border: 1px solid #0E4263; 14 | padding: 5px 20px; 15 | margin: 2px 5px; 16 | background: #2980B9; 17 | border-radius: 4px; 18 | color: #FFFFFF; 19 | } 20 | .index-links a:hover, .index-links a:active { 21 | background: #0E4263; 22 | } 23 | 24 | /* Table header p w/0 margin */ 25 | .index-links a table thead th { 26 | vertical-align: middle; 27 | } 28 | 29 | table thead th p { 30 | margin: 0; 31 | } 32 | 33 | .table-nowrap td { 34 | white-space: normal !important; 35 | } 36 | 37 | /* Breathe output changes */ 38 | .breathe-sectiondef.container { 39 | background: #f9f9f9; 40 | padding: 10px; 41 | margin-bottom: 10px; 42 | border: 1px solid #efefef; 43 | } 44 | .breathe-sectiondef.container .breathe-sectiondef-title { 45 | background: #2980b9; 46 | color: #FFFFFF; 47 | padding: 4px; 48 | margin: -10px -10px 0 -10px; 49 | } 50 | .breathe-sectiondef.container .function, 51 | .breathe-sectiondef.container .member, 52 | .breathe-sectiondef.container .class, 53 | .breathe-sectiondef.container .type { 54 | border-bottom: 1px solid #efefef; 55 | } 56 | .breathe-sectiondef.container .function:last-child, 57 | .breathe-sectiondef.container .member:last-child, 58 | .breathe-sectiondef.container .class:last-child, 59 | .breathe-sectiondef.container .type:last-child { 60 | border-bottom: none; 61 | margin-bottom: 0; 62 | } 63 | 64 | /*# sourceMappingURL=common.css.map */ 65 | -------------------------------------------------------------------------------- /docs/static/css/custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/docs/static/css/custom.css -------------------------------------------------------------------------------- /docs/static/dark-light/checked.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/static/dark-light/common-dark-light.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | :root { 18 | --heading-color: red; 19 | --duration: 0.5s; 20 | --timing: ease; 21 | } 22 | 23 | *, 24 | ::before, 25 | ::after { 26 | box-sizing: border-box; 27 | } 28 | 29 | body { 30 | margin: 0; 31 | transition: 32 | color var(--duration) var(--timing), 33 | background-color var(--duration) var(--timing); 34 | font-family: sans-serif; 35 | font-size: 12pt; 36 | background-color: var(--background-color); 37 | color: var(--text-color); 38 | display: flex; 39 | justify-content: center; 40 | } 41 | 42 | main { 43 | margin: 1rem; 44 | max-width: 30rem; 45 | position: relative; 46 | } 47 | 48 | h1 { 49 | color: var(--heading-color); 50 | text-shadow: 0.1rem 0.1rem 0.1rem var(--shadow-color); 51 | transition: text-shadow var(--duration) var(--timing); 52 | } 53 | 54 | img { 55 | max-width: 100%; 56 | height: auto; 57 | transition: filter var(--duration) var(--timing); 58 | } 59 | 60 | p { 61 | line-height: 1.5; 62 | word-wrap: break-word; 63 | overflow-wrap: break-word; 64 | hyphens: auto; 65 | } 66 | 67 | fieldset { 68 | border: solid 0.1rem; 69 | box-shadow: 0.1rem 0.1rem 0.1rem var(--shadow-color); 70 | transition: box-shadow var(--duration) var(--timing); 71 | } 72 | 73 | div { 74 | padding: 0.5rem; 75 | } 76 | 77 | aside { 78 | position: absolute; 79 | right: 0; 80 | padding: 0.5rem; 81 | } 82 | 83 | aside:nth-of-type(1) { 84 | top: 0; 85 | } 86 | 87 | aside:nth-of-type(2) { 88 | top: 3rem; 89 | } 90 | 91 | aside:nth-of-type(3) { 92 | top: 7rem; 93 | } 94 | 95 | aside:nth-of-type(4) { 96 | top: 12rem; 97 | } 98 | 99 | #content select, 100 | #content button, 101 | #content input[type="text"], 102 | #content input[type="search"] { 103 | width: 15rem; 104 | } 105 | 106 | dark-mode-toggle { 107 | --dark-mode-toggle-remember-icon-checked: url("checked.svg"); 108 | --dark-mode-toggle-remember-icon-unchecked: url("unchecked.svg"); 109 | --dark-mode-toggle-remember-font: 0.75rem "Helvetica"; 110 | --dark-mode-toggle-legend-font: bold 0.85rem "Helvetica"; 111 | --dark-mode-toggle-label-font: 0.85rem "Helvetica"; 112 | --dark-mode-toggle-color: var(--text-color); 113 | --dark-mode-toggle-background-color: none; 114 | 115 | margin-bottom: 1.5rem; 116 | } 117 | 118 | #dark-mode-toggle-1 { 119 | --dark-mode-toggle-dark-icon: url("sun.png"); 120 | --dark-mode-toggle-light-icon: url("moon.png"); 121 | } 122 | 123 | #dark-mode-toggle-2 { 124 | --dark-mode-toggle-dark-icon: url("sun.svg"); 125 | --dark-mode-toggle-light-icon: url("moon.svg"); 126 | --dark-mode-toggle-icon-size: 2rem; 127 | --dark-mode-toggle-icon-filter: invert(100%); 128 | } 129 | 130 | #dark-mode-toggle-3, 131 | #dark-mode-toggle-4 { 132 | --dark-mode-toggle-dark-icon: url("moon.png"); 133 | --dark-mode-toggle-light-icon: url("sun.png"); 134 | } 135 | 136 | #dark-mode-toggle-3 { 137 | --dark-mode-toggle-remember-filter: invert(100%); 138 | } 139 | 140 | #dark-mode-toggle-4 { 141 | --dark-mode-toggle-active-mode-background-color: var(--accent-color); 142 | --dark-mode-toggle-remember-filter: invert(100%); 143 | } 144 | -------------------------------------------------------------------------------- /docs/static/dark-light/dark.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | :root { 18 | color-scheme: dark; /* stylelint-disable-line property-no-unknown */ 19 | 20 | --background-color: rgb(15 15 15); 21 | --text-color: rgb(240 240 240); 22 | --shadow-color: rgb(240 240 240 / 50%); 23 | --accent-color: rgb(0 0 240 / 50%); 24 | } 25 | 26 | img { 27 | filter: grayscale(50%); 28 | } 29 | 30 | .icon { 31 | filter: invert(100%); 32 | } 33 | 34 | a { 35 | color: yellow; 36 | } 37 | -------------------------------------------------------------------------------- /docs/static/dark-light/light.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | :root { 18 | color-scheme: light; /* stylelint-disable-line property-no-unknown */ 19 | 20 | --background-color: rgb(240 240 240); 21 | --text-color: rgb(15 15 15); 22 | --shadow-color: rgb(15 15 15 / 50%); 23 | --accent-color: rgb(240 0 0 / 50%); 24 | } 25 | -------------------------------------------------------------------------------- /docs/static/dark-light/moon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/docs/static/dark-light/moon.png -------------------------------------------------------------------------------- /docs/static/dark-light/moon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | moon 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /docs/static/dark-light/sun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/docs/static/dark-light/sun.png -------------------------------------------------------------------------------- /docs/static/dark-light/sun.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /docs/static/dark-light/unchecked.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/static/images/logo.drawio: -------------------------------------------------------------------------------- 1 | jZJNb8MgDIZ/TY6VSGir5dqu7aZ10bRO6hkFN6BBiCgZ6X79yIB8qJq0C8KPjbFfO8Fb2R00adiroiCSDNEuwY9JlmGUubMHNw+yde5BpTn1KB3BiX9DgCjQllO4zgKNUsLwZg5LVddQmhkjWis7D7soMf+1IRXcgVNJxD09c2qYpw8rNPIn4BWLP6coeCSJwQFcGaHKThDeJXirlTL+JrstiF67qIt/t//DOxSmoTb/eVAs6BJyaY+FbDfL/OUizukiZPkiog0NH+3b+3PxsQ9Fm1tUQqu2ptAnSxO8sYwbODWk7L3Wjd4xZqQI7qvR6nNQbO3IRdUmjBf39iAHcsZ9L7Ew0Aa6CQq9HUBJMPrmQuKmLVf+SVy0aNtxbBkKjE1GFkdJwqZUQ+pRTHcJekZznNuvb7L8ePcD -------------------------------------------------------------------------------- /docs/static/images/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
LwPRINTF
LwPRINTF
-------------------------------------------------------------------------------- /docs/static/images/logo_tm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/docs/static/images/logo_tm.png -------------------------------------------------------------------------------- /docs/static/images/logo_tm_full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/docs/static/images/logo_tm_full.png -------------------------------------------------------------------------------- /docs/test-results/index.rst: -------------------------------------------------------------------------------- 1 | .. _test_results: 2 | 3 | Test results 4 | ============ 5 | 6 | Library is put under several tests to ensure correct output format. 7 | Results are underneath with information about number of passed and failed tests. 8 | 9 | .. note:: 10 | Majority of failed tests are linked to precision digits with floating-point based specifiers. 11 | This is considered as *OK* since failures are visible at higher number of precision digits, 12 | not affecting final results. Keep in mind that effective number of precision digits 13 | with ``float`` type is ``7`` and for ``double`` is ``15``. 14 | 15 | With the exception to additional specifiers, supported only by *LwPRINTF* library, 16 | all tests are compared against ``stdio printf`` library included in *Microsoft Visual Studio C/C++ compiler*. 17 | 18 | .. literalinclude:: ../../tests/test_results.test 19 | :encoding: utf-16 20 | :linenos: 21 | :caption: Test results of the library 22 | 23 | .. toctree:: 24 | :maxdepth: 2 25 | -------------------------------------------------------------------------------- /docs/user-manual/how-it-works.rst: -------------------------------------------------------------------------------- 1 | .. _how_it_works: 2 | 3 | How it works 4 | ============ 5 | 6 | LwPRINTF library supports ``2`` different formatting output types: 7 | 8 | * Write formatted data to user input array 9 | * Directly print formatted characters by calling ``output_function`` for every formatted character in the input string 10 | 11 | Text formatting is based on input format string followed by the data parameters. 12 | It is mostly used to prepare numeric data types to human readable format. 13 | 14 | .. note:: 15 | LwPRINTF is open-source implementation of regular *stdio.h* library in C language. 16 | It implements only output functions, excluding input scanning features 17 | 18 | Formatting functions take input *format string* followed by (optional) different data types. 19 | Internal algorithm scans character by character to understand type of expected data user would like to have printed. 20 | 21 | Every format specifier starts with letter ``%``, followed by optional set of flags, widths and other sets of characters. 22 | Last part of every specifier is its type, that being type of format and data to display. 23 | 24 | .. tip:: 25 | To print number ``1234`` in human readable format, use specifier ``%d``. 26 | With default configuration, call ``lwprintf_printf("%d", 1234);`` and it will print ``"1234"``. 27 | 28 | Check section :ref:`um_format_specifier` for list of all formats and data types 29 | 30 | Character output function 31 | ************************* 32 | 33 | API functions printing characters directly to the output stream (ex. :c:macro:`lwprintf_printf`), 34 | require output function to be set during initialization procedure. 35 | 36 | Output function is called by the API for every character to be printed/transmitted by the application. 37 | 38 | .. note:: 39 | Output function is set during initialization procedure. 40 | If not set (set as ``NULL``), it is not possible to use API function which directly print 41 | characters to output stream. Application is then limited only to API functions 42 | that write formatted data to input buffer. 43 | 44 | Notes to consider: 45 | 46 | * Output function must return same character as it was used as an input parameter to consider successful print 47 | * Output function will receive ``(int)'\0'`` character to indicate no more characters will follow in this API call 48 | * Single output function may be used for different LwPRINTF instances 49 | 50 | .. literalinclude:: ../examples_src/example_minimal.c 51 | :language: c 52 | :linenos: 53 | :caption: Absolute minimum example to support direct output 54 | 55 | .. toctree:: 56 | :maxdepth: 2 -------------------------------------------------------------------------------- /docs/user-manual/index.rst: -------------------------------------------------------------------------------- 1 | .. _um: 2 | 3 | User manual 4 | =========== 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | how-it-works 10 | format-specifier 11 | instances 12 | thread-safety -------------------------------------------------------------------------------- /docs/user-manual/instances.rst: -------------------------------------------------------------------------------- 1 | .. _lwprintf_instances: 2 | 3 | LwPRINTF instances 4 | ================== 5 | 6 | LwPRINTF is very flexible and allows multiple instances for output print functions. 7 | 8 | .. note:: 9 | Multiple instances with LwPRINTF are useful only with direct 10 | print functions, suchs as :c:macro:`lwprintf_printf`. 11 | If application uses only format functions which write to input buffer, 12 | it may always use default LwPRINTF instance which is 13 | created by the library itself 14 | 15 | Use of different instances is useful if application needs different print 16 | configurations. Each instance has its own ``print_output`` function, 17 | allowing application to use multiple debug configurations (as an example) 18 | 19 | .. tip:: 20 | Use functions with ``_ex`` suffix to direcly work with custom instances. 21 | Functions without ``_ex`` suffix use default LwPRINTF instance 22 | 23 | .. literalinclude:: ../examples_src/example_instance.c 24 | :language: c 25 | :linenos: 26 | :caption: Custom LwPRINTF instance for output 27 | 28 | .. note:: 29 | It is perfectly valid to use single output function for all application instances. 30 | Use check against input parameter for :c:type:`lwprintf_t` if it matches your custom LwPRINTF instance memory address 31 | 32 | .. literalinclude:: ../examples_src/example_instance_single_func.c 33 | :language: c 34 | :linenos: 35 | :caption: Single output function for all LwPRINTF instances 36 | 37 | .. toctree:: 38 | :maxdepth: 2 -------------------------------------------------------------------------------- /docs/user-manual/thread-safety.rst: -------------------------------------------------------------------------------- 1 | .. _thread_safety: 2 | 3 | Thread safety 4 | ============= 5 | 6 | LwPRINTF uses re-entrant functions, especially the one that format string to user application buffer. 7 | It is fully allowed to access to the same LwPRINTF instance from multiple operating-system threads. 8 | 9 | However, when it comes to direct print functions, such as :cpp:func:`lwprintf_printf_ex` (or any other similar), 10 | calling those functions from multiple threads may introduce mixed output stream of data. 11 | 12 | This is due to the fact that direct printing functions use same output function 13 | to print single character. When called from multiple threads, one thread 14 | may preempt another, causing strange output string. 15 | 16 | .. literalinclude:: ../examples_src/example_multi_thread_corrupted_text.c 17 | :language: c 18 | :linenos: 19 | :caption: Multiple threads printing at the same time without thread-safety enabled 20 | 21 | LwPRINTF therefore comes with a solution that introduces mutexes to lock print functions 22 | when in use from within single thread context. 23 | 24 | .. note:: 25 | If application does not have any issues concerning mixed output, 26 | it is safe to disable OS support in OS environment. 27 | This will not have any negative effect on performance or memory corruption. 28 | 29 | .. tip:: 30 | To enable thread-safety support, parameter ``LWPRINTF_CFG_OS`` must be set to ``1``. 31 | Please check :ref:`api_lwprintf_opt` for more information about other options. 32 | 33 | After thread-safety features has been enabled, it is necessary to implement 34 | ``4`` low-level system functions. 35 | 36 | .. tip:: 37 | System function template example is available in ``lwprintf/src/system/`` folder. 38 | 39 | Example code for ``CMSIS-OS V2`` 40 | 41 | .. note:: 42 | Check :ref:`api_lwprintf_sys` section for function description 43 | 44 | .. literalinclude:: ../../lwprintf/src/system/lwprintf_sys_cmsis_os.c 45 | :language: c 46 | :linenos: 47 | :caption: System function implementation for CMSIS-OS based operating systems 48 | 49 | .. toctree:: 50 | :maxdepth: 2 -------------------------------------------------------------------------------- /examples/additional_format_specifiers.c: -------------------------------------------------------------------------------- 1 | /* List of specifiers added in the library which are not available in standard printf implementation */ 2 | 3 | #include "lwprintf/lwprintf.h" 4 | 5 | /** 6 | * \brief List of additional specifiers to print 7 | */ 8 | void 9 | additional_format_specifiers(void) { 10 | unsigned char my_array[] = { 0x01, 0x02, 0xA4, 0xB5, 0xC6 }; 11 | 12 | /* Binary output */ 13 | 14 | /* Prints number 8 in binary format, so "1000" */ 15 | lwprintf_printf("%b\r\n", 8U); 16 | /* Prints number 16 in binary format with 10 places, so " 10000" */ 17 | lwprintf_printf("%10b\r\n", 16U); 18 | /* Prints number 16 in binary format with 10 places, leading zeros, so "0000010000" */ 19 | lwprintf_printf("%010b\r\n", 16U); 20 | 21 | /* Array outputs */ 22 | 23 | /* Fixed length with uppercase hex numbers, outputs "0102A4B5C6" */ 24 | lwprintf_printf("%5K\r\n", my_array); 25 | /* Fixed length with lowercase hex numbers, outputs "0102a4b5c6" */ 26 | lwprintf_printf("%5k\r\n", my_array); 27 | /* Variable length with uppercase letters, outputs "0102A4B5C6" */ 28 | lwprintf_printf("%*K\r\n", (int)LWPRINTF_ARRAYSIZE(my_array), my_array); 29 | /* Variable length with lowercase letters, outputs "0102a4b5c6" */ 30 | lwprintf_printf("%*k\r\n", (int)LWPRINTF_ARRAYSIZE(my_array), my_array); 31 | /* Variable length with uppercase letters and spaces, outputs "01 02 A4 B5 C6" */ 32 | lwprintf_printf("% *K\r\n", (int)LWPRINTF_ARRAYSIZE(my_array), my_array); 33 | /* Variable length with uppercase letters and spaces, outputs "01 02 a4 b5 c6" */ 34 | lwprintf_printf("% *k\r\n", (int)LWPRINTF_ARRAYSIZE(my_array), my_array); 35 | } -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lwprintf_stm32l432kc_nucleo 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature 24 | org.eclipse.cdt.core.cnature 25 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature 26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature 27 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 28 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 29 | com.st.stm32cube.ide.mcu.MCURootProjectNature 30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 32 | 33 | 34 | 35 | lwprintf/lwprintf.c 36 | 1 37 | PARENT-3-PROJECT_LOC/lwprintf/src/lwprintf/lwprintf.c 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 4, 3 | "configurations": [ 4 | { 5 | /* 6 | * ms-vscode.cmake-tools plugin should be installed. 7 | * 8 | * It provides data for C/C++ plugin, 9 | * such as include paths, browse paths, defines, etc. 10 | */ 11 | "name": "STM32", 12 | "configurationProvider": "ms-vscode.cmake-tools", 13 | "intelliSenseMode": "${default}" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-vscode.cpptools", 4 | "ms-vscode.cmake-tools", 5 | "marus25.cortex-debug", 6 | "twxs.cmake", 7 | "dan-c-underwood.arm", 8 | "zixuanwang.linkerscript" 9 | ] 10 | } -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Debug Microcontroller - ST-Link", 9 | "cwd": "${workspaceFolder}", 10 | "type": "cortex-debug", 11 | "executable": "${command:cmake.launchTargetPath}", //or fixed file path: build/stm32h735g-dk-led.elf 12 | "request": "launch", //Use "attach" to connect to target w/o elf download 13 | "servertype": "stlink", 14 | "device": "", //MCU used, ex. "STM32H735IG" 15 | "interface": "swd", 16 | "serialNumber": "", //Set ST-Link ID if you use multiple at the same time 17 | "runToMain": true, 18 | "svdFile": "path/to/file.svd", //Path to SVD file to see registers 19 | "v1": false, 20 | "showDevDebugOutput": "both", 21 | 22 | /* Will get automatically detected if STM32CubeIDE is installed to default directory 23 | or it can be manually provided if necessary.. */ 24 | //"serverpath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.0.100.202109301221\\tools\\bin\\ST-LINK_gdbserver.exe", 25 | //"armToolchainPath": "c:\\ST\\STM32CubeIDE_1.7.0\\STM32CubeIDE\\plugins\\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\\tools\\bin", 26 | //"stm32cubeprogrammer": "c:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin", 27 | 28 | /* If you use external loader, add additional arguments */ 29 | //"serverArgs": ["--extload", "path/to/ext/loader.stldr"], 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "cppbuild", 6 | "label": "Build project", 7 | "command": "cmake", 8 | "args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"], 9 | "options": { 10 | "cwd": "${workspaceFolder}" 11 | }, 12 | "problemMatcher": ["$gcc"], 13 | "group": { 14 | "kind": "build", 15 | "isDefault": true 16 | } 17 | }, 18 | { 19 | "type": "shell", 20 | "label": "Re-build project", 21 | "command": "cmake", 22 | "args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"], 23 | "options": { 24 | "cwd": "${workspaceFolder}" 25 | }, 26 | "problemMatcher": ["$gcc"], 27 | }, 28 | { 29 | "type": "shell", 30 | "label": "Clean project", 31 | "command": "cmake", 32 | "args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"], 33 | "options": { 34 | "cwd": "${workspaceFolder}" 35 | }, 36 | "problemMatcher": [] 37 | }, 38 | { 39 | "type": "shell", 40 | "label": "CubeProg: Flash project (SWD)", 41 | "command": "STM32_Programmer_CLI", 42 | "args": [ 43 | "--connect", 44 | "port=swd", 45 | "--download", "${command:cmake.launchTargetPath}", 46 | "-hardRst" 47 | ], 48 | "options": { 49 | "cwd": "${workspaceFolder}" 50 | }, 51 | "problemMatcher": [] 52 | }, 53 | { 54 | "type": "shell", 55 | "label": "CubeProg: Flash project with defined serial number (SWD) - you must set serial number first", 56 | "command": "STM32_Programmer_CLI", 57 | "args": [ 58 | "--connect", 59 | "port=swd", 60 | "sn=", 61 | "--download", "${command:cmake.launchTargetPath}", 62 | "-hardRst" 63 | ], 64 | "options": { 65 | "cwd": "${workspaceFolder}" 66 | }, 67 | "problemMatcher": [] 68 | }, 69 | { 70 | "type": "shell", 71 | "label": "CubeProg: List all available communication interfaces", 72 | "command": "STM32_Programmer_CLI", 73 | "args": [ 74 | "--list", 75 | ], 76 | "options": { 77 | "cwd": "${workspaceFolder}" 78 | }, 79 | "problemMatcher": [] 80 | }, 81 | ] 82 | } 83 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | 3 | # 4 | # Core project settings 5 | # 6 | set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) 7 | project(lwprintf_stm32l432kc_nucleo) 8 | enable_language(C CXX ASM) 9 | message("Build type: " ${CMAKE_BUILD_TYPE}) 10 | 11 | # Setup compiler settings 12 | set(CMAKE_C_STANDARD 11) 13 | set(CMAKE_C_STANDARD_REQUIRED ON) 14 | set(CMAKE_C_EXTENSIONS ON) 15 | set(CMAKE_CXX_STANDARD 20) 16 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 17 | set(CMAKE_CXX_EXTENSIONS ON) 18 | 19 | # 20 | # Core MCU flags, CPU, instruction set and FPU setup 21 | # 22 | set(CPU_PARAMETERS 23 | -mthumb 24 | # Other parameters 25 | # -mcpu, -mfloat, -mfloat-abi, ... 26 | -mcpu=cortex-m4 27 | -mfpu=fpv4-sp-d16 28 | -mfloat-abi=hard 29 | ) 30 | 31 | # Set linker script 32 | set(linker_script_SRC ${PROJ_PATH}/STM32L412KBUX_FLASH.ld) 33 | set(EXECUTABLE ${CMAKE_PROJECT_NAME}) 34 | 35 | # 36 | # Source files 37 | # 38 | set(src_lwprintf_SRCS 39 | ${PROJ_PATH}/../../../lwprintf/src/lwprintf/lwprintf.c) 40 | 41 | set(src_core_src_SRCS 42 | ${PROJ_PATH}/Core/Src/main.c 43 | ${PROJ_PATH}/Core/Src/stm32l4xx_hal_msp.c 44 | ${PROJ_PATH}/Core/Src/stm32l4xx_it.c 45 | ${PROJ_PATH}/Core/Src/syscalls.c 46 | ${PROJ_PATH}/Core/Src/sysmem.c 47 | ${PROJ_PATH}/Core/Src/system_stm32l4xx.c) 48 | 49 | set(src_core_startup_SRCS 50 | ${PROJ_PATH}/Core/Startup/startup_stm32l412kbux.s) 51 | 52 | set(src_drivers_stm32l4xx_hal_driver_src_SRCS 53 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c 54 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c 55 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c 56 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c 57 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c 58 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c 59 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c 60 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c 61 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c 62 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c 63 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c 64 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c 65 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c 66 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c 67 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c 68 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c 69 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c 70 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c 71 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c) 72 | 73 | # 74 | # Include directories 75 | # 76 | set(include_c_DIRS 77 | ${PROJ_PATH}/Core/Inc 78 | ${PROJ_PATH}/../../../lwprintf/src/include 79 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Inc 80 | ${PROJ_PATH}/Drivers/STM32L4xx_HAL_Driver/Inc/Legacy 81 | ${PROJ_PATH}/Drivers/CMSIS/Device/ST/STM32L4xx/Include 82 | ${PROJ_PATH}/Drivers/CMSIS/Include 83 | ) 84 | set(include_cxx_DIRS 85 | 86 | ) 87 | set(include_asm_DIRS 88 | 89 | ) 90 | 91 | # 92 | # Symbols definition 93 | # 94 | set(symbols_c_SYMB 95 | "USE_HAL_DRIVER" 96 | "STM32L412xx" 97 | "DEBUG" 98 | ) 99 | set(symbols_cxx_SYMB 100 | 101 | ) 102 | set(symbols_asm_SYMB 103 | 104 | ) 105 | 106 | # 107 | # Link directories setup 108 | # Must be before executable is added 109 | # 110 | set(link_DIRS 111 | 112 | ) 113 | link_directories(${EXECUTABLE} ${link_DIRS}) 114 | 115 | # 116 | # Executable files 117 | # 118 | add_executable(${EXECUTABLE} 119 | ${src_lwprintf_SRCS} 120 | ${src_core_src_SRCS} 121 | ${src_core_startup_SRCS} 122 | ${src_drivers_stm32l4xx_hal_driver_src_SRCS}) 123 | 124 | # 125 | # Add linked libraries for linker 126 | # 127 | set(link_LIBS 128 | 129 | ) 130 | target_link_libraries(${EXECUTABLE} ${link_LIBS}) 131 | 132 | # 133 | # Project symbols 134 | # 135 | target_compile_definitions(${EXECUTABLE} PRIVATE 136 | # Language specific only 137 | $<$: ${symbols_c_SYMB}> 138 | $<$: ${symbols_cxx_SYMB}> 139 | $<$: ${symbols_asm_SYMB}> 140 | 141 | # Configuration specific 142 | $<$: 143 | DEBUG 144 | > 145 | $<$: > 146 | ) 147 | 148 | # 149 | # Add include paths for each of the compiler 150 | # 151 | target_include_directories(${EXECUTABLE} PRIVATE 152 | # Language specific only 153 | $<$: ${include_c_DIRS}> 154 | $<$: ${include_cxx_DIRS}> 155 | $<$: ${include_asm_DIRS}> 156 | 157 | # Configuration specific 158 | $<$: > 159 | $<$: > 160 | ) 161 | 162 | # Compiler and linker options 163 | target_compile_options(${EXECUTABLE} PRIVATE 164 | ${CPU_PARAMETERS} 165 | -Wall 166 | -Wextra 167 | -Wpedantic 168 | -Wno-unused-parameter 169 | $<$: 170 | 171 | > 172 | $<$: 173 | #-Wno-volatile 174 | #-Wold-style-cast 175 | #-Wuseless-cast 176 | #-Wsuggest-override 177 | > 178 | $<$: 179 | -x assembler-with-cpp 180 | -MMD 181 | -MP 182 | > 183 | $<$: 184 | -Og -g3 -ggdb 185 | > 186 | $<$: 187 | -Og -g0 188 | > 189 | ) 190 | 191 | # Setup linker parameters 192 | target_link_options(${EXECUTABLE} PRIVATE 193 | -T${linker_script_SRC} 194 | ${CPU_PARAMETERS} 195 | -Wl,-Map=${CMAKE_PROJECT_NAME}.map 196 | -u _printf_float # STDIO float formatting support (remove if not used) 197 | --specs=nosys.specs 198 | -Wl,--start-group 199 | -lc 200 | -lm 201 | -lstdc++ 202 | -lsupc++ 203 | -Wl,--end-group 204 | -Wl,--print-memory-usage 205 | ) 206 | 207 | # Execute post-build to print size 208 | add_custom_command(TARGET ${EXECUTABLE} POST_BUILD 209 | COMMAND ${CMAKE_SIZE} $ 210 | ) 211 | 212 | # Convert output to hex and binary 213 | add_custom_command(TARGET ${EXECUTABLE} POST_BUILD 214 | COMMAND ${CMAKE_OBJCOPY} -O ihex $ ${EXECUTABLE}.hex 215 | ) 216 | 217 | # Convert to bin file -> add conditional check? 218 | add_custom_command(TARGET ${EXECUTABLE} POST_BUILD 219 | COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin 220 | ) 221 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "default", 6 | "hidden": true, 7 | "generator": "Ninja", 8 | "binaryDir": "${sourceDir}/build/${presetName}", 9 | "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake", 10 | "cacheVariables": { 11 | "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" 12 | } 13 | }, 14 | { 15 | "name": "Debug", 16 | "inherits": "default", 17 | "cacheVariables": { 18 | "CMAKE_BUILD_TYPE": "Debug" 19 | } 20 | }, 21 | { 22 | "name": "RelWithDebInfo", 23 | "inherits": "default", 24 | "cacheVariables": { 25 | "CMAKE_BUILD_TYPE": "RelWithDebInfo" 26 | } 27 | }, 28 | { 29 | "name": "Release", 30 | "inherits": "default", 31 | "cacheVariables": { 32 | "CMAKE_BUILD_TYPE": "Release" 33 | } 34 | }, 35 | { 36 | "name": "MinSizeRel", 37 | "inherits": "default", 38 | "cacheVariables": { 39 | "CMAKE_BUILD_TYPE": "MinSizeRel" 40 | } 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/lwprintf_opts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_opts.h 3 | * \brief LwPRINTF configuration file 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #ifndef LWPRINTF_HDR_OPTS_H 35 | #define LWPRINTF_HDR_OPTS_H 36 | 37 | #endif /* LWPRINTF_HDR_OPTS_H */ 38 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2020 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32l4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | /* USER CODE BEGIN Private defines */ 62 | 63 | /* USER CODE END Private defines */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __MAIN_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Inc/stm32l4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32l4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32L4xx_IT_H 23 | #define __STM32L4xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void PendSV_Handler(void); 58 | void SysTick_Handler(void); 59 | /* USER CODE BEGIN EFP */ 60 | 61 | /* USER CODE END EFP */ 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __STM32L4xx_IT_H */ 68 | 69 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 70 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | #include "lwprintf/lwprintf.h" 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN PTD */ 30 | 31 | /* USER CODE END PTD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | UART_HandleTypeDef huart2; 44 | 45 | /* USER CODE BEGIN PV */ 46 | 47 | /* USER CODE END PV */ 48 | 49 | /* Private function prototypes -----------------------------------------------*/ 50 | void SystemClock_Config(void); 51 | static void MX_GPIO_Init(void); 52 | static void MX_USART2_UART_Init(void); 53 | /* USER CODE BEGIN PFP */ 54 | 55 | /* USER CODE END PFP */ 56 | 57 | /* Private user code ---------------------------------------------------------*/ 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /** 61 | * \brief Output function to handle all characters for print operation 62 | * \param[in] ch: Character to output 63 | * \param[in] p: \ref lwprintf_t handle 64 | * \return ch on success, 0 on failure 65 | */ 66 | static int 67 | lwprintf_my_out_func(int ch, lwprintf_t* p) { 68 | uint8_t c = (uint8_t)ch; 69 | 70 | /* Don't print zero */ 71 | if (c == '\0') { 72 | return ch; 73 | } 74 | HAL_UART_Transmit(&huart2, &c, 1, 100); 75 | return ch; 76 | } 77 | 78 | /* USER CODE END 0 */ 79 | 80 | /** 81 | * @brief The application entry point. 82 | * @retval int 83 | */ 84 | int 85 | main(void) { 86 | /* USER CODE BEGIN 1 */ 87 | uint32_t my_int; 88 | /* USER CODE END 1 */ 89 | 90 | /* MCU Configuration--------------------------------------------------------*/ 91 | 92 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 93 | HAL_Init(); 94 | 95 | /* USER CODE BEGIN Init */ 96 | 97 | /* USER CODE END Init */ 98 | 99 | /* Configure the system clock */ 100 | SystemClock_Config(); 101 | 102 | /* USER CODE BEGIN SysInit */ 103 | 104 | /* USER CODE END SysInit */ 105 | 106 | /* Initialize all configured peripherals */ 107 | MX_GPIO_Init(); 108 | MX_USART2_UART_Init(); 109 | /* USER CODE BEGIN 2 */ 110 | 111 | /* Initialize library */ 112 | lwprintf_init(lwprintf_my_out_func); 113 | 114 | /* Print formatted data */ 115 | lwprintf_printf("My first string: %s\r\n", "Hello world"); 116 | lwprintf_printf("My first digits: %d\r\n", 10); 117 | lwprintf_printf("My first pointer: %p\r\n", &my_int); 118 | /* USER CODE END 2 */ 119 | 120 | /* Infinite loop */ 121 | /* USER CODE BEGIN WHILE */ 122 | while (1) { 123 | /* USER CODE END WHILE */ 124 | 125 | /* USER CODE BEGIN 3 */ 126 | } 127 | /* USER CODE END 3 */ 128 | } 129 | 130 | /** 131 | * @brief System Clock Configuration 132 | * @retval None 133 | */ 134 | void 135 | SystemClock_Config(void) { 136 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 137 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 138 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 139 | 140 | /** Configure LSE Drive Capability 141 | */ 142 | HAL_PWR_EnableBkUpAccess(); 143 | __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); 144 | /** Configure the main internal regulator output voltage 145 | */ 146 | if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) { 147 | Error_Handler(); 148 | } 149 | /** Initializes the RCC Oscillators according to the specified parameters 150 | * in the RCC_OscInitTypeDef structure. 151 | */ 152 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI; 153 | RCC_OscInitStruct.LSEState = RCC_LSE_ON; 154 | RCC_OscInitStruct.MSIState = RCC_MSI_ON; 155 | RCC_OscInitStruct.MSICalibrationValue = 0; 156 | RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; 157 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 158 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { 159 | Error_Handler(); 160 | } 161 | /** Initializes the CPU, AHB and APB buses clocks 162 | */ 163 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK 164 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; 165 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI; 166 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 167 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 168 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 169 | 170 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { 171 | Error_Handler(); 172 | } 173 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2; 174 | PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; 175 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { 176 | Error_Handler(); 177 | } 178 | /** Enable MSI Auto calibration 179 | */ 180 | HAL_RCCEx_EnableMSIPLLMode(); 181 | } 182 | 183 | /** 184 | * @brief USART2 Initialization Function 185 | * @param None 186 | * @retval None 187 | */ 188 | static void 189 | MX_USART2_UART_Init(void) { 190 | 191 | /* USER CODE BEGIN USART2_Init 0 */ 192 | 193 | /* USER CODE END USART2_Init 0 */ 194 | 195 | /* USER CODE BEGIN USART2_Init 1 */ 196 | 197 | /* USER CODE END USART2_Init 1 */ 198 | huart2.Instance = USART2; 199 | huart2.Init.BaudRate = 115200; 200 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 201 | huart2.Init.StopBits = UART_STOPBITS_1; 202 | huart2.Init.Parity = UART_PARITY_NONE; 203 | huart2.Init.Mode = UART_MODE_TX_RX; 204 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 205 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 206 | huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 207 | huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 208 | if (HAL_UART_Init(&huart2) != HAL_OK) { 209 | Error_Handler(); 210 | } 211 | /* USER CODE BEGIN USART2_Init 2 */ 212 | 213 | /* USER CODE END USART2_Init 2 */ 214 | 215 | } 216 | 217 | /** 218 | * @brief GPIO Initialization Function 219 | * @param None 220 | * @retval None 221 | */ 222 | static void 223 | MX_GPIO_Init(void) { 224 | 225 | /* GPIO Ports Clock Enable */ 226 | __HAL_RCC_GPIOC_CLK_ENABLE(); 227 | __HAL_RCC_GPIOA_CLK_ENABLE(); 228 | 229 | } 230 | 231 | /* USER CODE BEGIN 4 */ 232 | 233 | /* USER CODE END 4 */ 234 | 235 | /** 236 | * @brief This function is executed in case of error occurrence. 237 | * @retval None 238 | */ 239 | void 240 | Error_Handler(void) { 241 | /* USER CODE BEGIN Error_Handler_Debug */ 242 | /* User can add his own implementation to report the HAL error return state */ 243 | 244 | /* USER CODE END Error_Handler_Debug */ 245 | } 246 | 247 | #ifdef USE_FULL_ASSERT 248 | /** 249 | * @brief Reports the name of the source file and the source line number 250 | * where the assert_param error has occurred. 251 | * @param file: pointer to the source file name 252 | * @param line: assert_param error line source number 253 | * @retval None 254 | */ 255 | void 256 | assert_failed(uint8_t* file, uint32_t line) { 257 | /* USER CODE BEGIN 6 */ 258 | /* User can add his own implementation to report the file name and line number, 259 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 260 | /* USER CODE END 6 */ 261 | } 262 | #endif /* USE_FULL_ASSERT */ 263 | 264 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 265 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Src/stm32l4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32l4xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2020 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void 65 | HAL_MspInit(void) { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | 75 | /* USER CODE BEGIN MspInit 1 */ 76 | 77 | /* USER CODE END MspInit 1 */ 78 | } 79 | 80 | /** 81 | * @brief UART MSP Initialization 82 | * This function configures the hardware resources used in this example 83 | * @param huart: UART handle pointer 84 | * @retval None 85 | */ 86 | void 87 | HAL_UART_MspInit(UART_HandleTypeDef* huart) { 88 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 89 | if (huart->Instance == USART2) { 90 | /* USER CODE BEGIN USART2_MspInit 0 */ 91 | 92 | /* USER CODE END USART2_MspInit 0 */ 93 | /* Peripheral clock enable */ 94 | __HAL_RCC_USART2_CLK_ENABLE(); 95 | 96 | __HAL_RCC_GPIOA_CLK_ENABLE(); 97 | /**USART2 GPIO Configuration 98 | PA2 ------> USART2_TX 99 | PA3 ------> USART2_RX 100 | */ 101 | GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; 102 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 103 | GPIO_InitStruct.Pull = GPIO_NOPULL; 104 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 105 | GPIO_InitStruct.Alternate = GPIO_AF7_USART2; 106 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 107 | 108 | /* USER CODE BEGIN USART2_MspInit 1 */ 109 | 110 | /* USER CODE END USART2_MspInit 1 */ 111 | } 112 | 113 | } 114 | 115 | /** 116 | * @brief UART MSP De-Initialization 117 | * This function freeze the hardware resources used in this example 118 | * @param huart: UART handle pointer 119 | * @retval None 120 | */ 121 | void 122 | HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { 123 | if (huart->Instance == USART2) { 124 | /* USER CODE BEGIN USART2_MspDeInit 0 */ 125 | 126 | /* USER CODE END USART2_MspDeInit 0 */ 127 | /* Peripheral clock disable */ 128 | __HAL_RCC_USART2_CLK_DISABLE(); 129 | 130 | /**USART2 GPIO Configuration 131 | PA2 ------> USART2_TX 132 | PA3 ------> USART2_RX 133 | */ 134 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); 135 | 136 | /* USER CODE BEGIN USART2_MspDeInit 1 */ 137 | 138 | /* USER CODE END USART2_MspDeInit 1 */ 139 | } 140 | 141 | } 142 | 143 | /* USER CODE BEGIN 1 */ 144 | 145 | /* USER CODE END 1 */ 146 | 147 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 148 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Src/stm32l4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32l4xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "stm32l4xx_it.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | /* USER CODE END 0 */ 57 | 58 | /* External variables --------------------------------------------------------*/ 59 | 60 | /* USER CODE BEGIN EV */ 61 | 62 | /* USER CODE END EV */ 63 | 64 | /******************************************************************************/ 65 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 66 | /******************************************************************************/ 67 | /** 68 | * @brief This function handles Non maskable interrupt. 69 | */ 70 | void 71 | NMI_Handler(void) { 72 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 73 | 74 | /* USER CODE END NonMaskableInt_IRQn 0 */ 75 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 76 | 77 | /* USER CODE END NonMaskableInt_IRQn 1 */ 78 | } 79 | 80 | /** 81 | * @brief This function handles Hard fault interrupt. 82 | */ 83 | void 84 | HardFault_Handler(void) { 85 | /* USER CODE BEGIN HardFault_IRQn 0 */ 86 | 87 | /* USER CODE END HardFault_IRQn 0 */ 88 | while (1) { 89 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 90 | /* USER CODE END W1_HardFault_IRQn 0 */ 91 | } 92 | } 93 | 94 | /** 95 | * @brief This function handles Memory management fault. 96 | */ 97 | void 98 | MemManage_Handler(void) { 99 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 100 | 101 | /* USER CODE END MemoryManagement_IRQn 0 */ 102 | while (1) { 103 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 104 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 105 | } 106 | } 107 | 108 | /** 109 | * @brief This function handles Prefetch fault, memory access fault. 110 | */ 111 | void 112 | BusFault_Handler(void) { 113 | /* USER CODE BEGIN BusFault_IRQn 0 */ 114 | 115 | /* USER CODE END BusFault_IRQn 0 */ 116 | while (1) { 117 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 118 | /* USER CODE END W1_BusFault_IRQn 0 */ 119 | } 120 | } 121 | 122 | /** 123 | * @brief This function handles Undefined instruction or illegal state. 124 | */ 125 | void 126 | UsageFault_Handler(void) { 127 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 128 | 129 | /* USER CODE END UsageFault_IRQn 0 */ 130 | while (1) { 131 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 132 | /* USER CODE END W1_UsageFault_IRQn 0 */ 133 | } 134 | } 135 | 136 | /** 137 | * @brief This function handles System service call via SWI instruction. 138 | */ 139 | void 140 | SVC_Handler(void) { 141 | /* USER CODE BEGIN SVCall_IRQn 0 */ 142 | 143 | /* USER CODE END SVCall_IRQn 0 */ 144 | /* USER CODE BEGIN SVCall_IRQn 1 */ 145 | 146 | /* USER CODE END SVCall_IRQn 1 */ 147 | } 148 | 149 | /** 150 | * @brief This function handles Debug monitor. 151 | */ 152 | void 153 | DebugMon_Handler(void) { 154 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 155 | 156 | /* USER CODE END DebugMonitor_IRQn 0 */ 157 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 158 | 159 | /* USER CODE END DebugMonitor_IRQn 1 */ 160 | } 161 | 162 | /** 163 | * @brief This function handles Pendable request for system service. 164 | */ 165 | void 166 | PendSV_Handler(void) { 167 | /* USER CODE BEGIN PendSV_IRQn 0 */ 168 | 169 | /* USER CODE END PendSV_IRQn 0 */ 170 | /* USER CODE BEGIN PendSV_IRQn 1 */ 171 | 172 | /* USER CODE END PendSV_IRQn 1 */ 173 | } 174 | 175 | /** 176 | * @brief This function handles System tick timer. 177 | */ 178 | void 179 | SysTick_Handler(void) { 180 | /* USER CODE BEGIN SysTick_IRQn 0 */ 181 | 182 | /* USER CODE END SysTick_IRQn 0 */ 183 | HAL_IncTick(); 184 | /* USER CODE BEGIN SysTick_IRQn 1 */ 185 | 186 | /* USER CODE END SysTick_IRQn 1 */ 187 | } 188 | 189 | /******************************************************************************/ 190 | /* STM32L4xx Peripheral Interrupt Handlers */ 191 | /* Add here the Interrupt Handlers for the used peripherals. */ 192 | /* For the available peripheral interrupt handler names, */ 193 | /* please refer to the startup file (startup_stm32l4xx.s). */ 194 | /******************************************************************************/ 195 | 196 | /* USER CODE BEGIN 1 */ 197 | 198 | /* USER CODE END 1 */ 199 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 200 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | /* Variables */ 36 | //#undef errno 37 | extern int errno; 38 | extern int __io_putchar(int ch) __attribute__((weak)); 39 | extern int __io_getchar(void) __attribute__((weak)); 40 | 41 | register char* stack_ptr asm("sp"); 42 | 43 | char* __env[1] = { 0 }; 44 | char** environ = __env; 45 | 46 | 47 | /* Functions */ 48 | void 49 | initialise_monitor_handles() { 50 | } 51 | 52 | int 53 | _getpid(void) { 54 | return 1; 55 | } 56 | 57 | int 58 | _kill(int pid, int sig) { 59 | errno = EINVAL; 60 | return -1; 61 | } 62 | 63 | void 64 | _exit (int status) { 65 | _kill(status, -1); 66 | while (1) {} /* Make sure we hang here */ 67 | } 68 | 69 | __attribute__((weak)) int _read(int file, char* ptr, int len) { 70 | int DataIdx; 71 | 72 | for (DataIdx = 0; DataIdx < len; DataIdx++) { 73 | *ptr++ = __io_getchar(); 74 | } 75 | 76 | return len; 77 | } 78 | 79 | __attribute__((weak)) int _write(int file, char* ptr, int len) { 80 | int DataIdx; 81 | 82 | for (DataIdx = 0; DataIdx < len; DataIdx++) { 83 | __io_putchar(*ptr++); 84 | } 85 | return len; 86 | } 87 | 88 | int 89 | _close(int file) { 90 | return -1; 91 | } 92 | 93 | 94 | int 95 | _fstat(int file, struct stat* st) { 96 | st->st_mode = S_IFCHR; 97 | return 0; 98 | } 99 | 100 | int 101 | _isatty(int file) { 102 | return 1; 103 | } 104 | 105 | int 106 | _lseek(int file, int ptr, int dir) { 107 | return 0; 108 | } 109 | 110 | int 111 | _open(char* path, int flags, ...) { 112 | /* Pretend like we always fail */ 113 | return -1; 114 | } 115 | 116 | int 117 | _wait(int* status) { 118 | errno = ECHILD; 119 | return -1; 120 | } 121 | 122 | int 123 | _unlink(char* name) { 124 | errno = ENOENT; 125 | return -1; 126 | } 127 | 128 | int 129 | _times(struct tms* buf) { 130 | return -1; 131 | } 132 | 133 | int 134 | _stat(char* file, struct stat* st) { 135 | st->st_mode = S_IFCHR; 136 | return 0; 137 | } 138 | 139 | int 140 | _link(char* old, char* new) { 141 | errno = EMLINK; 142 | return -1; 143 | } 144 | 145 | int 146 | _fork(void) { 147 | errno = EAGAIN; 148 | return -1; 149 | } 150 | 151 | int 152 | _execve(char* name, char** argv, char** env) { 153 | errno = ENOMEM; 154 | return -1; 155 | } 156 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | 28 | /** 29 | * Pointer to the current high watermark of the heap usage 30 | */ 31 | static uint8_t* __sbrk_heap_end = NULL; 32 | 33 | /** 34 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 35 | * and others from the C library 36 | * 37 | * @verbatim 38 | * ############################################################################ 39 | * # .data # .bss # newlib heap # MSP stack # 40 | * # # # # Reserved by _Min_Stack_Size # 41 | * ############################################################################ 42 | * ^-- RAM start ^-- _end _estack, RAM end --^ 43 | * @endverbatim 44 | * 45 | * This implementation starts allocating at the '_end' linker symbol 46 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 47 | * The implementation considers '_estack' linker symbol to be RAM end 48 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 49 | * reserved size, please increase the '_Min_Stack_Size'. 50 | * 51 | * @param incr Memory size 52 | * @return Pointer to allocated memory 53 | */ 54 | void* 55 | _sbrk(ptrdiff_t incr) { 56 | extern uint8_t _end; /* Symbol defined in the linker script */ 57 | extern uint8_t _estack; /* Symbol defined in the linker script */ 58 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 59 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 60 | const uint8_t* max_heap = (uint8_t*)stack_limit; 61 | uint8_t* prev_heap_end; 62 | 63 | /* Initalize heap end at first call */ 64 | if (NULL == __sbrk_heap_end) { 65 | __sbrk_heap_end = &_end; 66 | } 67 | 68 | /* Protect heap from growing into the reserved MSP stack */ 69 | if (__sbrk_heap_end + incr > max_heap) { 70 | errno = ENOMEM; 71 | return (void*) -1; 72 | } 73 | 74 | prev_heap_end = __sbrk_heap_end; 75 | __sbrk_heap_end += incr; 76 | 77 | return (void*)prev_heap_end; 78 | } 79 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l412xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l412xx.h -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Device/ST/STM32L4xx/Include/system_stm32l4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32l4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32L4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Apache License, Version 2.0, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/Apache-2.0 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32l4xx_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32L4XX_H 32 | #define __SYSTEM_STM32L4XX_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32L4xx_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32L4xx_System_Exported_Variables 48 | * @{ 49 | */ 50 | /* The SystemCoreClock variable is updated in three ways: 51 | 1) by calling CMSIS function SystemCoreClockUpdate() 52 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 53 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 54 | Note: If you use this function to configure the system clock; then there 55 | is no need to call the 2 first functions listed above, since SystemCoreClock 56 | variable is updated automatically. 57 | */ 58 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 59 | 60 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 61 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 62 | extern const uint32_t MSIRangeTable[12]; /*!< MSI ranges table values */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @addtogroup STM32L4xx_System_Exported_Constants 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @addtogroup STM32L4xx_System_Exported_Macros 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @addtogroup STM32L4xx_System_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | extern void SystemInit(void); 89 | extern void SystemCoreClockUpdate(void); 90 | /** 91 | * @} 92 | */ 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif /*__SYSTEM_STM32L4XX_H */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** 105 | * @} 106 | */ 107 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 108 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Include/cmsis_compiler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_compiler.h 3 | * @brief CMSIS compiler generic header file 4 | * @version V5.1.0 5 | * @date 09. October 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef __CMSIS_COMPILER_H 26 | #define __CMSIS_COMPILER_H 27 | 28 | #include 29 | 30 | /* 31 | * Arm Compiler 4/5 32 | */ 33 | #if defined ( __CC_ARM ) 34 | #include "cmsis_armcc.h" 35 | 36 | 37 | /* 38 | * Arm Compiler 6.6 LTM (armclang) 39 | */ 40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100) 41 | #include "cmsis_armclang_ltm.h" 42 | 43 | /* 44 | * Arm Compiler above 6.10.1 (armclang) 45 | */ 46 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) 47 | #include "cmsis_armclang.h" 48 | 49 | 50 | /* 51 | * GNU Compiler 52 | */ 53 | #elif defined ( __GNUC__ ) 54 | #include "cmsis_gcc.h" 55 | 56 | 57 | /* 58 | * IAR Compiler 59 | */ 60 | #elif defined ( __ICCARM__ ) 61 | #include 62 | 63 | 64 | /* 65 | * TI Arm Compiler 66 | */ 67 | #elif defined ( __TI_ARM__ ) 68 | #include 69 | 70 | #ifndef __ASM 71 | #define __ASM __asm 72 | #endif 73 | #ifndef __INLINE 74 | #define __INLINE inline 75 | #endif 76 | #ifndef __STATIC_INLINE 77 | #define __STATIC_INLINE static inline 78 | #endif 79 | #ifndef __STATIC_FORCEINLINE 80 | #define __STATIC_FORCEINLINE __STATIC_INLINE 81 | #endif 82 | #ifndef __NO_RETURN 83 | #define __NO_RETURN __attribute__((noreturn)) 84 | #endif 85 | #ifndef __USED 86 | #define __USED __attribute__((used)) 87 | #endif 88 | #ifndef __WEAK 89 | #define __WEAK __attribute__((weak)) 90 | #endif 91 | #ifndef __PACKED 92 | #define __PACKED __attribute__((packed)) 93 | #endif 94 | #ifndef __PACKED_STRUCT 95 | #define __PACKED_STRUCT struct __attribute__((packed)) 96 | #endif 97 | #ifndef __PACKED_UNION 98 | #define __PACKED_UNION union __attribute__((packed)) 99 | #endif 100 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 101 | struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 102 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 103 | #endif 104 | #ifndef __UNALIGNED_UINT16_WRITE 105 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 106 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 107 | #endif 108 | #ifndef __UNALIGNED_UINT16_READ 109 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 110 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 111 | #endif 112 | #ifndef __UNALIGNED_UINT32_WRITE 113 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 114 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 115 | #endif 116 | #ifndef __UNALIGNED_UINT32_READ 117 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 118 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 119 | #endif 120 | #ifndef __ALIGNED 121 | #define __ALIGNED(x) __attribute__((aligned(x))) 122 | #endif 123 | #ifndef __RESTRICT 124 | #define __RESTRICT __restrict 125 | #endif 126 | #ifndef __COMPILER_BARRIER 127 | #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 128 | #define __COMPILER_BARRIER() (void)0 129 | #endif 130 | 131 | 132 | /* 133 | * TASKING Compiler 134 | */ 135 | #elif defined ( __TASKING__ ) 136 | /* 137 | * The CMSIS functions have been implemented as intrinsics in the compiler. 138 | * Please use "carm -?i" to get an up to date list of all intrinsics, 139 | * Including the CMSIS ones. 140 | */ 141 | 142 | #ifndef __ASM 143 | #define __ASM __asm 144 | #endif 145 | #ifndef __INLINE 146 | #define __INLINE inline 147 | #endif 148 | #ifndef __STATIC_INLINE 149 | #define __STATIC_INLINE static inline 150 | #endif 151 | #ifndef __STATIC_FORCEINLINE 152 | #define __STATIC_FORCEINLINE __STATIC_INLINE 153 | #endif 154 | #ifndef __NO_RETURN 155 | #define __NO_RETURN __attribute__((noreturn)) 156 | #endif 157 | #ifndef __USED 158 | #define __USED __attribute__((used)) 159 | #endif 160 | #ifndef __WEAK 161 | #define __WEAK __attribute__((weak)) 162 | #endif 163 | #ifndef __PACKED 164 | #define __PACKED __packed__ 165 | #endif 166 | #ifndef __PACKED_STRUCT 167 | #define __PACKED_STRUCT struct __packed__ 168 | #endif 169 | #ifndef __PACKED_UNION 170 | #define __PACKED_UNION union __packed__ 171 | #endif 172 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 173 | struct __packed__ T_UINT32 { uint32_t v; }; 174 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 175 | #endif 176 | #ifndef __UNALIGNED_UINT16_WRITE 177 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 178 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 179 | #endif 180 | #ifndef __UNALIGNED_UINT16_READ 181 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 182 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 183 | #endif 184 | #ifndef __UNALIGNED_UINT32_WRITE 185 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 186 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 187 | #endif 188 | #ifndef __UNALIGNED_UINT32_READ 189 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 190 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 191 | #endif 192 | #ifndef __ALIGNED 193 | #define __ALIGNED(x) __align(x) 194 | #endif 195 | #ifndef __RESTRICT 196 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 197 | #define __RESTRICT 198 | #endif 199 | #ifndef __COMPILER_BARRIER 200 | #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 201 | #define __COMPILER_BARRIER() (void)0 202 | #endif 203 | 204 | 205 | /* 206 | * COSMIC Compiler 207 | */ 208 | #elif defined ( __CSMC__ ) 209 | #include 210 | 211 | #ifndef __ASM 212 | #define __ASM _asm 213 | #endif 214 | #ifndef __INLINE 215 | #define __INLINE inline 216 | #endif 217 | #ifndef __STATIC_INLINE 218 | #define __STATIC_INLINE static inline 219 | #endif 220 | #ifndef __STATIC_FORCEINLINE 221 | #define __STATIC_FORCEINLINE __STATIC_INLINE 222 | #endif 223 | #ifndef __NO_RETURN 224 | // NO RETURN is automatically detected hence no warning here 225 | #define __NO_RETURN 226 | #endif 227 | #ifndef __USED 228 | #warning No compiler specific solution for __USED. __USED is ignored. 229 | #define __USED 230 | #endif 231 | #ifndef __WEAK 232 | #define __WEAK __weak 233 | #endif 234 | #ifndef __PACKED 235 | #define __PACKED @packed 236 | #endif 237 | #ifndef __PACKED_STRUCT 238 | #define __PACKED_STRUCT @packed struct 239 | #endif 240 | #ifndef __PACKED_UNION 241 | #define __PACKED_UNION @packed union 242 | #endif 243 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 244 | @packed struct T_UINT32 { uint32_t v; }; 245 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 246 | #endif 247 | #ifndef __UNALIGNED_UINT16_WRITE 248 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 249 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 250 | #endif 251 | #ifndef __UNALIGNED_UINT16_READ 252 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 253 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 254 | #endif 255 | #ifndef __UNALIGNED_UINT32_WRITE 256 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 257 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 258 | #endif 259 | #ifndef __UNALIGNED_UINT32_READ 260 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 261 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 262 | #endif 263 | #ifndef __ALIGNED 264 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 265 | #define __ALIGNED(x) 266 | #endif 267 | #ifndef __RESTRICT 268 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 269 | #define __RESTRICT 270 | #endif 271 | #ifndef __COMPILER_BARRIER 272 | #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 273 | #define __COMPILER_BARRIER() (void)0 274 | #endif 275 | 276 | 277 | #else 278 | #error Unknown compiler. 279 | #endif 280 | 281 | 282 | #endif /* __CMSIS_COMPILER_H */ 283 | 284 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.3 5 | * @date 24. June 2019 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2019 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 3U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2017 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef STM32L4xx_HAL_DEF_H 23 | #define STM32L4xx_HAL_DEF_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32l4xx.h" 31 | #include "Legacy/stm32_hal_legacy.h" /* Aliases file for old names compatibility */ 32 | #include 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** 37 | * @brief HAL Status structures definition 38 | */ 39 | typedef enum 40 | { 41 | HAL_OK = 0x00, 42 | HAL_ERROR = 0x01, 43 | HAL_BUSY = 0x02, 44 | HAL_TIMEOUT = 0x03 45 | } HAL_StatusTypeDef; 46 | 47 | /** 48 | * @brief HAL Lock structures definition 49 | */ 50 | typedef enum 51 | { 52 | HAL_UNLOCKED = 0x00, 53 | HAL_LOCKED = 0x01 54 | } HAL_LockTypeDef; 55 | 56 | /* Exported macros -----------------------------------------------------------*/ 57 | 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | 60 | #define HAL_MAX_DELAY 0xFFFFFFFFU 61 | 62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 64 | 65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 66 | do{ \ 67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 69 | } while(0) 70 | 71 | /** @brief Reset the Handle's State field. 72 | * @param __HANDLE__: specifies the Peripheral Handle. 73 | * @note This macro can be used for the following purpose: 74 | * - When the Handle is declared as local variable; before passing it as parameter 75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 76 | * to set to 0 the Handle's "State" field. 77 | * Otherwise, "State" field may have any random value and the first time the function 78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 79 | * (i.e. HAL_PPP_MspInit() will not be executed). 80 | * - When there is a need to reconfigure the low level hardware: instead of calling 81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 84 | * @retval None 85 | */ 86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) 87 | 88 | #if (USE_RTOS == 1) 89 | /* Reserved for future use */ 90 | #error " USE_RTOS should be 0 in the current HAL release " 91 | #else 92 | #define __HAL_LOCK(__HANDLE__) \ 93 | do{ \ 94 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 95 | { \ 96 | return HAL_BUSY; \ 97 | } \ 98 | else \ 99 | { \ 100 | (__HANDLE__)->Lock = HAL_LOCKED; \ 101 | } \ 102 | }while (0) 103 | 104 | #define __HAL_UNLOCK(__HANDLE__) \ 105 | do{ \ 106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 107 | }while (0) 108 | #endif /* USE_RTOS */ 109 | 110 | 111 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 112 | #ifndef __weak 113 | #define __weak __attribute__((weak)) 114 | #endif 115 | #ifndef __packed 116 | #define __packed __attribute__((packed)) 117 | #endif 118 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 119 | #ifndef __weak 120 | #define __weak __attribute__((weak)) 121 | #endif /* __weak */ 122 | #ifndef __packed 123 | #define __packed __attribute__((__packed__)) 124 | #endif /* __packed */ 125 | #endif /* __GNUC__ */ 126 | 127 | 128 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 129 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 130 | #ifndef __ALIGN_BEGIN 131 | #define __ALIGN_BEGIN 132 | #endif 133 | #ifndef __ALIGN_END 134 | #define __ALIGN_END __attribute__ ((aligned (4))) 135 | #endif 136 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 137 | #ifndef __ALIGN_END 138 | #define __ALIGN_END __attribute__ ((aligned (4))) 139 | #endif /* __ALIGN_END */ 140 | #ifndef __ALIGN_BEGIN 141 | #define __ALIGN_BEGIN 142 | #endif /* __ALIGN_BEGIN */ 143 | #else 144 | #ifndef __ALIGN_END 145 | #define __ALIGN_END 146 | #endif /* __ALIGN_END */ 147 | #ifndef __ALIGN_BEGIN 148 | #if defined (__CC_ARM) /* ARM Compiler V5 */ 149 | #define __ALIGN_BEGIN __align(4) 150 | #elif defined (__ICCARM__) /* IAR Compiler */ 151 | #define __ALIGN_BEGIN 152 | #endif /* __CC_ARM */ 153 | #endif /* __ALIGN_BEGIN */ 154 | #endif /* __GNUC__ */ 155 | 156 | /** 157 | * @brief __RAM_FUNC definition 158 | */ 159 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 160 | /* ARM Compiler V4/V5 and V6 161 | -------------------------- 162 | RAM functions are defined using the toolchain options. 163 | Functions that are executed in RAM should reside in a separate source module. 164 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 165 | area of a module to a memory space in physical RAM. 166 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 167 | dialog. 168 | */ 169 | #define __RAM_FUNC 170 | 171 | #elif defined ( __ICCARM__ ) 172 | /* ICCARM Compiler 173 | --------------- 174 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 175 | */ 176 | #define __RAM_FUNC __ramfunc 177 | 178 | #elif defined ( __GNUC__ ) 179 | /* GNU Compiler 180 | ------------ 181 | RAM functions are defined using a specific toolchain attribute 182 | "__attribute__((section(".RamFunc")))". 183 | */ 184 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 185 | 186 | #endif 187 | 188 | /** 189 | * @brief __NOINLINE definition 190 | */ 191 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 192 | /* ARM V4/V5 and V6 & GNU Compiler 193 | ------------------------------- 194 | */ 195 | #define __NOINLINE __attribute__ ( (noinline) ) 196 | 197 | #elif defined ( __ICCARM__ ) 198 | /* ICCARM Compiler 199 | --------------- 200 | */ 201 | #define __NOINLINE _Pragma("optimize = no_inline") 202 | 203 | #endif 204 | 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | #endif /* STM32L4xx_HAL_DEF_H */ 211 | 212 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 213 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_flash_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32L4xx_HAL_FLASH_EX_H 22 | #define STM32L4xx_HAL_FLASH_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32l4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32L4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup FLASHEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /* Exported constants --------------------------------------------------------*/ 42 | #if defined (FLASH_CFGR_LVEN) 43 | /** @addtogroup FLASHEx_Exported_Constants 44 | * @{ 45 | */ 46 | /** @defgroup FLASHEx_LVE_PIN_CFG FLASHEx LVE pin configuration 47 | * @{ 48 | */ 49 | #define FLASH_LVE_PIN_CTRL 0x00000000U /*!< LVE FLASH pin controlled by power controller */ 50 | #define FLASH_LVE_PIN_FORCED FLASH_CFGR_LVEN /*!< LVE FLASH pin enforced to low (external SMPS used) */ 51 | /** 52 | * @} 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | #endif /* FLASH_CFGR_LVEN */ 59 | 60 | /* Exported macro ------------------------------------------------------------*/ 61 | 62 | /* Exported functions --------------------------------------------------------*/ 63 | /** @addtogroup FLASHEx_Exported_Functions 64 | * @{ 65 | */ 66 | 67 | /* Extended Program operation functions *************************************/ 68 | /** @addtogroup FLASHEx_Exported_Functions_Group1 69 | * @{ 70 | */ 71 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 72 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 73 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 74 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 75 | /** 76 | * @} 77 | */ 78 | 79 | #if defined (FLASH_CFGR_LVEN) 80 | /** @addtogroup FLASHEx_Exported_Functions_Group2 81 | * @{ 82 | */ 83 | HAL_StatusTypeDef HAL_FLASHEx_ConfigLVEPin(uint32_t ConfigLVE); 84 | /** 85 | * @} 86 | */ 87 | #endif /* FLASH_CFGR_LVEN */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /* Private function ----------------------------------------------------------*/ 94 | /** @addtogroup FLASHEx_Private_Functions FLASHEx Private Functions 95 | * @{ 96 | */ 97 | void FLASH_PageErase(uint32_t Page, uint32_t Banks); 98 | void FLASH_FlushCaches(void); 99 | /** 100 | * @} 101 | */ 102 | 103 | /* Private macros ------------------------------------------------------------*/ 104 | /** 105 | @cond 0 106 | */ 107 | #if defined (FLASH_CFGR_LVEN) 108 | #define IS_FLASH_LVE_PIN(CFG) (((CFG) == FLASH_LVE_PIN_CTRL) || ((CFG) == FLASH_LVE_PIN_FORCED)) 109 | #endif /* FLASH_CFGR_LVEN */ 110 | /** 111 | @endcond 112 | */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif /* STM32L4xx_HAL_FLASH_EX_H */ 127 | 128 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 129 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32L4xx_FLASH_RAMFUNC_H 22 | #define STM32L4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32l4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32L4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup FLASH_RAMFUNC 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions --------------------------------------------------------*/ 42 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 43 | * @{ 44 | */ 45 | 46 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 47 | * @{ 48 | */ 49 | /* Peripheral Control functions ************************************************/ 50 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void); 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void); 52 | #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig); 54 | #endif 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* STM32L4xx_FLASH_RAMFUNC_H */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_i2c_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_i2c_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of I2C HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32L4xx_HAL_I2C_EX_H 22 | #define STM32L4xx_HAL_I2C_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32l4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32L4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup I2CEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /** @defgroup I2CEx_Exported_Constants I2C Extended Exported Constants 42 | * @{ 43 | */ 44 | 45 | /** @defgroup I2CEx_Analog_Filter I2C Extended Analog Filter 46 | * @{ 47 | */ 48 | #define I2C_ANALOGFILTER_ENABLE 0x00000000U 49 | #define I2C_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF 50 | /** 51 | * @} 52 | */ 53 | 54 | /** @defgroup I2CEx_FastModePlus I2C Extended Fast Mode Plus 55 | * @{ 56 | */ 57 | #define I2C_FMP_NOT_SUPPORTED 0xAAAA0000U /*!< Fast Mode Plus not supported */ 58 | #define I2C_FASTMODEPLUS_PB6 SYSCFG_CFGR1_I2C_PB6_FMP /*!< Enable Fast Mode Plus on PB6 */ 59 | #define I2C_FASTMODEPLUS_PB7 SYSCFG_CFGR1_I2C_PB7_FMP /*!< Enable Fast Mode Plus on PB7 */ 60 | #if defined(SYSCFG_CFGR1_I2C_PB8_FMP) 61 | #define I2C_FASTMODEPLUS_PB8 SYSCFG_CFGR1_I2C_PB8_FMP /*!< Enable Fast Mode Plus on PB8 */ 62 | #define I2C_FASTMODEPLUS_PB9 SYSCFG_CFGR1_I2C_PB9_FMP /*!< Enable Fast Mode Plus on PB9 */ 63 | #else 64 | #define I2C_FASTMODEPLUS_PB8 (uint32_t)(0x00000010U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus PB8 not supported */ 65 | #define I2C_FASTMODEPLUS_PB9 (uint32_t)(0x00000012U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus PB9 not supported */ 66 | #endif 67 | #define I2C_FASTMODEPLUS_I2C1 SYSCFG_CFGR1_I2C1_FMP /*!< Enable Fast Mode Plus on I2C1 pins */ 68 | #if defined(SYSCFG_CFGR1_I2C2_FMP) 69 | #define I2C_FASTMODEPLUS_I2C2 SYSCFG_CFGR1_I2C2_FMP /*!< Enable Fast Mode Plus on I2C2 pins */ 70 | #else 71 | #define I2C_FASTMODEPLUS_I2C2 (uint32_t)(0x00000200U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C2 not supported */ 72 | #endif 73 | #define I2C_FASTMODEPLUS_I2C3 SYSCFG_CFGR1_I2C3_FMP /*!< Enable Fast Mode Plus on I2C3 pins */ 74 | #if defined(SYSCFG_CFGR1_I2C4_FMP) 75 | #define I2C_FASTMODEPLUS_I2C4 SYSCFG_CFGR1_I2C4_FMP /*!< Enable Fast Mode Plus on I2C4 pins */ 76 | #else 77 | #define I2C_FASTMODEPLUS_I2C4 (uint32_t)(0x00000800U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C4 not supported */ 78 | #endif 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /** @defgroup I2CEx_Exported_Macros I2C Extended Exported Macros 89 | * @{ 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /* Exported functions --------------------------------------------------------*/ 97 | /** @addtogroup I2CEx_Exported_Functions I2C Extended Exported Functions 98 | * @{ 99 | */ 100 | 101 | /** @addtogroup I2CEx_Exported_Functions_Group1 I2C Extended Filter Mode Functions 102 | * @{ 103 | */ 104 | /* Peripheral Control functions ************************************************/ 105 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); 106 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); 107 | /** 108 | * @} 109 | */ 110 | 111 | /** @addtogroup I2CEx_Exported_Functions_Group2 I2C Extended WakeUp Mode Functions 112 | * @{ 113 | */ 114 | HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c); 115 | HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c); 116 | /** 117 | * @} 118 | */ 119 | 120 | /** @addtogroup I2CEx_Exported_Functions_Group3 I2C Extended FastModePlus Functions 121 | * @{ 122 | */ 123 | void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus); 124 | void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus); 125 | /** 126 | * @} 127 | */ 128 | 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /* Private constants ---------------------------------------------------------*/ 135 | /** @defgroup I2CEx_Private_Constants I2C Extended Private Constants 136 | * @{ 137 | */ 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /* Private macros ------------------------------------------------------------*/ 144 | /** @defgroup I2CEx_Private_Macro I2C Extended Private Macros 145 | * @{ 146 | */ 147 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 148 | ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 149 | 150 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 151 | 152 | #define IS_I2C_FASTMODEPLUS(__CONFIG__) ((((__CONFIG__) & I2C_FMP_NOT_SUPPORTED) != I2C_FMP_NOT_SUPPORTED) && \ 153 | ((((__CONFIG__) & (I2C_FASTMODEPLUS_PB6)) == I2C_FASTMODEPLUS_PB6) || \ 154 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB7)) == I2C_FASTMODEPLUS_PB7) || \ 155 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB8)) == I2C_FASTMODEPLUS_PB8) || \ 156 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB9)) == I2C_FASTMODEPLUS_PB9) || \ 157 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C1)) == I2C_FASTMODEPLUS_I2C1) || \ 158 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C2)) == I2C_FASTMODEPLUS_I2C2) || \ 159 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C3)) == I2C_FASTMODEPLUS_I2C3) || \ 160 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C4)) == I2C_FASTMODEPLUS_I2C4))) 161 | /** 162 | * @} 163 | */ 164 | 165 | /* Private Functions ---------------------------------------------------------*/ 166 | /** @defgroup I2CEx_Private_Functions I2C Extended Private Functions 167 | * @{ 168 | */ 169 | /* Private functions are defined in stm32l4xx_hal_i2c_ex.c file */ 170 | /** 171 | * @} 172 | */ 173 | 174 | /** 175 | * @} 176 | */ 177 | 178 | /** 179 | * @} 180 | */ 181 | 182 | #ifdef __cplusplus 183 | } 184 | #endif 185 | 186 | #endif /* STM32L4xx_HAL_I2C_EX_H */ 187 | 188 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 189 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC driver. 6 | * This file provides a Flash firmware functions which should be 7 | * executed from internal SRAM 8 | * + FLASH HalfPage Programming 9 | * + FLASH Power Down in Run mode 10 | * 11 | * @verbatim 12 | ============================================================================== 13 | ##### Flash RAM functions ##### 14 | ============================================================================== 15 | 16 | *** ARM Compiler *** 17 | -------------------- 18 | [..] RAM functions are defined using the toolchain options. 19 | Functions that are executed in RAM should reside in a separate 20 | source module. Using the 'Options for File' dialog you can simply change 21 | the 'Code / Const' area of a module to a memory space in physical RAM. 22 | Available memory areas are declared in the 'Target' tab of the 23 | Options for Target' dialog. 24 | 25 | *** ICCARM Compiler *** 26 | ----------------------- 27 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 28 | 29 | *** GNU Compiler *** 30 | -------------------- 31 | [..] RAM functions are defined using a specific toolchain attribute 32 | "__attribute__((section(".RamFunc")))". 33 | 34 | @endverbatim 35 | ****************************************************************************** 36 | * @attention 37 | * 38 | *

© Copyright (c) 2017 STMicroelectronics. 39 | * All rights reserved.

40 | * 41 | * This software component is licensed by ST under BSD 3-Clause license, 42 | * the "License"; You may not use this file except in compliance with the 43 | * License. You may obtain a copy of the License at: 44 | * opensource.org/licenses/BSD-3-Clause 45 | * 46 | ****************************************************************************** 47 | */ 48 | 49 | /* Includes ------------------------------------------------------------------*/ 50 | #include "stm32l4xx_hal.h" 51 | 52 | /** @addtogroup STM32L4xx_HAL_Driver 53 | * @{ 54 | */ 55 | 56 | /** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC 57 | * @brief FLASH functions executed from RAM 58 | * @{ 59 | */ 60 | 61 | #ifdef HAL_FLASH_MODULE_ENABLED 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* Private define ------------------------------------------------------------*/ 65 | /* Private macro -------------------------------------------------------------*/ 66 | /* Private variables ---------------------------------------------------------*/ 67 | /* Private function prototypes -----------------------------------------------*/ 68 | /* Exported functions -------------------------------------------------------*/ 69 | 70 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH in RAM function Exported Functions 71 | * @{ 72 | */ 73 | 74 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions 75 | * @brief Data transfers functions 76 | * 77 | @verbatim 78 | =============================================================================== 79 | ##### ramfunc functions ##### 80 | =============================================================================== 81 | [..] 82 | This subsection provides a set of functions that should be executed from RAM. 83 | 84 | @endverbatim 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @brief Enable the Power down in Run Mode 90 | * @note This function should be called and executed from SRAM memory 91 | * @retval HAL status 92 | */ 93 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void) 94 | { 95 | /* Enable the Power Down in Run mode*/ 96 | __HAL_FLASH_POWER_DOWN_ENABLE(); 97 | 98 | return HAL_OK; 99 | 100 | } 101 | 102 | /** 103 | * @brief Disable the Power down in Run Mode 104 | * @note This function should be called and executed from SRAM memory 105 | * @retval HAL status 106 | */ 107 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void) 108 | { 109 | /* Disable the Power Down in Run mode*/ 110 | __HAL_FLASH_POWER_DOWN_DISABLE(); 111 | 112 | return HAL_OK; 113 | } 114 | 115 | #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 116 | /** 117 | * @brief Program the FLASH DBANK User Option Byte. 118 | * 119 | * @note To configure the user option bytes, the option lock bit OPTLOCK must 120 | * be cleared with the call of the HAL_FLASH_OB_Unlock() function. 121 | * @note To modify the DBANK option byte, no PCROP region should be defined. 122 | * To deactivate PCROP, user should perform RDP changing 123 | * 124 | * @param DBankConfig The FLASH DBANK User Option Byte value. 125 | * This parameter can be one of the following values: 126 | * @arg OB_DBANK_128_BITS: Single-bank with 128-bits data 127 | * @arg OB_DBANK_64_BITS: Dual-bank with 64-bits data 128 | * 129 | * @retval HAL status 130 | */ 131 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig) 132 | { 133 | uint32_t count, reg; 134 | HAL_StatusTypeDef status = HAL_ERROR; 135 | 136 | /* Process Locked */ 137 | __HAL_LOCK(&pFlash); 138 | 139 | /* Check if the PCROP is disabled */ 140 | reg = FLASH->PCROP1SR; 141 | if (reg > FLASH->PCROP1ER) 142 | { 143 | reg = FLASH->PCROP2SR; 144 | if (reg > FLASH->PCROP2ER) 145 | { 146 | /* Disable Flash prefetch */ 147 | __HAL_FLASH_PREFETCH_BUFFER_DISABLE(); 148 | 149 | if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U) 150 | { 151 | /* Disable Flash instruction cache */ 152 | __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); 153 | 154 | /* Flush Flash instruction cache */ 155 | __HAL_FLASH_INSTRUCTION_CACHE_RESET(); 156 | } 157 | 158 | if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U) 159 | { 160 | /* Disable Flash data cache */ 161 | __HAL_FLASH_DATA_CACHE_DISABLE(); 162 | 163 | /* Flush Flash data cache */ 164 | __HAL_FLASH_DATA_CACHE_RESET(); 165 | } 166 | 167 | /* Disable WRP zone 1 of 1st bank if needed */ 168 | reg = FLASH->WRP1AR; 169 | if (((reg & FLASH_WRP1AR_WRP1A_STRT) >> FLASH_WRP1AR_WRP1A_STRT_Pos) <= 170 | ((reg & FLASH_WRP1AR_WRP1A_END) >> FLASH_WRP1AR_WRP1A_END_Pos)) 171 | { 172 | MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT); 173 | } 174 | 175 | /* Disable WRP zone 2 of 1st bank if needed */ 176 | reg = FLASH->WRP1BR; 177 | if (((reg & FLASH_WRP1BR_WRP1B_STRT) >> FLASH_WRP1BR_WRP1B_STRT_Pos) <= 178 | ((reg & FLASH_WRP1BR_WRP1B_END) >> FLASH_WRP1BR_WRP1B_END_Pos)) 179 | { 180 | MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT); 181 | } 182 | 183 | /* Disable WRP zone 1 of 2nd bank if needed */ 184 | reg = FLASH->WRP2AR; 185 | if (((reg & FLASH_WRP2AR_WRP2A_STRT) >> FLASH_WRP2AR_WRP2A_STRT_Pos) <= 186 | ((reg & FLASH_WRP2AR_WRP2A_END) >> FLASH_WRP2AR_WRP2A_END_Pos)) 187 | { 188 | MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT); 189 | } 190 | 191 | /* Disable WRP zone 2 of 2nd bank if needed */ 192 | reg = FLASH->WRP2BR; 193 | if (((reg & FLASH_WRP2BR_WRP2B_STRT) >> FLASH_WRP2BR_WRP2B_STRT_Pos) <= 194 | ((reg & FLASH_WRP2BR_WRP2B_END) >> FLASH_WRP2BR_WRP2B_END_Pos)) 195 | { 196 | MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT); 197 | } 198 | 199 | /* Modify the DBANK user option byte */ 200 | MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig); 201 | 202 | /* Set OPTSTRT Bit */ 203 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 204 | 205 | /* Wait for last operation to be completed */ 206 | /* 8 is the number of required instruction cycles for the below loop statement (timeout expressed in ms) */ 207 | count = FLASH_TIMEOUT_VALUE * (SystemCoreClock / 8U / 1000U); 208 | do 209 | { 210 | if (count == 0U) 211 | { 212 | break; 213 | } 214 | count--; 215 | } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET); 216 | 217 | /* If the option byte program operation is completed, disable the OPTSTRT Bit */ 218 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 219 | 220 | /* Set the bit to force the option byte reloading */ 221 | SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH); 222 | } 223 | } 224 | 225 | /* Process Unlocked */ 226 | __HAL_UNLOCK(&pFlash); 227 | 228 | return status; 229 | } 230 | #endif 231 | 232 | /** 233 | * @} 234 | */ 235 | 236 | /** 237 | * @} 238 | */ 239 | #endif /* HAL_FLASH_MODULE_ENABLED */ 240 | 241 | 242 | 243 | /** 244 | * @} 245 | */ 246 | 247 | /** 248 | * @} 249 | */ 250 | 251 | 252 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 253 | 254 | 255 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/STM32L412KBUX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file LinkerScript.ld 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief Linker script for STM32L412KBUx Device from STM32L4 series 6 | * 128Kbytes FLASH 7 | * 40Kbytes RAM 8 | * 9 | * Set heap size, stack size and stack location according 10 | * to application requirements. 11 | * 12 | * Set memory bank area and size if external memory is used 13 | ****************************************************************************** 14 | * @attention 15 | * 16 | *

© Copyright (c) 2020 STMicroelectronics. 17 | * All rights reserved.

18 | * 19 | * This software component is licensed by ST under BSD 3-Clause license, 20 | * the "License"; You may not use this file except in compliance with the 21 | * License. You may obtain a copy of the License at: 22 | * opensource.org/licenses/BSD-3-Clause 23 | * 24 | ****************************************************************************** 25 | */ 26 | 27 | /* Entry Point */ 28 | ENTRY(Reset_Handler) 29 | 30 | /* Highest address of the user mode stack */ 31 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 32 | 33 | _Min_Heap_Size = 0x200 ; /* required amount of heap */ 34 | _Min_Stack_Size = 0x400 ; /* required amount of stack */ 35 | 36 | /* Memories definition */ 37 | MEMORY 38 | { 39 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K 40 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K 41 | } 42 | 43 | /* Sections */ 44 | SECTIONS 45 | { 46 | /* The startup code into "FLASH" Rom type memory */ 47 | .isr_vector : 48 | { 49 | . = ALIGN(4); 50 | KEEP(*(.isr_vector)) /* Startup code */ 51 | . = ALIGN(4); 52 | } >FLASH 53 | 54 | /* The program code and other data into "FLASH" Rom type memory */ 55 | .text : 56 | { 57 | . = ALIGN(4); 58 | *(.text) /* .text sections (code) */ 59 | *(.text*) /* .text* sections (code) */ 60 | *(.glue_7) /* glue arm to thumb code */ 61 | *(.glue_7t) /* glue thumb to arm code */ 62 | *(.eh_frame) 63 | 64 | KEEP (*(.init)) 65 | KEEP (*(.fini)) 66 | 67 | . = ALIGN(4); 68 | _etext = .; /* define a global symbols at end of code */ 69 | } >FLASH 70 | 71 | /* Constant data into "FLASH" Rom type memory */ 72 | .rodata : 73 | { 74 | . = ALIGN(4); 75 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 76 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 77 | . = ALIGN(4); 78 | } >FLASH 79 | 80 | .ARM.extab : { 81 | . = ALIGN(4); 82 | *(.ARM.extab* .gnu.linkonce.armextab.*) 83 | . = ALIGN(4); 84 | } >FLASH 85 | 86 | .ARM : { 87 | . = ALIGN(4); 88 | __exidx_start = .; 89 | *(.ARM.exidx*) 90 | __exidx_end = .; 91 | . = ALIGN(4); 92 | } >FLASH 93 | 94 | .preinit_array : 95 | { 96 | . = ALIGN(4); 97 | PROVIDE_HIDDEN (__preinit_array_start = .); 98 | KEEP (*(.preinit_array*)) 99 | PROVIDE_HIDDEN (__preinit_array_end = .); 100 | . = ALIGN(4); 101 | } >FLASH 102 | 103 | .init_array : 104 | { 105 | . = ALIGN(4); 106 | PROVIDE_HIDDEN (__init_array_start = .); 107 | KEEP (*(SORT(.init_array.*))) 108 | KEEP (*(.init_array*)) 109 | PROVIDE_HIDDEN (__init_array_end = .); 110 | . = ALIGN(4); 111 | } >FLASH 112 | 113 | .fini_array : 114 | { 115 | . = ALIGN(4); 116 | PROVIDE_HIDDEN (__fini_array_start = .); 117 | KEEP (*(SORT(.fini_array.*))) 118 | KEEP (*(.fini_array*)) 119 | PROVIDE_HIDDEN (__fini_array_end = .); 120 | . = ALIGN(4); 121 | } >FLASH 122 | 123 | /* Used by the startup to initialize data */ 124 | _sidata = LOADADDR(.data); 125 | 126 | /* Initialized data sections into "RAM" Ram type memory */ 127 | .data : 128 | { 129 | . = ALIGN(4); 130 | _sdata = .; /* create a global symbol at data start */ 131 | *(.data) /* .data sections */ 132 | *(.data*) /* .data* sections */ 133 | 134 | . = ALIGN(4); 135 | _edata = .; /* define a global symbol at data end */ 136 | 137 | } >RAM AT> FLASH 138 | 139 | /* Uninitialized data section into "RAM" Ram type memory */ 140 | . = ALIGN(4); 141 | .bss : 142 | { 143 | /* This is used by the startup in order to initialize the .bss section */ 144 | _sbss = .; /* define a global symbol at bss start */ 145 | __bss_start__ = _sbss; 146 | *(.bss) 147 | *(.bss*) 148 | *(COMMON) 149 | 150 | . = ALIGN(4); 151 | _ebss = .; /* define a global symbol at bss end */ 152 | __bss_end__ = _ebss; 153 | } >RAM 154 | 155 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 156 | ._user_heap_stack : 157 | { 158 | . = ALIGN(8); 159 | PROVIDE ( end = . ); 160 | PROVIDE ( _end = . ); 161 | . = . + _Min_Heap_Size; 162 | . = . + _Min_Stack_Size; 163 | . = ALIGN(8); 164 | } >RAM 165 | 166 | /* Remove information from the compiler libraries */ 167 | /DISCARD/ : 168 | { 169 | libc.a ( * ) 170 | libm.a ( * ) 171 | libgcc.a ( * ) 172 | } 173 | 174 | .ARM.attributes 0 : { *(.ARM.attributes) } 175 | } 176 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/cmake/gcc-arm-none-eabi.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Generic) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | # Some default GCC settings 5 | # arm-none-eabi- must be part of path environment 6 | set(TOOLCHAIN_PREFIX arm-none-eabi-) 7 | set(FLAGS "-fdata-sections -ffunction-sections -Wl,--gc-sections") 8 | set(CPP_FLAGS "${FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics") 9 | 10 | set(CMAKE_C_FLAGS ${FLAGS}) 11 | set(CMAKE_CXX_FLAGS ${CPP_FLAGS}) 12 | 13 | set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) 14 | set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) 15 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) 16 | set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) 17 | set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) 18 | 19 | set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") 20 | set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") 21 | set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") 22 | 23 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 24 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/lwprintf_stm32l432kc_nucleo Debug.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /examples/stm32/lwprintf_stm32l432kc_nucleo/lwprintf_stm32l432kc_nucleo.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | File.Version=6 3 | KeepUserPlacement=false 4 | Mcu.Family=STM32L4 5 | Mcu.IP0=NVIC 6 | Mcu.IP1=RCC 7 | Mcu.IP2=SYS 8 | Mcu.IP3=USART2 9 | Mcu.IPNb=4 10 | Mcu.Name=STM32L412KBUx 11 | Mcu.Package=UFQFPN32 12 | Mcu.Pin0=PC14-OSC32_IN (PC14) 13 | Mcu.Pin1=PC15-OSC32_OUT (PC15) 14 | Mcu.Pin2=PA2 15 | Mcu.Pin3=PA3 16 | Mcu.Pin4=VP_SYS_VS_Systick 17 | Mcu.PinsNb=5 18 | Mcu.ThirdPartyNb=0 19 | Mcu.UserConstants= 20 | Mcu.UserName=STM32L412KBUx 21 | MxCube.Version=6.0.0 22 | MxDb.Version=DB.6.0.0 23 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 24 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 25 | NVIC.ForceEnableDMAVector=true 26 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 27 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 28 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 29 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 30 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 31 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 32 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true 33 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 34 | PA2.Mode=Asynchronous 35 | PA2.Signal=USART2_TX 36 | PA3.Mode=Asynchronous 37 | PA3.Signal=USART2_RX 38 | PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator 39 | PC14-OSC32_IN\ (PC14).Signal=RCC_OSC32_IN 40 | PC15-OSC32_OUT\ (PC15).Mode=LSE-External-Oscillator 41 | PC15-OSC32_OUT\ (PC15).Signal=RCC_OSC32_OUT 42 | PinOutPanel.RotationAngle=0 43 | ProjectManager.AskForMigrate=true 44 | ProjectManager.BackupPrevious=false 45 | ProjectManager.CompilerOptimize=6 46 | ProjectManager.ComputerToolchain=false 47 | ProjectManager.CoupleFile=false 48 | ProjectManager.CustomerFirmwarePackage= 49 | ProjectManager.DefaultFWLocation=true 50 | ProjectManager.DeletePrevious=true 51 | ProjectManager.DeviceId=STM32L412KBUx 52 | ProjectManager.FirmwarePackage=STM32Cube FW_L4 V1.16.0 53 | ProjectManager.FreePins=false 54 | ProjectManager.HalAssertFull=false 55 | ProjectManager.HeapSize=0x200 56 | ProjectManager.KeepUserCode=true 57 | ProjectManager.LastFirmware=true 58 | ProjectManager.LibraryCopy=1 59 | ProjectManager.MainLocation=Core/Src 60 | ProjectManager.NoMain=false 61 | ProjectManager.PreviousToolchain= 62 | ProjectManager.ProjectBuild=false 63 | ProjectManager.ProjectFileName=lwprintf_stm32l432kc_nucleo.ioc 64 | ProjectManager.ProjectName=lwprintf_stm32l432kc_nucleo 65 | ProjectManager.RegisterCallBack= 66 | ProjectManager.StackSize=0x400 67 | ProjectManager.TargetToolchain=STM32CubeIDE 68 | ProjectManager.ToolChainLocation= 69 | ProjectManager.UnderRoot=true 70 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true 71 | RCC.ADCFreq_Value=4000000 72 | RCC.CRSFreq_Value=48000000 73 | RCC.FamilyName=M 74 | RCC.HSE_VALUE=8000000 75 | RCC.HSI48_VALUE=48000000 76 | RCC.HSI_VALUE=16000000 77 | RCC.IPParameters=ADCFreq_Value,CRSFreq_Value,FamilyName,HSE_VALUE,HSI48_VALUE,HSI_VALUE,LSCOPinFreq_Value,LSI_VALUE,MSI_VALUE,PLLQoutputFreq_Value,PLLRCLKFreq_Value,RNGFreq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value 78 | RCC.LSCOPinFreq_Value=32000 79 | RCC.LSI_VALUE=32000 80 | RCC.MSI_VALUE=4000000 81 | RCC.PLLQoutputFreq_Value=16000000 82 | RCC.PLLRCLKFreq_Value=16000000 83 | RCC.RNGFreq_Value=4000000 84 | RCC.USBFreq_Value=4000000 85 | RCC.VCOInputFreq_Value=4000000 86 | RCC.VCOOutputFreq_Value=32000000 87 | USART2.IPParameters=VirtualMode-Asynchronous 88 | USART2.VirtualMode-Asynchronous=VM_ASYNC 89 | VP_SYS_VS_Systick.Mode=SysTick 90 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 91 | board=custom 92 | isbadioc=false 93 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LwPRINTF", 3 | "version": "1.0.6", 4 | "description": "Lightweight printf and sprintf library for embedded systems", 5 | "keywords": "printf, lightweight, lwprintf, sprintf, snprintf, embedded, stdio, manager, library", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/MaJerle/lwprintf.git" 9 | }, 10 | "authors": [ 11 | { 12 | "name": "Tilen Majerle", 13 | "email": "tilen@majerle.eu", 14 | "url": "https://majerle.eu" 15 | } 16 | ], 17 | "license": "MIT", 18 | "homepage": "https://github.com/MaJerle/lwprintf", 19 | "dependencies": {}, 20 | "frameworks": "*", 21 | "platforms": "*", 22 | "export": { 23 | "exclude": [ 24 | ".github", 25 | "dev", 26 | "docs", 27 | "**/.vs", 28 | "**/Debug", 29 | "build", 30 | "**/build" 31 | ] 32 | }, 33 | "build": { 34 | "includeDir": "lwprintf/src/include" 35 | } 36 | } -------------------------------------------------------------------------------- /lwprintf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/library.cmake) -------------------------------------------------------------------------------- /lwprintf/library.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # LIB_PREFIX: LWPRINTF 3 | # 4 | # This file provides set of variables for end user 5 | # and also generates one (or more) libraries, that can be added to the project using target_link_libraries(...) 6 | # 7 | # Before this file is included to the root CMakeLists file (using include() function), user can set some variables: 8 | # 9 | # LWPRINTF_SYS_PORT: If defined, it will include port source file from the library. 10 | # LWPRINTF_OPTS_FILE: If defined, it is the path to the user options file. If not defined, one will be generated for you automatically 11 | # LWPRINTF_COMPILE_OPTIONS: If defined, it provide compiler options for generated library. 12 | # LWPRINTF_COMPILE_DEFINITIONS: If defined, it provides "-D" definitions to the library build 13 | # 14 | 15 | # Custom include directory 16 | set(LWPRINTF_CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib_inc) 17 | 18 | # Library core sources 19 | set(lwprintf_core_SRCS 20 | ${CMAKE_CURRENT_LIST_DIR}/src/lwprintf/lwprintf.c 21 | ) 22 | 23 | # Add system port 24 | if(DEFINED LWPRINTF_SYS_PORT) 25 | set(lwprintf_core_SRCS 26 | ${lwprintf_core_SRCS} 27 | ${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c 28 | ) 29 | endif() 30 | 31 | # Setup include directories 32 | set(lwprintf_include_DIRS 33 | ${CMAKE_CURRENT_LIST_DIR}/src/include 34 | ${LWPRINTF_CUSTOM_INC_DIR} 35 | ) 36 | 37 | # Register library to the system 38 | add_library(lwprintf) 39 | target_sources(lwprintf PRIVATE ${lwprintf_core_SRCS}) 40 | target_include_directories(lwprintf PUBLIC ${lwprintf_include_DIRS}) 41 | target_compile_options(lwprintf PRIVATE ${LWPRINTF_COMPILE_OPTIONS}) 42 | target_compile_definitions(lwprintf PRIVATE ${LWPRINTF_COMPILE_DEFINITIONS}) 43 | 44 | # Create config file if user didn't provide one info himself 45 | if(NOT LWPRINTF_OPTS_FILE) 46 | message(STATUS "Using default lwprintf_opts.h file") 47 | set(LWPRINTF_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/src/include/lwprintf/lwprintf_opts_template.h) 48 | else() 49 | message(STATUS "Using custom lwprintf_opts.h file from ${LWPRINTF_OPTS_FILE}") 50 | endif() 51 | 52 | configure_file(${LWPRINTF_OPTS_FILE} ${LWPRINTF_CUSTOM_INC_DIR}/lwprintf_opts.h COPYONLY) 53 | -------------------------------------------------------------------------------- /lwprintf/src/include/lwprintf/lwprintf_opt.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_opt.h 3 | * \brief LwPRINTF options 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #ifndef LWPRINTF_OPT_HDR_H 35 | #define LWPRINTF_OPT_HDR_H 36 | 37 | /* Uncomment to ignore user options (or set macro in compiler flags) */ 38 | /* #define LWPRINTF_IGNORE_USER_OPTS */ 39 | 40 | /* Include application options */ 41 | #ifndef LWPRINTF_IGNORE_USER_OPTS 42 | #include "lwprintf_opts.h" 43 | #endif /* LWPRINTF_IGNORE_USER_OPTS */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif /* __cplusplus */ 48 | 49 | /** 50 | * \defgroup LWPRINTF_OPT Configuration 51 | * \brief LwPRINTF options 52 | * \{ 53 | */ 54 | 55 | /** 56 | * \brief Enables `1` or disables `0` operating system support in the library 57 | * 58 | * \note When `LWPRINTF_CFG_OS` is enabled, user must implement functions in \ref LWPRINTF_SYS group. 59 | */ 60 | #ifndef LWPRINTF_CFG_OS 61 | #define LWPRINTF_CFG_OS 0 62 | #endif 63 | 64 | /** 65 | * \brief Mutex handle type 66 | * 67 | * \note This value must be set in case \ref LWPRINTF_CFG_OS is set to `1`. 68 | * If data type is not known to compiler, include header file with 69 | * definition before you define handle type 70 | */ 71 | #ifndef LWPRINTF_CFG_OS_MUTEX_HANDLE 72 | #define LWPRINTF_CFG_OS_MUTEX_HANDLE void* 73 | #endif 74 | 75 | /** 76 | * \brief Enables `1` or disables `0` manual mutex lock. 77 | * 78 | * When this feature is enabled, together with \ref LWPRINTF_CFG_OS, behavior is as following: 79 | * - System mutex is kept created during init phase 80 | * - Calls to direct printing functions are not thread-safe by default anymore 81 | * - Calls to sprintf (buffer functions) are kept thread-safe 82 | * - User must manually call \ref lwprintf_protect or \ref lwprintf_protect_ex functions to protect direct printing operation 83 | * - User must manually call \ref lwprintf_unprotect or \ref lwprintf_unprotect_ex functions to exit protected area 84 | * 85 | * \note If you prefer to completely disable locking mechanism with this library, 86 | * turn off \ref LWPRINTF_CFG_OS and fully manually handle mutual exclusion for non-reentrant functions 87 | */ 88 | #ifndef LWPRINTF_CFG_OS_MANUAL_PROTECT 89 | #define LWPRINTF_CFG_OS_MANUAL_PROTECT 0 90 | #endif 91 | 92 | /** 93 | * \brief Enables `1` or disables `0` support for `long long int` type, signed or unsigned. 94 | * 95 | */ 96 | #ifndef LWPRINTF_CFG_SUPPORT_LONG_LONG 97 | #define LWPRINTF_CFG_SUPPORT_LONG_LONG 1 98 | #endif 99 | 100 | /** 101 | * \brief Enables `1` or disables `0` support for any specifier accepting any kind of integer types. 102 | * This is enabling `%d, %b, %u, %o, %i, %x` specifiers 103 | * 104 | */ 105 | #ifndef LWPRINTF_CFG_SUPPORT_TYPE_INT 106 | #define LWPRINTF_CFG_SUPPORT_TYPE_INT 1 107 | #endif 108 | 109 | /** 110 | * \brief Enables `1` or disables `0` support `%p` pointer print type 111 | * 112 | * When enabled, architecture must support `uintptr_t` type, normally available with C11 standard 113 | */ 114 | #ifndef LWPRINTF_CFG_SUPPORT_TYPE_POINTER 115 | #define LWPRINTF_CFG_SUPPORT_TYPE_POINTER 1 116 | #endif 117 | 118 | /** 119 | * \brief Enables `1` or disables `0` support `%f` float type 120 | * 121 | */ 122 | #ifndef LWPRINTF_CFG_SUPPORT_TYPE_FLOAT 123 | #define LWPRINTF_CFG_SUPPORT_TYPE_FLOAT 1 124 | #endif 125 | 126 | /** 127 | * \brief Enables `1` or disables `0` support for `%e` engineering output type for float numbers 128 | * 129 | * \note \ref LWPRINTF_CFG_SUPPORT_TYPE_FLOAT has to be enabled to use this feature 130 | * 131 | */ 132 | #ifndef LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING 133 | #define LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING 1 134 | #endif 135 | 136 | /** 137 | * \brief Enables `1` or disables `0` support for `%s` for string output 138 | * 139 | */ 140 | #ifndef LWPRINTF_CFG_SUPPORT_TYPE_STRING 141 | #define LWPRINTF_CFG_SUPPORT_TYPE_STRING 1 142 | #endif 143 | 144 | /** 145 | * \brief Enables `1` or disables `0` support for `%k` for hex byte array output 146 | * 147 | */ 148 | #ifndef LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY 149 | #define LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY 1 150 | #endif 151 | 152 | /** 153 | * \brief Specifies default number of precision for floating number 154 | * 155 | * Represents number of digits to be used after comma if no precision 156 | * is set with specifier itself 157 | * 158 | */ 159 | #ifndef LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION 160 | #define LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION 6 161 | #endif 162 | 163 | /** 164 | * \brief Enables `1` or disables `0` optional short names for LwPRINTF API functions. 165 | * 166 | * It adds functions for default instance: `lwprintf`, `lwsnprintf` and others 167 | */ 168 | #ifndef LWPRINTF_CFG_ENABLE_SHORTNAMES 169 | #define LWPRINTF_CFG_ENABLE_SHORTNAMES 0 170 | #endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */ 171 | 172 | /** 173 | * \brief Enables `1` or disables `0` C standard API names 174 | * 175 | * Disabled by default not to interfere with compiler implementation. 176 | * Application may need to remove standard C STDIO library from linkage 177 | * to be able to properly compile LwPRINTF with this option enabled 178 | */ 179 | #ifndef LWPRINTF_CFG_ENABLE_STD_NAMES 180 | #define LWPRINTF_CFG_ENABLE_STD_NAMES 0 181 | #endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */ 182 | 183 | /** 184 | * \} 185 | */ 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif /* __cplusplus */ 190 | 191 | #endif /* LWPRINTF_OPT_HDR_H */ 192 | -------------------------------------------------------------------------------- /lwprintf/src/include/lwprintf/lwprintf_opts_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_opts_template.h 3 | * \brief LwPRINTF configuration file 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #ifndef LWPRINTF_OPTS_HDR_H 35 | #define LWPRINTF_OPTS_HDR_H 36 | 37 | /* Rename this file to "lwprintf_opts.h" for your application */ 38 | 39 | /* 40 | * Open "include/lwprintf/lwprintf_opt.h" and 41 | * copy & replace here settings you want to change values 42 | */ 43 | 44 | #endif /* LWPRINTF_OPTS_HDR_H */ 45 | -------------------------------------------------------------------------------- /lwprintf/src/include/system/lwprintf_sys.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_sys.h 3 | * \brief System functions for OS 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #ifndef LWPRINTF_SYS_HDR_H 35 | #define LWPRINTF_SYS_HDR_H 36 | 37 | #include 38 | #include 39 | #include "lwprintf/lwprintf.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | 45 | #if LWPRINTF_CFG_OS || __DOXYGEN__ 46 | 47 | /** 48 | * \defgroup LWPRINTF_SYS System functions 49 | * \brief System functions when used with operating system 50 | * \{ 51 | */ 52 | 53 | /** 54 | * \brief Create a new mutex and assign value to handle 55 | * \param[out] m: Output variable to save mutex handle 56 | * \return `1` on success, `0` otherwise 57 | */ 58 | uint8_t lwprintf_sys_mutex_create(LWPRINTF_CFG_OS_MUTEX_HANDLE* m); 59 | 60 | /** 61 | * \brief Check if mutex handle is valid 62 | * \param[in] m: Mutex handle to check if valid 63 | * \return `1` on success, `0` otherwise 64 | */ 65 | uint8_t lwprintf_sys_mutex_isvalid(LWPRINTF_CFG_OS_MUTEX_HANDLE* m); 66 | 67 | /** 68 | * \brief Wait for a mutex until ready (unlimited time) 69 | * \param[in] m: Mutex handle to wait for 70 | * \return `1` on success, `0` otherwise 71 | */ 72 | uint8_t lwprintf_sys_mutex_wait(LWPRINTF_CFG_OS_MUTEX_HANDLE* m); 73 | 74 | /** 75 | * \brief Release already locked mutex 76 | * \param[in] m: Mutex handle to release 77 | * \return `1` on success, `0` otherwise 78 | */ 79 | uint8_t lwprintf_sys_mutex_release(LWPRINTF_CFG_OS_MUTEX_HANDLE* m); 80 | 81 | /** 82 | * \} 83 | */ 84 | 85 | #endif /* LWPRINTF_CFG_OS || __DOXYGEN__ */ 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif /* __cplusplus */ 90 | 91 | #endif /* LWPRINTF_SYS_HDR_H */ 92 | -------------------------------------------------------------------------------- /lwprintf/src/system/lwprintf_sys_cmsis_os.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_sys_cmsis_os.c 3 | * \brief System functions for CMSIS-OS based operating system 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #include "system/lwprintf_sys.h" 35 | 36 | #if LWPRINTF_CFG_OS && !__DOXYGEN__ 37 | 38 | #include "cmsis_os.h" 39 | 40 | uint8_t 41 | lwprintf_sys_mutex_create(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 42 | const osMutexAttr_t attr = { 43 | .name = "lwprintf_mutex", 44 | .attr_bits = osMutexRecursive, 45 | }; 46 | return (*m = osMutexNew(&attr)) != NULL; 47 | } 48 | 49 | uint8_t 50 | lwprintf_sys_mutex_isvalid(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 51 | return *m != NULL; 52 | } 53 | 54 | uint8_t 55 | lwprintf_sys_mutex_wait(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 56 | return osMutexAcquire(*m, osWaitForever) == osOK; 57 | } 58 | 59 | uint8_t 60 | lwprintf_sys_mutex_release(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 61 | return osMutexRelease(*m) == osOK; 62 | } 63 | 64 | #endif /* LWPRINTF_CFG_OS && !__DOXYGEN__ */ 65 | -------------------------------------------------------------------------------- /lwprintf/src/system/lwprintf_sys_threadx.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_sys_cmsis_os.c 3 | * \brief System functions for CMSIS-OS based operating system 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #include "system/lwprintf_sys.h" 35 | 36 | #if LWPRINTF_CFG_OS && !__DOXYGEN__ 37 | 38 | /* 39 | * To use this module, options must be defined as 40 | * 41 | * #define LWPRINTF_CFG_OS_MUTEX_HANDLE TX_MUTEX 42 | */ 43 | 44 | /* Include ThreadX API module */ 45 | #include "tx_api.h" 46 | #include "tx_mutex.h" 47 | 48 | uint8_t 49 | lwprintf_sys_mutex_create(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 50 | static char name[] = "lwprintf_mutex"; 51 | return tx_mutex_create(m, name, TX_INHERIT) == TX_SUCCESS; 52 | } 53 | 54 | uint8_t 55 | lwprintf_sys_mutex_isvalid(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 56 | return m->tx_mutex_id == TX_MUTEX_ID; 57 | } 58 | 59 | uint8_t 60 | lwprintf_sys_mutex_wait(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 61 | return tx_mutex_get(m, TX_WAIT_FOREVER) == TX_SUCCESS; 62 | } 63 | 64 | uint8_t 65 | lwprintf_sys_mutex_release(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 66 | return tx_mutex_put(m) == TX_SUCCESS; 67 | } 68 | 69 | #endif /* LWPRINTF_CFG_OS && !__DOXYGEN__ */ 70 | -------------------------------------------------------------------------------- /lwprintf/src/system/lwprintf_sys_win32.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwprintf_sys_win32.c 3 | * \brief System functions for WIN32 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2024 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwPRINTF - Lightweight stdio manager library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v1.0.6 33 | */ 34 | #include "system/lwprintf_sys.h" 35 | 36 | #if LWPRINTF_CFG_OS && !__DOXYGEN__ 37 | 38 | #include "Windows.h" 39 | 40 | uint8_t 41 | lwprintf_sys_mutex_create(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 42 | *m = CreateMutex(NULL, FALSE, NULL); 43 | return 1; 44 | } 45 | 46 | uint8_t 47 | lwprintf_sys_mutex_isvalid(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 48 | return *m != NULL; 49 | } 50 | 51 | uint8_t 52 | lwprintf_sys_mutex_wait(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 53 | DWORD ret; 54 | ret = WaitForSingleObject(*m, INFINITE); 55 | if (ret != WAIT_OBJECT_0) { 56 | return 0; 57 | } 58 | return 1; 59 | } 60 | 61 | uint8_t 62 | lwprintf_sys_mutex_release(LWPRINTF_CFG_OS_MUTEX_HANDLE* m) { 63 | ReleaseMutex(*m); 64 | return 1; 65 | } 66 | 67 | #endif /* LWPRINTF_CFG_OS && !__DOXYGEN__ */ 68 | -------------------------------------------------------------------------------- /tests/test_results.test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaJerle/lwprintf/0eeaaa3fc7f83d9e7b829852472c130b19e53bda/tests/test_results.test --------------------------------------------------------------------------------