feat: 移植 lwprintf

feat: 创建 can 发送接口
feat: 添加编码器读数接口
This commit is contained in:
2024-04-19 17:16:24 +08:00
parent f0cbc9f1d3
commit 8408ab1cf3
21 changed files with 2522 additions and 94 deletions

View File

@@ -68,6 +68,9 @@
{ {
"path": "project/src/at32f413_wk_config.c" "path": "project/src/at32f413_wk_config.c"
}, },
{
"path": "project/src/by_debug.c"
},
{ {
"path": "project/src/main.c" "path": "project/src/main.c"
} }
@@ -129,7 +132,8 @@
".eide/deps", ".eide/deps",
"3rd-part/dwt_delay", "3rd-part/dwt_delay",
"3rd-part/PID-Library", "3rd-part/PID-Library",
"app" "app",
"3rd-part/lwprintf"
], ],
"libList": [], "libList": [],
"sourceDirList": [], "sourceDirList": [],

400
3rd-part/lwprintf/.gitignore vendored Normal file
View File

@@ -0,0 +1,400 @@
#Build Keil files
*.rar
*.o
*.d
*.crf
*.htm
*.dep
*.map
*.bak
*.axf
*.lnp
*.lst
*.ini
*.scvd
*.iex
*.sct
*.MajerleT
*.tjuln
*.tilen
*.dbgconf
*.uvguix
*.uvoptx
*.__i
*.i
*.txt
!docs/*.txt
!CMakeLists.txt
RTE/
*debug
# IAR Settings
**/settings/*.crun
**/settings/*.dbgdt
**/settings/*.cspy
**/settings/*.cspy.*
**/settings/*.xcl
**/settings/*.dni
**/settings/*.wsdt
**/settings/*.wspos
# IAR Debug Exe
**/Exe/*.sim
# IAR Debug Obj
**/Obj/*.pbd
**/Obj/*.pbd.*
**/Obj/*.pbi
**/Obj/*.pbi.*
*.TMP
/docs_src/x_Doxyfile.doxy
.DS_Store
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Dd]ebug*/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
_build/
build/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
*.out
*.sim
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# TypeScript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
log_file.txt
.metadata/
.mxproject
.settings/
project.ioc
mx.scratch
*.tilen majerle
# Altium
Project outputs*
History/
*.SchDocPreview
*.$$$Preview
# VSCode projects
project_vscode_compiled.exe

View File

@@ -0,0 +1,6 @@
Tilen Majerle <tilen.majerle@gmail.com>
Tilen Majerle <tilen@majerle.eu>
Okarss <104319900+Okarss@users.noreply.github.com>
Dmitry Karasev <karasevsdmitry@yandex.ru>
Brian <bayuan@purdue.edu>
Peter Maxwell Warasila <madmaxwell@soundcomesout.com>

View File

@@ -0,0 +1,41 @@
# Changelog
## Develop
- Add `lwprintf_debug` and `lwprintf_debug_cond` functions
## v1.0.5
- Fix building the library with `LWPRINTF_CFG_OS=1` and `LWPRINTF_CFG_OS_MANUAL_PROTECT=0` options
## v1.0.4
- Fix calculation for NULL terminated string and precision with 0 as an input
- Split CMakeLists.txt files between library and executable
- Fix missing break in switch statement
- Add support for manual mutual-exclusion setup in OS mode
- Change license year to 2022
- Update code style with astyle
- Add `.clang-format` draft
- Fix protection functions for when print mode is not used
## v1.0.3
- CMSIS-OS improvements for Kernel aware debuggers
## v1.0.2
- Fixed `float` output when engineering mode is disabled
## v1.0.1
- Fixed compiler error when engineering mode disabled but float enabled
- Properly handled `zero` float inputs
## v1.0.0
- First stable release
- Embedded systems optimized library
- Apply all modifiers except `%a`
- Extensive docs available
- Operating system ready with CMSIS-OS template

21
3rd-part/lwprintf/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Tilen MAJERLE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,29 @@
# Lightweight printf stdio manager
<h3>Read first: <a href="http://docs.majerle.eu/projects/lwprintf/">Documentation</a></h3>
## Features
* Written in C (C11), compatible with ``size_t`` and ``uintmax_t`` types for some specifiers
* Implements output functions compatible with ``printf``, ``vprintf``, ``snprintf``, ``sprintf`` and ``vsnprintf``
* Low-memory footprint, suitable for embedded systems
* Reentrant access to all API functions
* Operating-system ready
* Requires single output function to be implemented by user for ``printf``-like API calls
* With optional functions for operating systems to protect multiple threads printing to the same output stream
* Allows multiple output stream functions (unlike standard ``printf`` which supports only one) to separate parts of application
* Added additional specifiers vs original features
* User friendly MIT license
## Contribute
Fresh contributions are always welcome. Simple instructions to proceed:
1. Fork Github repository
2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project
3. Create a pull request to develop branch with new features or bug fixes
Alternatively you may:
1. Report a bug
2. Ask for a feature request

1274
3rd-part/lwprintf/lwprintf.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,313 @@
/**
* \file lwprintf.h
* \brief Lightweight stdio manager
*/
/*
* Copyright (c) 2024 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* This file is part of LwPRINTF - Lightweight stdio manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.5
*/
#ifndef LWPRINTF_HDR_H
#define LWPRINTF_HDR_H
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include "lwprintf_opt.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* \defgroup LWPRINTF Lightweight stdio manager
* \brief Lightweight stdio manager
* \{
*/
/**
* \brief Unused variable macro
* \param[in] x: Unused variable
*/
#define LWPRINTF_UNUSED(x) ((void)(x))
/**
* \brief Calculate size of statically allocated array
* \param[in] x: Input array
* \return Number of array elements
*/
#define LWPRINTF_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
/**
* \brief Forward declaration for LwPRINTF instance
*/
struct lwprintf;
/**
* \brief Callback function for character output
* \param[in] ch: Character to print
* \param[in] lwobj: LwPRINTF instance
* \return `ch` on success, `0` to terminate further string processing
*/
typedef int (*lwprintf_output_fn)(int ch, struct lwprintf* lwobj);
/**
* \brief LwPRINTF instance
*/
typedef struct lwprintf {
lwprintf_output_fn out_fn; /*!< Output function for direct print operations */
#if LWPRINTF_CFG_OS || __DOXYGEN__
LWPRINTF_CFG_OS_MUTEX_HANDLE mutex; /*!< OS mutex handle */
#endif /* LWPRINTF_CFG_OS || __DOXYGEN__ */
} lwprintf_t;
uint8_t lwprintf_init_ex(lwprintf_t* lwobj, lwprintf_output_fn out_fn);
int lwprintf_vprintf_ex(lwprintf_t* const lwobj, const char* format, va_list arg);
int lwprintf_printf_ex(lwprintf_t* const lwobj, const char* format, ...);
int lwprintf_vsnprintf_ex(lwprintf_t* const lwobj, char* s, size_t n, const char* format, va_list arg);
int lwprintf_snprintf_ex(lwprintf_t* const lwobj, char* s, size_t n, const char* format, ...);
uint8_t lwprintf_protect_ex(lwprintf_t* const lwobj);
uint8_t lwprintf_unprotect_ex(lwprintf_t* const lwobj);
/**
* \brief Write formatted data from variable argument list to sized buffer
* \param[in,out] lwobj: LwPRINTF instance. Set to `NULL` to use default instance
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
* The buffer should have a size of at least `n` characters
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
* \param[in] ...: Optional arguments for format string
* \return The number of characters that would have been written,
* not counting the terminating null character.
*/
#define lwprintf_sprintf_ex(lwobj, s, format, ...) lwprintf_snprintf_ex((lwobj), (s), SIZE_MAX, (format), ##__VA_ARGS__)
/**
* \brief Initialize default LwPRINTF instance
* \param[in] out_fn: Output function used for print operation
* \return `1` on success, `0` otherwise
* \sa lwprintf_init_ex
*/
#define lwprintf_init(out_fn) lwprintf_init_ex(NULL, (out_fn))
/**
* \brief Print formatted data from variable argument list to the output with default LwPRINTF instance
* \param[in] format: C string that contains the text to be written to output
* \param[in] arg: A value identifying a variable arguments list initialized with `va_start`.
* `va_list` is a special type defined in `<cstdarg>`.
* \return The number of characters that would have been written if `n` had been sufficiently large,
* not counting the terminating null character.
*/
#define lwprintf_vprintf(format, arg) lwprintf_vprintf_ex(NULL, (format), (arg))
/**
* \brief Print formatted data to the output with default LwPRINTF instance
* \param[in] format: C string that contains the text to be written to output
* \param[in] ...: Optional arguments for format string
* \return The number of characters that would have been written if `n` had been sufficiently large,
* not counting the terminating null character.
*/
#define lwprintf_printf(format, ...) lwprintf_printf_ex(NULL, (format), ##__VA_ARGS__)
/**
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
* The buffer should have a size of at least `n` characters
* \param[in] n: Maximum number of bytes to be used in the buffer.
* The generated string has a length of at most `n - 1`,
* leaving space for the additional terminating null character
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
* \param[in] arg: A value identifying a variable arguments list initialized with `va_start`.
* `va_list` is a special type defined in `<cstdarg>`.
* \return The number of characters that would have been written if `n` had been sufficiently large,
* not counting the terminating null character.
*/
#define lwprintf_vsnprintf(s, n, format, arg) lwprintf_vsnprintf_ex(NULL, (s), (n), (format), (arg))
/**
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
* The buffer should have a size of at least `n` characters
* \param[in] n: Maximum number of bytes to be used in the buffer.
* The generated string has a length of at most `n - 1`,
* leaving space for the additional terminating null character
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
* \param[in] ...: Optional arguments for format string
* \return The number of characters that would have been written if `n` had been sufficiently large,
* not counting the terminating null character.
*/
#define lwprintf_snprintf(s, n, format, ...) lwprintf_snprintf_ex(NULL, (s), (n), (format), ##__VA_ARGS__)
/**
* \brief Write formatted data from variable argument list to sized buffer with default LwPRINTF instance
* \param[in] s: Pointer to a buffer where the resulting C-string is stored.
* The buffer should have a size of at least `n` characters
* \param[in] format: C string that contains a format string that follows the same specifications as format in printf
* \param[in] ...: Optional arguments for format string
* \return The number of characters that would have been written,
* not counting the terminating null character.
*/
#define lwprintf_sprintf(s, format, ...) lwprintf_sprintf_ex(NULL, (s), (format), ##__VA_ARGS__)
/**
* \brief Manually enable mutual exclusion
* \return `1` if protected, `0` otherwise
*/
#define lwprintf_protect() lwprintf_protect_ex(NULL)
/**
* \brief Manually disable mutual exclusion
* \return `1` if protected, `0` otherwise
*/
#define lwprintf_unprotect() lwprintf_unprotect_ex(NULL)
#if LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__
/**
* \copydoc lwprintf_printf
* \note This function is equivalent to \ref lwprintf_printf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwprintf lwprintf_printf
/**
* \copydoc lwprintf_vprintf
* \note This function is equivalent to \ref lwprintf_vprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwvprintf lwprintf_vprintf
/**
* \copydoc lwprintf_vsnprintf
* \note This function is equivalent to \ref lwprintf_vsnprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwvsnprintf lwprintf_vsnprintf
/**
* \copydoc lwprintf_snprintf
* \note This function is equivalent to \ref lwprintf_snprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwsnprintf lwprintf_snprintf
/**
* \copydoc lwprintf_sprintf
* \note This function is equivalent to \ref lwprintf_sprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwsprintf lwprintf_sprintf
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__ */
#if LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__
/**
* \copydoc lwprintf_printf
* \note This function is equivalent to \ref lwprintf_printf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define printf lwprintf_printf
/**
* \copydoc lwprintf_vprintf
* \note This function is equivalent to \ref lwprintf_vprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define vprintf lwprintf_vprintf
/**
* \copydoc lwprintf_vsnprintf
* \note This function is equivalent to \ref lwprintf_vsnprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define vsnprintf lwprintf_vsnprintf
/**
* \copydoc lwprintf_snprintf
* \note This function is equivalent to \ref lwprintf_snprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define snprintf lwprintf_snprintf
/**
* \copydoc lwprintf_sprintf
* \note This function is equivalent to \ref lwprintf_sprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define sprintf lwprintf_sprintf
#endif /* LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__ */
/* Debug module */
#if !defined(NDEBUG)
/**
* \brief Debug output function
*
* Its purpose is to have a debug printout to the defined output,
* which will get disabled for the release build (when NDEBUG is defined).
*
* \note It calls \ref lwprintf_printf to execute the print
* \note Defined as empty when \ref NDEBUG is enabled
* \param[in] fmt: Format text
* \param[in] ...: Optional formatting parameters
*/
#define lwprintf_debug(fmt, ...) lwprintf_printf((fmt), ##__VA_ARGS__)
/**
* \brief Conditional debug output
*
* It prints the formatted text only if condition is true
*
* Its purpose is to have a debug printout to the defined output,
* which will get disabled for the release build (when NDEBUG is defined).
*
* \note It calls \ref lwprintf_debug to execute the print
* \note Defined as empty when \ref NDEBUG is enabled
* \param[in] cond: Condition to check before outputing the message
* \param[in] fmt: Format text
* \param[in] ...: Optional formatting parameters
*/
#define lwprintf_debug_cond(cond, fmt, ...) \
do { \
if ((cond)) { \
lwprintf_debug((fmt), ##__VA_ARGS__) \
} \
} while (0)
#else
#define lwprintf_debug(fmt, ...) ((void)0)
#define lwprintf_debug_cond(cond, fmt, ...) ((void)0)
#endif
/**
* \}
*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* LWPRINTF_HDR_H */

View File

@@ -0,0 +1,191 @@
/**
* \file lwprintf_opt.h
* \brief LwPRINTF options
*/
/*
* Copyright (c) 2024 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* This file is part of LwPRINTF - Lightweight stdio manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.5
*/
#ifndef LWPRINTF_OPT_HDR_H
#define LWPRINTF_OPT_HDR_H
/* Uncomment to ignore user options (or set macro in compiler flags) */
/* #define LWPRINTF_IGNORE_USER_OPTS */
/* Include application options */
#ifndef LWPRINTF_IGNORE_USER_OPTS
#include "lwprintf_opts.h"
#endif /* LWPRINTF_IGNORE_USER_OPTS */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* \defgroup LWPRINTF_OPT Configuration
* \brief LwPRINTF options
* \{
*/
/**
* \brief Enables `1` or disables `0` operating system support in the library
*
* \note When `LWPRINTF_CFG_OS` is enabled, user must implement functions in \ref LWPRINTF_SYS group.
*/
#ifndef LWPRINTF_CFG_OS
#define LWPRINTF_CFG_OS 0
#endif
/**
* \brief Mutex handle type
*
* \note This value must be set in case \ref LWPRINTF_CFG_OS is set to `1`.
* If data type is not known to compiler, include header file with
* definition before you define handle type
*/
#ifndef LWPRINTF_CFG_OS_MUTEX_HANDLE
#define LWPRINTF_CFG_OS_MUTEX_HANDLE void*
#endif
/**
* \brief Enables `1` or disables `0` manual mutex lock.
*
* When this feature is enabled, together with \ref LWPRINTF_CFG_OS, behavior is as following:
* - System mutex is kept created during init phase
* - Calls to direct printing functions are not thread-safe by default anymore
* - Calls to sprintf (buffer functions) are kept thread-safe
* - User must manually call \ref lwprintf_protect or \ref lwprintf_protect_ex functions to protect direct printing operation
* - User must manually call \ref lwprintf_unprotect or \ref lwprintf_unprotect_ex functions to exit protected area
*
* \note If you prefer to completely disable locking mechanism with this library,
* turn off \ref LWPRINTF_CFG_OS and fully manually handle mutual exclusion for non-reentrant functions
*/
#ifndef LWPRINTF_CFG_OS_MANUAL_PROTECT
#define LWPRINTF_CFG_OS_MANUAL_PROTECT 0
#endif
/**
* \brief Enables `1` or disables `0` support for `long long int` type, signed or unsigned.
*
*/
#ifndef LWPRINTF_CFG_SUPPORT_LONG_LONG
#define LWPRINTF_CFG_SUPPORT_LONG_LONG 1
#endif
/**
* \brief Enables `1` or disables `0` support for any specifier accepting any kind of integer types.
* This is enabling `%d, %b, %u, %o, %i, %x` specifiers
*
*/
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_INT
#define LWPRINTF_CFG_SUPPORT_TYPE_INT 1
#endif
/**
* \brief Enables `1` or disables `0` support `%p` pointer print type
*
* When enabled, architecture must support `uintptr_t` type, normally available with C11 standard
*/
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_POINTER
#define LWPRINTF_CFG_SUPPORT_TYPE_POINTER 1
#endif
/**
* \brief Enables `1` or disables `0` support `%f` float type
*
*/
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_FLOAT
#define LWPRINTF_CFG_SUPPORT_TYPE_FLOAT 1
#endif
/**
* \brief Enables `1` or disables `0` support for `%e` engineering output type for float numbers
*
* \note \ref LWPRINTF_CFG_SUPPORT_TYPE_FLOAT has to be enabled to use this feature
*
*/
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING
#define LWPRINTF_CFG_SUPPORT_TYPE_ENGINEERING 1
#endif
/**
* \brief Enables `1` or disables `0` support for `%s` for string output
*
*/
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_STRING
#define LWPRINTF_CFG_SUPPORT_TYPE_STRING 1
#endif
/**
* \brief Enables `1` or disables `0` support for `%k` for hex byte array output
*
*/
#ifndef LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY
#define LWPRINTF_CFG_SUPPORT_TYPE_BYTE_ARRAY 1
#endif
/**
* \brief Specifies default number of precision for floating number
*
* Represents number of digits to be used after comma if no precision
* is set with specifier itself
*
*/
#ifndef LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION
#define LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION 6
#endif
/**
* \brief Enables `1` or disables `0` optional short names for LwPRINTF API functions.
*
* It adds functions for default instance: `lwprintf`, `lwsnprintf` and others
*/
#ifndef LWPRINTF_CFG_ENABLE_SHORTNAMES
#define LWPRINTF_CFG_ENABLE_SHORTNAMES 1
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */
/**
* \brief Enables `1` or disables `0` C standard API names
*
* Disabled by default not to interfere with compiler implementation.
* Application may need to remove standard C STDIO library from linkage
* to be able to properly compile LwPRINTF with this option enabled
*/
#ifndef LWPRINTF_CFG_ENABLE_STD_NAMES
#define LWPRINTF_CFG_ENABLE_STD_NAMES 0
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */
/**
* \}
*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* LWPRINTF_OPT_HDR_H */

View File

@@ -0,0 +1,44 @@
/**
* \file lwprintf_opts_template.h
* \brief LwPRINTF configuration file
*/
/*
* Copyright (c) 2024 Tilen MAJERLE
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* This file is part of LwPRINTF - Lightweight stdio manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.5
*/
#ifndef LWPRINTF_OPTS_HDR_H
#define LWPRINTF_OPTS_HDR_H
/* Rename this file to "lwprintf_opts.h" for your application */
/*
* Open "include/lwprintf/lwprintf_opt.h" and
* copy & replace here settings you want to change values
*/
#endif /* LWPRINTF_OPTS_HDR_H */

View File

@@ -38,7 +38,7 @@
<ModeSub name="Activated" value="TRUE"/> <ModeSub name="Activated" value="TRUE"/>
</Mode> </Mode>
<Parameters> <Parameters>
<ParametersSub name="DividerValue" value="499"/> <ParametersSub name="DividerValue" value="19"/>
<ParametersSub name="Period" value="999"/> <ParametersSub name="Period" value="999"/>
<ParametersSub name="Overflow_Event" value="FALSE"/> <ParametersSub name="Overflow_Event" value="FALSE"/>
<ParametersSub name="OCMode_1" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/> <ParametersSub name="OCMode_1" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
@@ -67,16 +67,13 @@
</Mode> </Mode>
<Parameters> <Parameters>
<ParametersSub name="DividerValue" value="999"/> <ParametersSub name="DividerValue" value="999"/>
<ParametersSub name="Period" value="199"/> <ParametersSub name="Period" value="1999"/>
</Parameters> </Parameters>
</TMR4> </TMR4>
<USART2> <USART2>
<Mode> <Mode>
<ModeSub name="Mode" value="Asynchronous"/> <ModeSub name="Mode" value="Asynchronous"/>
</Mode> </Mode>
<Parameters>
<ParametersSub name="Mode" value="MODE_RX"/>
</Parameters>
</USART2> </USART2>
<NVIC> <NVIC>
<SysTick_Handler>0;0;0</SysTick_Handler> <SysTick_Handler>0;0;0</SysTick_Handler>

View File

@@ -33,18 +33,5 @@
"EIDE.OpenOCD.ExePath": "D:/Program Files (x86)/at32_OpenOCD_V2.0.2/bin/openocd.exe" "EIDE.OpenOCD.ExePath": "D:/Program Files (x86)/at32_OpenOCD_V2.0.2/bin/openocd.exe"
}, },
"extensions": { "extensions": {
"recommendations": [
"cl.eide",
"keroc.hex-fmt",
"xiaoyongdong.srecord",
"hars.cppsnippets",
"zixuanwang.linkerscript",
"redhat.vscode-yaml",
"IBM.output-colorizer",
"cschlosser.doxdocgen",
"ms-vscode.vscode-serial-monitor",
"dan-c-underwood.arm",
"marus25.cortex-debug"
]
} }
} }

31
app/by_can.c Normal file
View File

@@ -0,0 +1,31 @@
#include "by_can.h"
#include <string.h>
#include <assert.h>
uint8_t by_can_send_stdd(uint32_t id, const uint8_t *data, uint8_t len)
{
assert(id < 0x7FF);
if (len > 8) {
len = 8;
}
uint8_t transmit_mailbox;
can_tx_message_type tx_message_struct;
tx_message_struct.standard_id = id; /* 设置发送数据帧的 ID=0x400 */
tx_message_struct.extended_id = 0; /* 不设置 */
tx_message_struct.id_type = CAN_ID_STANDARD; /* 发送数据帧类型(标准/扩展):标准数据帧 */
tx_message_struct.frame_type = CAN_TFT_DATA; /* 发送帧类型(远程/数据):数据帧 */
tx_message_struct.dlc = len; /* 发送数据长度0~88 */
memcpy(tx_message_struct.data, data, len); /* 复制发送数据 */
transmit_mailbox = can_message_transmit(CAN1, &tx_message_struct); /* 将以上待发送报文写入发送邮箱并请求发送 */
/* 等待该邮箱发送成功—对应邮箱发送成功标志置起 */
while (can_transmit_status_get(CAN1, (can_tx_mailbox_num_type)transmit_mailbox) !=
CAN_TX_STATUS_SUCCESSFUL)
;
return 0;
}

8
app/by_can.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _BY_CAN_H__
#define _BY_CAN_H__
#include "at32f413.h"
uint8_t by_can_send_stdd(uint32_t id, const uint8_t *data, uint8_t len);
#endif

View File

@@ -6,6 +6,9 @@
#define DRV_ENABLE() gpio_bits_set(GPIOB, GPIO_PINS_15) #define DRV_ENABLE() gpio_bits_set(GPIOB, GPIO_PINS_15)
#define DRV_DISABLE() gpio_bits_reset(GPIOB, GPIO_PINS_15) #define DRV_DISABLE() gpio_bits_reset(GPIOB, GPIO_PINS_15)
int16_t speed_m1;
int16_t speed_m2;
void by_motion_pwm_m1(int32_t pwm_duty) void by_motion_pwm_m1(int32_t pwm_duty)
{ {
pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦 pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦
@@ -24,10 +27,23 @@ void by_motion_pwm_m2(int32_t pwm_duty)
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, pwm_duty); tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, pwm_duty);
} }
int16_t by_motion_get_speed_m1(void)
{
speed_m1 = (int16_t)tmr_counter_value_get(TMR2);
tmr_counter_value_set(TMR2, 0);
return speed_m1;
}
int16_t by_motion_get_speed_m2(void)
{
speed_m2 = (int16_t)tmr_counter_value_get(TMR3);
tmr_counter_value_set(TMR3, 0);
return speed_m2;
}
void by_motion_init(void) void by_motion_init(void)
{ {
DRV_ENABLE(); DRV_ENABLE();
by_motion_pwm_m1(125); by_motion_pwm_m1(-125);
by_motion_pwm_m2(0); by_motion_pwm_m2(0);
} }

View File

@@ -3,6 +3,11 @@
#include "at32f413.h" #include "at32f413.h"
void by_motion_init(void); extern void by_motion_init(void);
extern int16_t by_motion_get_speed_m1(void);
extern int16_t by_motion_get_speed_m2(void);
extern int16_t speed_m1;
extern int16_t speed_m2;
#endif #endif

31
project/inc/by_debug.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef _BY_DEBUG_H__
#define _BY_DEBUG_H__
#include <stdio.h>
#include "at32f413.h"
#include "lwprintf.h"
#define BY_DEBUG_USART_INDEX (USART2)
#define BY_DEBUG_LOG_MODE (2) // 0-not log, 1-no debug log, 2-all
#if (BY_DEBUG_LOG_MODE == 2)
#define LOGI(format, ...) lwprintf("[INFO] " format "\r\n", ##__VA_ARGS__)
#define LOGW(format, ...) lwprintf("[WARN] " format "\r\n", ##__VA_ARGS__)
#define LOGE(format, ...) lwprintf("[ERR] " format "\r\n", ##__VA_ARGS__)
#define LOGD(format, ...) lwprintf("[DEBUG] " format "\r\n", ##__VA_ARGS__)
#elif (BY_DEBUG_LOG_MODE == 1)
#define LOGI(format, ...) lwprintf("[INFO] " format "\r\n", ##__VA_ARGS__)
#define LOGW(format, ...) lwprintf("[WARN] " format "\r\n", ##__VA_ARGS__)
#define LOGE(format, ...) lwprintf("[ERR] " format "\r\n", ##__VA_ARGS__)
#define LOGD(format, ...)
#elif (BY_DEBUG_LOG_MODE == 0)
#define LOGI(format, ...)
#define LOGW(format, ...)
#define LOGE(format, ...)
#define LOGD(format, ...)
#endif
extern void by_debug_init(void);
#endif

View File

@@ -1,27 +1,27 @@
/* add user code begin Header */ /* add user code begin Header */
/** /**
************************************************************************** **************************************************************************
* @file at32f413_int.c * @file at32f413_int.c
* @brief main interrupt service routines. * @brief main interrupt service routines.
************************************************************************** **************************************************************************
* Copyright notice & Disclaimer * Copyright notice & Disclaimer
* *
* The software Board Support Package (BSP) that is made available to * The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery. * download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP * Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and * software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the * development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer. * software is governed by this copyright notice and the following disclaimer.
* *
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
* *
************************************************************************** **************************************************************************
*/ */
/* add user code end Header */ /* add user code end Header */
/* includes ------------------------------------------------------------------*/ /* includes ------------------------------------------------------------------*/
@@ -29,7 +29,7 @@
/* private includes ----------------------------------------------------------*/ /* private includes ----------------------------------------------------------*/
/* add user code begin private includes */ /* add user code begin private includes */
#include "by_motion.h"
/* add user code end private includes */ /* add user code end private includes */
/* private typedef -----------------------------------------------------------*/ /* private typedef -----------------------------------------------------------*/
@@ -68,10 +68,10 @@
/* add user code end external variables */ /* add user code end external variables */
/** /**
* @brief this function handles nmi exception. * @brief this function handles nmi exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void NMI_Handler(void) void NMI_Handler(void)
{ {
/* add user code begin NonMaskableInt_IRQ 0 */ /* add user code begin NonMaskableInt_IRQ 0 */
@@ -84,18 +84,17 @@ void NMI_Handler(void)
} }
/** /**
* @brief this function handles hard fault exception. * @brief this function handles hard fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
/* add user code begin HardFault_IRQ 0 */ /* add user code begin HardFault_IRQ 0 */
/* add user code end HardFault_IRQ 0 */ /* add user code end HardFault_IRQ 0 */
/* go to infinite loop when hard fault exception occurs */ /* go to infinite loop when hard fault exception occurs */
while (1) while (1) {
{
/* add user code begin W1_HardFault_IRQ 0 */ /* add user code begin W1_HardFault_IRQ 0 */
/* add user code end W1_HardFault_IRQ 0 */ /* add user code end W1_HardFault_IRQ 0 */
@@ -103,18 +102,17 @@ void HardFault_Handler(void)
} }
/** /**
* @brief this function handles memory manage exception. * @brief this function handles memory manage exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void MemManage_Handler(void) void MemManage_Handler(void)
{ {
/* add user code begin MemoryManagement_IRQ 0 */ /* add user code begin MemoryManagement_IRQ 0 */
/* add user code end MemoryManagement_IRQ 0 */ /* add user code end MemoryManagement_IRQ 0 */
/* go to infinite loop when memory manage exception occurs */ /* go to infinite loop when memory manage exception occurs */
while (1) while (1) {
{
/* add user code begin W1_MemoryManagement_IRQ 0 */ /* add user code begin W1_MemoryManagement_IRQ 0 */
/* add user code end W1_MemoryManagement_IRQ 0 */ /* add user code end W1_MemoryManagement_IRQ 0 */
@@ -122,18 +120,17 @@ void MemManage_Handler(void)
} }
/** /**
* @brief this function handles bus fault exception. * @brief this function handles bus fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void BusFault_Handler(void) void BusFault_Handler(void)
{ {
/* add user code begin BusFault_IRQ 0 */ /* add user code begin BusFault_IRQ 0 */
/* add user code end BusFault_IRQ 0 */ /* add user code end BusFault_IRQ 0 */
/* go to infinite loop when bus fault exception occurs */ /* go to infinite loop when bus fault exception occurs */
while (1) while (1) {
{
/* add user code begin W1_BusFault_IRQ 0 */ /* add user code begin W1_BusFault_IRQ 0 */
/* add user code end W1_BusFault_IRQ 0 */ /* add user code end W1_BusFault_IRQ 0 */
@@ -141,18 +138,17 @@ void BusFault_Handler(void)
} }
/** /**
* @brief this function handles usage fault exception. * @brief this function handles usage fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void UsageFault_Handler(void) void UsageFault_Handler(void)
{ {
/* add user code begin UsageFault_IRQ 0 */ /* add user code begin UsageFault_IRQ 0 */
/* add user code end UsageFault_IRQ 0 */ /* add user code end UsageFault_IRQ 0 */
/* go to infinite loop when usage fault exception occurs */ /* go to infinite loop when usage fault exception occurs */
while (1) while (1) {
{
/* add user code begin W1_UsageFault_IRQ 0 */ /* add user code begin W1_UsageFault_IRQ 0 */
/* add user code end W1_UsageFault_IRQ 0 */ /* add user code end W1_UsageFault_IRQ 0 */
@@ -160,10 +156,10 @@ void UsageFault_Handler(void)
} }
/** /**
* @brief this function handles svcall exception. * @brief this function handles svcall exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void SVC_Handler(void) void SVC_Handler(void)
{ {
/* add user code begin SVCall_IRQ 0 */ /* add user code begin SVCall_IRQ 0 */
@@ -175,10 +171,10 @@ void SVC_Handler(void)
} }
/** /**
* @brief this function handles debug monitor exception. * @brief this function handles debug monitor exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void DebugMon_Handler(void) void DebugMon_Handler(void)
{ {
/* add user code begin DebugMonitor_IRQ 0 */ /* add user code begin DebugMonitor_IRQ 0 */
@@ -190,10 +186,10 @@ void DebugMon_Handler(void)
} }
/** /**
* @brief this function handles pendsv_handler exception. * @brief this function handles pendsv_handler exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void PendSV_Handler(void) void PendSV_Handler(void)
{ {
/* add user code begin PendSV_IRQ 0 */ /* add user code begin PendSV_IRQ 0 */
@@ -205,14 +201,18 @@ void PendSV_Handler(void)
} }
/** /**
* @brief this function handles TMR4 handler. * @brief this function handles TMR4 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void TMR4_GLOBAL_IRQHandler(void) void TMR4_GLOBAL_IRQHandler(void)
{ {
/* add user code begin TMR4_GLOBAL_IRQ 0 */ /* add user code begin TMR4_GLOBAL_IRQ 0 */
if (SET == tmr_interrupt_flag_get(TMR4, TMR_OVF_FLAG)) {
by_motion_get_speed_m1();
by_motion_get_speed_m2();
tmr_flag_clear(TMR4, TMR_OVF_FLAG);
}
/* add user code end TMR4_GLOBAL_IRQ 0 */ /* add user code end TMR4_GLOBAL_IRQ 0 */
/* add user code begin TMR4_GLOBAL_IRQ 1 */ /* add user code begin TMR4_GLOBAL_IRQ 1 */

View File

@@ -282,6 +282,7 @@ void wk_usart2_init(void)
/* configure param */ /* configure param */
usart_init(USART2, 115200, USART_DATA_8BITS, USART_STOP_1_BIT); usart_init(USART2, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
usart_transmitter_enable(USART2, TRUE);
usart_receiver_enable(USART2, TRUE); usart_receiver_enable(USART2, TRUE);
usart_parity_selection_config(USART2, USART_PARITY_NONE); usart_parity_selection_config(USART2, USART_PARITY_NONE);
@@ -348,7 +349,7 @@ void wk_tmr1_init(void)
gpio_init(GPIOA, &gpio_init_struct); gpio_init(GPIOA, &gpio_init_struct);
/* configure counter settings */ /* configure counter settings */
tmr_base_init(TMR1, 999, 499); tmr_base_init(TMR1, 999, 19);
tmr_cnt_dir_set(TMR1, TMR_COUNT_UP); tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1); tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);
tmr_repetition_counter_set(TMR1, 0); tmr_repetition_counter_set(TMR1, 0);
@@ -562,7 +563,7 @@ void wk_tmr4_init(void)
/* add user code end tmr4_init 1 */ /* add user code end tmr4_init 1 */
/* configure counter settings */ /* configure counter settings */
tmr_base_init(TMR4, 199, 999); tmr_base_init(TMR4, 1999, 999);
tmr_cnt_dir_set(TMR4, TMR_COUNT_UP); tmr_cnt_dir_set(TMR4, TMR_COUNT_UP);
tmr_clock_source_div_set(TMR4, TMR_CLOCK_DIV1); tmr_clock_source_div_set(TMR4, TMR_CLOCK_DIV1);
tmr_period_buffer_enable(TMR4, FALSE); tmr_period_buffer_enable(TMR4, FALSE);
@@ -582,7 +583,7 @@ void wk_tmr4_init(void)
*/ */
/* add user code begin tmr4_init 2 */ /* add user code begin tmr4_init 2 */
tmr_interrupt_enable(TMR4, TMR_OVF_INT, TRUE);
/* add user code end tmr4_init 2 */ /* add user code end tmr4_init 2 */
} }

23
project/src/by_debug.c Normal file
View File

@@ -0,0 +1,23 @@
#include "by_debug.h"
#include "at32f413.h"
#include "lwprintf.h"
int lwprintf_out(int ch, lwprintf_t *lwp)
{
/* May use printf to output it for test */
if (ch != '\0') {
while (usart_flag_get(BY_DEBUG_USART_INDEX, USART_TDC_FLAG) == RESET)
;
usart_data_transmit(BY_DEBUG_USART_INDEX, (char)ch);
}
return ch;
}
void by_debug_init(void)
{
lwprintf_init(lwprintf_out);
}

View File

@@ -31,6 +31,8 @@
/* add user code begin private includes */ /* add user code begin private includes */
#include "dwt_delay.h" #include "dwt_delay.h"
#include "by_debug.h"
#include "by_can.h"
#include "by_motion.h" #include "by_motion.h"
/* add user code end private includes */ /* add user code end private includes */
@@ -72,7 +74,7 @@
int main(void) int main(void)
{ {
/* add user code begin 1 */ /* add user code begin 1 */
by_debug_init();
/* add user code end 1 */ /* add user code end 1 */
/* system clock config. */ /* system clock config. */
@@ -110,8 +112,12 @@ int main(void)
/* add user code begin 2 */ /* add user code begin 2 */
DWT_Init(); DWT_Init();
LOGD("dwt init done");
by_motion_init(); by_motion_init();
LOGD("motion init done");
LOGI("init done");
/* add user code end 2 */ /* add user code end 2 */
while(1) while(1)