樊春春 2 месяцев назад
Родитель
Сommit
ce5af60be1

+ 206 - 148
.clang-format

@@ -1,7 +1,7 @@
 ---
 # 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
-Language:        Cpp
-# BasedOnStyle:  LLVM
+Language: Cpp
+BasedOnStyle: Google
 # 访问说明符(public、private等)的偏移
 AccessModifierOffset: -4
 # 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
@@ -9,24 +9,44 @@ AlignAfterOpenBracket: Align
 # 对齐数组列
 AlignArrayOfStructures: None
 # 对齐连续宏定义
-AlignConsecutiveMacros: true
+AlignConsecutiveMacros: #AcrossEmptyLinesAndComments
+  Enabled: true
+  AcrossEmptyLines: true
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
 # 连续赋值时,对齐所有等号
-AlignConsecutiveAssignments: true
+AlignConsecutiveAssignments:
+  Enabled: true
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
 # 对齐连续位字段
-AlignConsecutiveBitFields: true
+AlignConsecutiveBitFields:
+  Enabled: true
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
 # 连续声明时,对齐所有声明的变量名
-AlignConsecutiveDeclarations: true
+AlignConsecutiveDeclarations:
+  Enabled: true
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
 # 左对齐逃脱换行(使用反斜杠换行)的反斜杠
-AlignEscapedNewlines: Right
+AlignEscapedNewlines: Left
 # 水平对齐二元和三元表达式的操作数
 AllowAllArgumentsOnNextLine: true
 AllowAllConstructorInitializersOnNextLine: true
 AlwaysBreakAfterDefinitionReturnType: None
-AlignOperands:   Align
+AlignOperands: true #Align
 # 对齐连续的尾随的注释
 AlignTrailingComments: true
 # 允许函数声明的所有参数在放在下一行
-AllowAllParametersOfDeclarationOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: false
 # 允许短的枚举放在同一行
 AllowShortEnumsOnASingleLine: true
 # 允许短的块放在同一行
@@ -34,7 +54,7 @@ AllowShortBlocksOnASingleLine: Never
 # 允许短的case标签放在同一行
 AllowShortCaseLabelsOnASingleLine: false
 # 允许短的函数放在同一行
-AllowShortFunctionsOnASingleLine: All
+AllowShortFunctionsOnASingleLine: false #All
 # 允许短的匿名函数放在同一行
 AllowShortLambdasOnASingleLine: All
 # 允许短的if语句保持在同一行
@@ -47,142 +67,138 @@ AlwaysBreakAfterReturnType: None
 AlwaysBreakBeforeMultilineStrings: false
 # 总是在template声明后换行
 AlwaysBreakTemplateDeclarations: MultiLine
+# 属性声明相关配置
 AttributeMacros:
   - __capability
 # false表示函数实参要么都在同一行,要么都各自一行
 BinPackArguments: true
 # false表示所有形参要么都在同一行,要么都各自一行
 BinPackParameters: true
-# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
+# 是否允许短方法单行,只有一行的函数将不会分行,直接写在函数名后
+# 括号是分行,还是不分行,只有当 BreakBeforeBraces 设置为 Custom 时才有效
 BraceWrapping:
-  AfterCaseLabel:  false
-  AfterClass:      false
-  AfterControlStatement: Never
-  AfterEnum:       false
-  AfterFunction:   false
-  AfterNamespace:  false
-  AfterObjCDeclaration: false
-  AfterStruct:     false
-  AfterUnion:      false
+  AfterCaseLabel: true
+  # class 定义后面
+  AfterClass: true
+  # 控制语句后面
+  AfterControlStatement: true
+  AfterEnum: true
+  AfterFunction: true
+  AfterNamespace: true
+  AfterObjCDeclaration: true
+  AfterStruct: true
+  AfterUnion: true
   AfterExternBlock: false
-  BeforeCatch:     false
-  BeforeElse:      false
-  BeforeLambdaBody: false
-  BeforeWhile:     false
-  IndentBraces:    false
+  BeforeCatch: true
+  BeforeElse: true
+  # 缩进大括号
+  IndentBraces: false
   SplitEmptyFunction: true
   SplitEmptyRecord: true
   SplitEmptyNamespace: true
-# 在二元运算符前换行
 BreakBeforeBinaryOperators: None
-# 在concept前换行
-BreakBeforeConceptDeclarations: true
-# 在大括号前换行: Attach(始终将大括号附加到周围的上下文)
-BreakBeforeBraces: Allman
+# BreakAfterAttributes: Never
+# BreakArrays: true
+# BreakBeforeConceptDeclarations: Always
+BreakBeforeBraces: Custom
 BreakBeforeInheritanceComma: false
-# 继承列表样式
-BreakInheritanceList: AfterComma
-# 在三元运算符前换行
+BreakInheritanceList: BeforeColon
+# 三元运算符换行后在前
 BreakBeforeTernaryOperators: true
-# 构造函数初始值设定项换行样式
-BreakConstructorInitializers: BeforeComma
-# 在java字段的注释后换行
+BreakConstructorInitializersBeforeComma: false
+# 构造函数初始化列表换行规则
+BreakConstructorInitializers: BeforeColon
 BreakAfterJavaFieldAnnotations: false
-# 每行字符的限制,0表示没有限制
-ColumnLimit:     0
-# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
-CommentPragmas:  '^ IWYU pragma:'
-# 在新行上声明每个命名空间
+BreakStringLiterals: true
+# 代码最大列数
+ColumnLimit: 0
+CommentPragmas: "^ IWYU pragma:"
 CompactNamespaces: false
-# 构造函数的初始化列表的缩进宽度
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+# 构造函数初始化列表和继承列表换行后缩进的字符数,无符号整数。
 ConstructorInitializerIndentWidth: 4
-# 延续的行的缩进宽度
+# 当一行代码放不下,自动换行后的缩进
 ContinuationIndentWidth: 4
-# 去除C++11的列表初始化的大括号{后和}前的空格
+# 大括号列表附近是否有空格{ 1, 2 }/{1, 2}
 Cpp11BracedListStyle: true
-# 继承最常用的换行方式
 DeriveLineEnding: true
-# 继承最常用的指针和引用的对齐方式
 DerivePointerAlignment: false
-# 关闭格式化
-DisableFormat:   false
-# 删除访问修饰符后的所有空行
+# 设置位false后可以使用// clang-format off .. // clang-format on注释禁用某段代码格式化
+DisableFormat: false
+# 类中访问修饰符后放置空行
 EmptyLineAfterAccessModifier: Never
-# 仅当访问修饰符开始一个新的逻辑块时才添加空行
+# 类中访问修饰符之前放置空行
 EmptyLineBeforeAccessModifier: LogicalBlock
-# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
 ExperimentalAutoDetectBinPacking: false
-# 自动补充namespace注释
+# 自动修复命名空间注释名称
 FixNamespaceComments: true
-# 需要被解读为foreach循环而不是函数调用的宏
 ForEachMacros:
+  - forever
   - foreach
   - Q_FOREACH
   - BOOST_FOREACH
 IfMacros:
   - KJ_IF_MAYBE
-# 多个#include块合并在一起并排序为一个
-IncludeBlocks:   Merge
-# 可以定义负数优先级从而保证某些#include永远在最前面
+# 头文件分类排序
+IncludeBlocks: Preserve
 IncludeCategories:
-  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
-    Priority:        2
-    SortPriority:    0
-    CaseSensitive:   false
-  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
-    Priority:        3
-    SortPriority:    0
-    CaseSensitive:   false
-  - Regex:           '.*'
-    Priority:        1
-    SortPriority:    0
-    CaseSensitive:   false
-IncludeIsMainRegex: '(Test)?$'
-IncludeIsMainSourceRegex: ''
-# 缩进访问修饰符
+  - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority: 2
+    SortPriority: 0
+  - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+    Priority: 3
+    SortPriority: 0
+  - Regex: ".*"
+    Priority: 1
+    SortPriority: 0
+IncludeIsMainRegex: "(Test)?$"
+IncludeIsMainSourceRegex: ""
+# 指定访问修饰符是否应具有自己的缩进级别
 IndentAccessModifiers: false
-# 缩进case标签
-IndentCaseLabels: false
-# case 标签后面的块使用与 case 标签相同的缩进级别
-IndentCaseBlocks: false
-# 缩进goto标签。
-IndentGotoLabels: false
-# 缩进预处理器指令
-IndentPPDirectives: None
-# 向后兼容缩进外部块
+# case的{}缩进
+IndentCaseBlocks: true
+# case的标签是否缩进
+IndentCaseLabels: true
 IndentExternBlock: AfterExternBlock
-# 缩进模板中的requires子句
-IndentRequires:  false
-# 缩进宽度
-IndentWidth:     4
-# 函数返回类型换行时,缩进函数声明或函数定义的函数名
+IndentGotoLabels: true
+# 预处理器指令缩进样式
+IndentPPDirectives: None
+IndentRequiresClause: true
+# 换行缩进字符数
+IndentWidth: 4
 IndentWrappedFunctionNames: false
-# 插入尾随逗号
-InsertTrailingCommas: None
-# 保留JavaScript字符串引号
+# 控制语句(if、else、for、do和while)后面自动插入大括号(危险,可能导致代码错误)
+InsertBraces: false
+# InsertNewlineAtEOF: false
+# 仅适用于 JavaScript
+# InsertTrailingCommas: None
+# IntegerLiteralSeparator: # 格式化整数文字分隔符
+#   Binary: 4 # 二进制文本中的分隔符格式,按4位分割
+#   BinaryMinDigits: 0 # 达到多少位二进制文本才进行分割
+#   Decimal: 3 # 以十进制文字格式设置分隔符的格式。
+#   DecimalMinDigits: 0 # 十进制最小分割位数
+#   Hex: 2 # 十六进制文字格式分割个数
+#   HexMinDigits: 0
 JavaScriptQuotes: Leave
-# 包装 JavaScript 导入/导出语句
 JavaScriptWrapImports: true
-# 保留在块开始处的空行
 KeepEmptyLinesAtTheStartOfBlocks: true
-# 相对于 lambda 签名对齐 lambda 主体
+# lambda表达式换行、缩进样式样式
 LambdaBodyIndentation: Signature
-# 开始一个块的宏的正则表达式
-MacroBlockBegin: ''
-# 结束一个块的宏的正则表达式
-MacroBlockEnd:   ''
-# 连续空行的最大
+# 换行符样
+# LineEnding: DeriveLF
+MacroBlockBegin: ""
+MacroBlockEnd: ""
+# 要保留的最大连续空行数
 MaxEmptyLinesToKeep: 1
-# 命名空间缩进
+# 命名空间缩进
 NamespaceIndentation: None
 ObjCBinPackProtocolList: Auto
-# 使用ObjC块时缩进宽度
-ObjCBlockIndentWidth: 4
+ObjCBlockIndentWidth: 0
 ObjCBreakBeforeNestedBlockParam: true
-# 在ObjC的@property后添加一个空格
 ObjCSpaceAfterProperty: false
-# 在ObjC的protocol列表前添加一个空格
 ObjCSpaceBeforeProtocolList: true
+# 设置初始化列表,和BreakConstructorInitializers 有一定冲突
+PackConstructorInitializers: BinPack
 PenaltyBreakAssignment: 2
 PenaltyBreakBeforeFirstCallParameter: 19
 PenaltyBreakComment: 300
@@ -191,73 +207,76 @@ PenaltyBreakString: 1000
 PenaltyBreakTemplateDeclaration: 10
 PenaltyExcessCharacter: 1000000
 PenaltyReturnTypeOnItsOwnLine: 60
-PenaltyIndentedWhitespace: 0
-# 指针的对齐: Left, Right, Middle
+# 指针对齐风格
 PointerAlignment: Right
-# 缩进预处理器语句的列数
-PPIndentWidth:   -1
-# 引用的对齐
-ReferenceAlignment: Pointer
-# 允许重新排版注释
-ReflowComments:  true
-# 短命名空间跨越的最大展开行数
+ReflowComments: true
+PPIndentWidth: -1
+# 不同的排列说明符和限定符的方法(危险,可能改变代码含义)
+QualifierAlignment: Leave
+# 引用对齐风格
+# ReferenceAlignment: Pointer
+# RemoveBracesLLVM: false
+# RemoveSemicolon: false
+# RequiresClausePosition: OwnLine
+# RequiresExpressionIndentation: OuterScope
+# 指定使用空行分隔定义块,包括 类、结构、枚举和函数。
+SeparateDefinitionBlocks: Always
 ShortNamespaceLines: 1
-# 允许排序#include
-SortIncludes:    true
-# java静态导入放在非静态导入之前
+# 头文件排序规则
+SortIncludes: CaseSensitive
 SortJavaStaticImport: Before
-# using声明排序
+# using声明排序 Lexicographic
 SortUsingDeclarations: true
-# 在C风格类型转换后添加空格
-SpaceAfterCStyleCast: false
-# 在!后添加空格
+# 定义在哪些情况下在左括号之前放置空格
+SpaceBeforeParens: Custom
+# 在C语言风格的强制类型转换后插入空格
+SpaceAfterCStyleCast: true
+# 不在逻辑运算符 !后插入控制
 SpaceAfterLogicalNot: false
-# 在Template关键字后添加空格
 SpaceAfterTemplateKeyword: true
-# 在赋值运算符之前添加空格
+SpaceAroundPointerQualifiers: Default
+# 赋值运算符前是否有空格
 SpaceBeforeAssignmentOperators: true
-# 不在case冒号之前添加空格
+# case的:前是否有空格
 SpaceBeforeCaseColon: false
-# 不在C++11大括号列表之前添加空格
+# 调用构造函数时初始化列表的大括号前面是否有空格
 SpaceBeforeCpp11BracedList: false
-# 在构造函数初始化器冒号之前添加空格
+# 构造函数的:前面是否有空格
 SpaceBeforeCtorInitializerColon: true
-# 在继承冒号前添加空格
+# 继承的:前面是否有空格
 SpaceBeforeInheritanceColon: true
-# 开圆括号之前添加一个空格: Never, ControlStatements, Always
-SpaceBeforeParens: ControlStatements
-# 不要确保指针限定符周围有空格,而是使用 PointerAlignment
-SpaceAroundPointerQualifiers: Default
-# 在基于范围的for循环冒号之前添加空格
+# 函数调用时括号前添加空格
+# SpaceBeforeParentheses: true
+# 括号内部添加空格
+SpacesInParentheses: false
+# 范围的for循环冒号之前删除空格
 SpaceBeforeRangeBasedForLoopColon: true
-# {}中间不添加空格
 SpaceInEmptyBlock: false
-# 在空的圆括号中添加空格
 SpaceInEmptyParentheses: false
-# 在尾随的评论前添加的空格数(只适用于//)
+# 尾部//注释之前的空格
 SpacesBeforeTrailingComments: 1
-# 在尖括号的<后和>前添加空格
-SpacesInAngles:  Never
-# 不在if/for/switch/while条件周围插入空格
+SpacesInAngles: false
 SpacesInConditionalStatement: false
-# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
 SpacesInContainerLiterals: true
-# 在C风格类型转换的括号中添加空格
 SpacesInCStyleCastParentheses: false
-# 行注释开头允许有多少个空格。要禁用最大值,请将其设置为-1,除此之外,最大值优先于最小值
-SpacesInLineCommentPrefix:
-  Minimum:         1
-  Maximum:         -1
-# 在圆括号的(后和)前添加空格
-SpacesInParentheses: false
-# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
 SpacesInSquareBrackets: false
 # 不在[前添加空格
 SpaceBeforeSquareBrackets: false
+# 单独控制不同情况下括号前面的空格,在SpaceBeforeParens==Custom时生效
+SpaceBeforeParensOptions:
+  AfterControlStatements: true
+  AfterForeachMacros: true
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+  AfterIfMacros: true
+  AfterOverloadedOperator: true
+  AfterRequiresInClause: true
+  AfterRequiresInExpression: true
+  BeforeNonEmptyParentheses: true
 # 位域:每边都添加空格
 BitFieldColonSpacing: Both
-# 标准
-Standard:        Latest
+# 标准 解析和格式化与此标准兼容的c++结构
+Standard: Latest
 # 在语句前面被忽略的宏定义,就好像它们是一个属性一样
 StatementAttributeLikeMacros:
   - Q_EMIT
@@ -265,12 +284,49 @@ StatementAttributeLikeMacros:
 StatementMacros:
   - Q_UNUSED
   - QT_REQUIRE_VERSION
+  - Q_CLASSINFO
+  - Q_ENUM
+  - Q_ENUM_NS
+  - Q_FLAG
+  - Q_FLAG_NS
+  - Q_GADGET
+  - Q_GADGET_EXPORT
+  - Q_INTERFACES
+  - Q_MOC_INCLUDE
+  - Q_NAMESPACE
+  - Q_NAMESPACE_EXPORT
+  - Q_OBJECT
+  - Q_PROPERTY
+  - Q_REVISION
+  - Q_DISABLE_COPY
+  - Q_SET_OBJECT_NAME
+  - QT_BEGIN_NAMESPACE
+  - QT_END_NAMESPACE
+  - QML_ADDED_IN_MINOR_VERSION
+  - QML_ANONYMOUS
+  - QML_ATTACHED
+  - QML_DECLARE_TYPE
+  - QML_DECLARE_TYPEINFO
+  - QML_ELEMENT
+  - QML_EXTENDED
+  - QML_EXTENDED_NAMESPACE
+  - QML_EXTRA_VERSION
+  - QML_FOREIGN
+  - QML_FOREIGN_NAMESPACE
+  - QML_IMPLEMENTS_INTERFACES
+  - QML_INTERFACE
+  - QML_NAMED_ELEMENT
+  - QML_REMOVED_IN_MINOR_VERSION
+  - QML_SINGLETON
+  - QML_UNAVAILABLE
+  - QML_UNCREATABLE
+  - QML_VALUE_TYPE
 # tab宽度
-TabWidth:        4
+TabWidth: 4
 # 使用\n换行
-UseCRLF:         false
+UseCRLF: false
 # 使用tab字符:ForIndentation——仅将制表符用于缩进
-UseTab:          Never
+UseTab: Never
 # 对空格敏感的宏定义
 WhitespaceSensitiveMacros:
   - STRINGIZE
@@ -278,3 +334,5 @@ WhitespaceSensitiveMacros:
   - BOOST_PP_STRINGIZE
   - NS_SWIFT_NAME
   - CF_SWIFT_NAME
+---
+

+ 92 - 0
.clang-tidy

@@ -0,0 +1,92 @@
+---
+Checks: '-*,
+        clang-analyzer-core.*,
+        clang-analyzer-cplusplus.*,
+        modernize-redundant-void-arg,
+        modernize-use-bool-literals,
+        modernize-use-equals-default,
+        modernize-use-nullptr,
+        modernize-use-override,
+        google-explicit-constructor,
+        google-readability-casting,
+        readability-braces-around-statements,
+        readability-identifier-naming.ClassCase,
+        readability-identifier-naming.StructCase,
+        readability-identifier-naming.TypedefCase,
+        readability-identifier-naming.EnumCase,
+        readability-non-const-parameter,
+        cert-dcl21-cpp,
+        bugprone-undelegated-constructor,
+        bugprone-macro-parentheses,
+        bugprone-macro-repeated-side-effects,
+        bugprone-forward-declaration-namespace,
+        bugprone-bool-pointer-implicit-conversion,
+        bugprone-misplaced-widening-cast,
+        cppcoreguidelines-narrowing-conversions,
+        misc-unconventional-assign-operator,
+        misc-unused-parameters'
+WarningsAsErrors: ''
+HeaderFilterRegex: ''
+CheckOptions:
+  # 现代化(Modernize)
+  - key:             modernize-redundant-void-arg
+    value:           'true'  # 检查并移除函数声明中冗余的 void 参数。
+  - key:             modernize-use-bool-literals
+    value:           'true'  # 建议使用布尔字面量 true 和 false 代替整数值 0 和 1。
+  - key:             modernize-use-equals-default
+    value:           'true'  # 建议在默认构造函数、复制构造函数和赋值运算符中使用 = default,以简化代码。
+  - key:             modernize-use-nullptr
+    value:           'true'  # 建议使用 nullptr 代替 NULL 或 0 来表示空指针。
+  - key:             modernize-use-override
+    value:           'true'  # 建议在覆盖基类虚函数时使用 override 关键字,以增加代码的清晰性和安全性。
+
+  # Google 代码风格(Google)
+  - key:             google-explicit-constructor
+    value:           'true'  # 检查并建议在单参数构造函数中使用 explicit 关键字,以防止隐式转换。
+  - key:             google-readability-casting
+    value:           'false'  # 检查并建议使用 C++ 风格的类型转换(如 static_cast、dynamic_cast、const_cast 和 reinterpret_cast)代替 C 风格的类型转换。
+
+  # 可读性(Readability)
+  - key:             readability-braces-around-statements
+    value:           'true'  # 建议在单行语句周围添加大括号,以提高代码的可读性和一致性。
+  - key:             readability-identifier-naming.ClassCase
+    value:           'CamelCase'  # 类名应使用 CamelCase 风格,例如 MyClassName。
+  - key:             readability-identifier-naming.StructCase
+    value:           'CamelCase'  # 结构体名应使用 CamelCase 风格,例如 MyStructName。
+  - key:             readability-identifier-naming.TypedefCase
+    value:           'CamelCase'  # 类型定义应使用 CamelCase 风格,例如 MyTypeDef。
+  - key:             readability-identifier-naming.EnumCase
+    value:           'CamelCase'  # 枚举名应使用 CamelCase 风格,例如 MyEnumName。
+  - key:             readability-non-const-parameter
+    value:           'true'  # 检查并标识非 const 参数,以提高代码的可读性和安全性。
+
+  # CERT 安全编码标准(CERT)
+  - key:             cert-dcl21-cpp
+    value:           'true'  # 检查并标识在头文件中不应包含无命名空间的 using 声明和指令,以防止命名空间污染。
+
+  # Bug 检测(Bugprone)
+  - key:             bugprone-undelegated-constructor
+    value:           'true'  # 检查并标识未委托的构造函数,以确保构造函数的正确性。
+  - key:             bugprone-macro-parentheses
+    value:           'true'  # 检查并建议在宏定义中使用括号,以防止潜在的错误。
+  - key:             bugprone-macro-repeated-side-effects
+    value:           'true'  # 检查并标识宏中重复的副作用,以防止潜在的错误。
+  - key:             bugprone-forward-declaration-namespace
+    value:           'true'  # 检查并标识命名空间前向声明的潜在问题。
+  - key:             bugprone-bool-pointer-implicit-conversion
+    value:           'true'  # 检查并标识布尔指针的隐式转换,以防止潜在的错误。
+  - key:             bugprone-misplaced-widening-cast
+    value:           'true'  # 检查并标识错误的宽化转换,以防止潜在的错误。
+
+  # C++ 核心指南(CppCoreGuidelines)
+  - key:             cppcoreguidelines-narrowing-conversions
+    value:           'true'  # 检查并标识可能导致数据丢失的窄化转换。
+
+  # 杂项(Miscellaneous)
+  - key:             misc-unconventional-assign-operator
+    value:           'true'  # 检查并标识不常见的赋值操作符重载,以确保代码的一致性和可维护性。
+  - key:             misc-unused-parameters
+    value:           'true'  # 检测未使用的参数。
+...
+
+

+ 1 - 2
.gitignore

@@ -10,7 +10,6 @@
 .idea
 .idea/
 
-.cache
-Project/GCC/build
+/build
 compile_commands.json
 **/Thumbs.db

+ 2 - 2
CMakeLists.txt

@@ -28,7 +28,7 @@ set(MCU_PARAMS
 # C 源文件
 file(GLOB_RECURSE C_SRCS
         ${CMAKE_CURRENT_SOURCE_DIR}/app/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/project/gcc/startup_stm32f40xx.s
+        ${CMAKE_CURRENT_SOURCE_DIR}/startup/startup_stm32f40xx.s
         ${CMAKE_CURRENT_SOURCE_DIR}/libraries/STM32F4xx_StdPeriph_Driver/src/*.c
         ${CMAKE_CURRENT_SOURCE_DIR}/driver/*.c
         ${CMAKE_CURRENT_SOURCE_DIR}/dev/*.c
@@ -80,7 +80,7 @@ set(LINK_LIBS)
 
 # 链接脚本
 set(LINK_SRC
-        ${CMAKE_CURRENT_SOURCE_DIR}/project/gcc/STM32F417IG_FLASH.ld
+        ${CMAKE_CURRENT_SOURCE_DIR}/ldscripts/STM32F417IG_FLASH.ld
         )
 
 # 编译器参数

+ 2 - 2
CMakePresets.json

@@ -5,8 +5,8 @@
             "name": "default",
             "hidden": true,
             "generator": "Ninja",
-            "binaryDir": "${sourceDir}/project/gcc/build/${presetName}",
-            "toolchainFile": "${sourceDir}/project/gcc/cmake/gcc-arm-none-eabi.cmake",
+            "binaryDir": "${sourceDir}/build/${presetName}",
+            "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",
             "cacheVariables": {
                 "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
             }

+ 0 - 0
project/gcc/STM32F40x.svd → STM32F40x.svd


+ 26 - 26
app/main.c

@@ -9,7 +9,7 @@
 
 uint16_t cache_buf[1024] = {0};
 
-int main(void)
+int main (void)
 {
     drv_board_init();
     dev_can_network_init();
@@ -17,37 +17,37 @@ int main(void)
     u16      cnt    = 0;
 
     iap_param_init();
-    fmc_read_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, 4);
+    fmc_read_n_half_word (UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, 4);
 
     if (upgrade.param.sign == UPGRADE_SIGN)
     {
-        if (check_addr_sp(DOWNLOAD_START_ADDR))
+        if (check_addr_sp (DOWNLOAD_START_ADDR))
         {
             fmc_clear_flag_star();
-            erase_app_flash(APP_START_ADDR, APP_END_ADDR);
+            erase_app_flash (APP_START_ADDR, APP_END_ADDR);
             while (w_size < upgrade.param.moving_size)
             {
                 if ((upgrade.param.moving_size - w_size) > FMC_PAGE_SIZE)
                 {
-                    fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
-                    fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
+                    fmc_read_n_half_word (DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
+                    fmc_write_n_half_word (APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
                     w_size += FMC_PAGE_SIZE;
                 }
                 else
                 {
                     if (((upgrade.param.moving_size - w_size) % 2) != 0)
                         w_size--;
-                    fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
-                    fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
+                    fmc_read_n_half_word (DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
+                    fmc_write_n_half_word (APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
                     w_size = upgrade.param.moving_size;
                 }
             }
             fmc_clear_flag_end();
 
-            if (check_addr_sp(APP_START_ADDR) && check_addr_pc(APP_START_ADDR + 4))
+            if (check_addr_sp (APP_START_ADDR) && check_addr_pc (APP_START_ADDR + 4))
             {
-                CAN_DeInit(CAN1);
-                __set_PRIMASK(1);
+                CAN_DeInit (CAN1);
+                __set_PRIMASK (1);
                 run_app();
             }
             else
@@ -58,53 +58,53 @@ int main(void)
         else
         {
             iap_flag_release();
-            CAN_DeInit(CAN1);
-            __set_PRIMASK(1);
+            CAN_DeInit (CAN1);
+            __set_PRIMASK (1);
             run_app();
         }
     }
 
-    if (INVALID == check_addr_sp(APP_START_ADDR))
+    if (INVALID == check_addr_sp (APP_START_ADDR))
     {
-        if (check_addr_sp(DOWNLOAD_START_ADDR))
+        if (check_addr_sp (DOWNLOAD_START_ADDR))
         {
             fmc_clear_flag_star();
-            erase_app_flash(APP_START_ADDR, APP_END_ADDR);
+            erase_app_flash (APP_START_ADDR, APP_END_ADDR);
             while (w_size < upgrade.param.moving_size)
             {
                 if ((upgrade.param.moving_size - w_size) > FMC_PAGE_SIZE)
                 {
-                    fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
-                    fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
+                    fmc_read_n_half_word (DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
+                    fmc_write_n_half_word (APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
                     w_size += FMC_PAGE_SIZE;
                 }
                 else
                 {
                     if (((upgrade.param.moving_size - w_size) % 2) != 0)
                         w_size--;
-                    fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
-                    fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
+                    fmc_read_n_half_word (DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
+                    fmc_write_n_half_word (APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
                     w_size = upgrade.param.moving_size;
                 }
             }
             fmc_clear_flag_end();
 
-            if (check_addr_sp(APP_START_ADDR) && check_addr_pc(APP_START_ADDR))
+            if (check_addr_sp (APP_START_ADDR) && check_addr_pc (APP_START_ADDR))
             {
-                CAN_DeInit(CAN1);
-                __set_PRIMASK(1);
+                CAN_DeInit (CAN1);
+                __set_PRIMASK (1);
                 run_app();
             }
         }
     }
     else
     {
-        CAN_DeInit(CAN1);
-        __set_PRIMASK(1);
+        CAN_DeInit (CAN1);
+        __set_PRIMASK (1);
         run_app();
     }
 
-    schedule_init(TASK_PERIOD);
+    schedule_init (TASK_PERIOD);
 
     while (1)
     {

+ 3 - 3
app/stm32f4xx_conf.h

@@ -124,11 +124,11 @@
  *   If expr is true, it returns no value.
  * @retval None
  */
-#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+#define assert_param(expr) ((expr) ? (void) 0 : assert_failed ((uint8_t *) __FILE__, __LINE__))
 /* Exported functions ------------------------------------------------------- */
-void assert_failed(uint8_t *file, uint32_t line);
+void assert_failed (uint8_t *file, uint32_t line);
 #else
-#define assert_param(expr) ((void)0)
+#define assert_param(expr) ((void) 0)
 #endif /* USE_FULL_ASSERT */
 
 #endif /* __STM32F4xx_CONF_H */

+ 9 - 9
app/stm32f4xx_it.c

@@ -52,7 +52,7 @@
  * @param  None
  * @retval None
  */
-void NMI_Handler(void)
+void NMI_Handler (void)
 {
 }
 
@@ -61,7 +61,7 @@ void NMI_Handler(void)
  * @param  None
  * @retval None
  */
-void HardFault_Handler(void)
+void HardFault_Handler (void)
 {
     /* Go to infinite loop when Hard Fault exception occurs */
     while (1)
@@ -74,7 +74,7 @@ void HardFault_Handler(void)
  * @param  None
  * @retval None
  */
-void MemManage_Handler(void)
+void MemManage_Handler (void)
 {
     /* Go to infinite loop when Memory Manage exception occurs */
     while (1)
@@ -87,7 +87,7 @@ void MemManage_Handler(void)
  * @param  None
  * @retval None
  */
-void BusFault_Handler(void)
+void BusFault_Handler (void)
 {
     /* Go to infinite loop when Bus Fault exception occurs */
     while (1)
@@ -100,7 +100,7 @@ void BusFault_Handler(void)
  * @param  None
  * @retval None
  */
-void UsageFault_Handler(void)
+void UsageFault_Handler (void)
 {
     /* Go to infinite loop when Usage Fault exception occurs */
     while (1)
@@ -113,7 +113,7 @@ void UsageFault_Handler(void)
  * @param  None
  * @retval None
  */
-void SVC_Handler(void)
+void SVC_Handler (void)
 {
 }
 
@@ -122,7 +122,7 @@ void SVC_Handler(void)
  * @param  None
  * @retval None
  */
-void DebugMon_Handler(void)
+void DebugMon_Handler (void)
 {
 }
 
@@ -131,7 +131,7 @@ void DebugMon_Handler(void)
  * @param  None
  * @retval None
  */
-void PendSV_Handler(void)
+void PendSV_Handler (void)
 {
 }
 
@@ -140,7 +140,7 @@ void PendSV_Handler(void)
  * @param  None
  * @retval None
  */
-void SysTick_Handler(void)
+void SysTick_Handler (void)
 {
     schedule_clock();
     jump_boot_time_ctrl();

+ 15 - 16
app/stm32f4xx_it.h

@@ -30,27 +30,26 @@
 #define __STM32F4xx_IT_H
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 /* Includes ------------------------------------------------------------------*/
 #include "stm32f4xx.h"
 
-    /* Exported types ------------------------------------------------------------*/
-    /* Exported constants --------------------------------------------------------*/
-    /* Exported macro ------------------------------------------------------------*/
-    /* Exported functions ------------------------------------------------------- */
-
-    void NMI_Handler(void);
-    void HardFault_Handler(void);
-    void MemManage_Handler(void);
-    void BusFault_Handler(void);
-    void UsageFault_Handler(void);
-    void SVC_Handler(void);
-    void DebugMon_Handler(void);
-    void PendSV_Handler(void);
-    void SysTick_Handler(void);
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+void NMI_Handler (void);
+void HardFault_Handler (void);
+void MemManage_Handler (void);
+void BusFault_Handler (void);
+void UsageFault_Handler (void);
+void SVC_Handler (void);
+void DebugMon_Handler (void);
+void PendSV_Handler (void);
+void SysTick_Handler (void);
 
 #ifdef __cplusplus
 }

+ 82 - 82
app/system_stm32f4xx.c

@@ -451,10 +451,10 @@ __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}
  * @{
  */
 
-static void SetSysClock(void);
+static void SetSysClock (void);
 
 #if defined(DATA_IN_ExtSRAM) || defined(DATA_IN_ExtSDRAM)
-static void SystemInit_ExtMemCtl(void);
+static void SystemInit_ExtMemCtl (void);
 #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
 
 /**
@@ -472,7 +472,7 @@ static void SystemInit_ExtMemCtl(void);
  * @param  None
  * @retval None
  */
-void SystemInit(void)
+void SystemInit (void)
 {
 /* FPU settings ------------------------------------------------------------*/
 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
@@ -480,19 +480,19 @@ void SystemInit(void)
 #endif
     /* Reset the RCC clock configuration to the default reset state ------------*/
     /* Set HSION bit */
-    RCC->CR |= (uint32_t)0x00000001;
+    RCC->CR |= (uint32_t) 0x00000001;
 
     /* Reset CFGR register */
     RCC->CFGR = 0x00000000;
 
     /* Reset HSEON, CSSON and PLLON bits */
-    RCC->CR &= (uint32_t)0xFEF6FFFF;
+    RCC->CR &= (uint32_t) 0xFEF6FFFF;
 
     /* Reset PLLCFGR register */
     RCC->PLLCFGR = 0x24003010;
 
     /* Reset HSEBYP bit */
-    RCC->CR &= (uint32_t)0xFFFBFFFF;
+    RCC->CR &= (uint32_t) 0xFFFBFFFF;
 
     /* Disable all interrupts */
     RCC->CIR = 0x00000000;
@@ -549,7 +549,7 @@ void SystemInit(void)
  * @param  None
  * @retval None
  */
-void SystemCoreClockUpdate(void)
+void SystemCoreClockUpdate (void)
 {
     uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
 #if defined(STM32F446xx)
@@ -560,73 +560,73 @@ void SystemCoreClockUpdate(void)
 
     switch (tmp)
     {
-    case 0x00: /* HSI used as system clock source */
-        SystemCoreClock = HSI_VALUE;
-        break;
-    case 0x04: /* HSE used as system clock source */
-        SystemCoreClock = HSE_VALUE;
-        break;
-    case 0x08: /* PLL P used as system clock source */
-               /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
-                 SYSCLK = PLL_VCO / PLL_P
-                 */
-        pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
-        pllm      = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
+        case 0x00: /* HSI used as system clock source */
+            SystemCoreClock = HSI_VALUE;
+            break;
+        case 0x04: /* HSE used as system clock source */
+            SystemCoreClock = HSE_VALUE;
+            break;
+        case 0x08: /* PLL P used as system clock source */
+                   /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
+                     SYSCLK = PLL_VCO / PLL_P
+                     */
+            pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
+            pllm      = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
 
 #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F446xx)
-        if (pllsource != 0)
-        {
-            /* HSE used as PLL clock source */
-            pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
-        }
-        else
-        {
-            /* HSI used as PLL clock source */
-            pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
-        }
+            if (pllsource != 0)
+            {
+                /* HSE used as PLL clock source */
+                pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+            }
+            else
+            {
+                /* HSI used as PLL clock source */
+                pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+            }
 #elif defined(STM32F411xE)
 #if defined(USE_HSE_BYPASS)
-        if (pllsource != 0)
-        {
-            /* HSE used as PLL clock source */
-            pllvco = (HSE_BYPASS_INPUT_FREQUENCY / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
-        }
+            if (pllsource != 0)
+            {
+                /* HSE used as PLL clock source */
+                pllvco = (HSE_BYPASS_INPUT_FREQUENCY / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+            }
 #else
-        if (pllsource == 0)
-        {
-            /* HSI used as PLL clock source */
-            pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
-        }
+            if (pllsource == 0)
+            {
+                /* HSI used as PLL clock source */
+                pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+            }
 #endif /* USE_HSE_BYPASS */
 #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F446xx */
-        pllp            = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> 16) + 1) * 2;
-        SystemCoreClock = pllvco / pllp;
-        break;
+            pllp            = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> 16) + 1) * 2;
+            SystemCoreClock = pllvco / pllp;
+            break;
 #if defined(STM32F446xx)
-    case 0x0C: /* PLL R used as system clock source */
-               /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
-                 SYSCLK = PLL_VCO / PLL_R
-                 */
-        pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
-        pllm      = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
-        if (pllsource != 0)
-        {
-            /* HSE used as PLL clock source */
-            pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
-        }
-        else
-        {
-            /* HSI used as PLL clock source */
-            pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
-        }
-
-        pllr            = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 28) + 1) * 2;
-        SystemCoreClock = pllvco / pllr;
-        break;
+        case 0x0C: /* PLL R used as system clock source */
+                   /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
+                     SYSCLK = PLL_VCO / PLL_R
+                     */
+            pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
+            pllm      = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
+            if (pllsource != 0)
+            {
+                /* HSE used as PLL clock source */
+                pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+            }
+            else
+            {
+                /* HSI used as PLL clock source */
+                pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+            }
+
+            pllr            = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 28) + 1) * 2;
+            SystemCoreClock = pllvco / pllr;
+            break;
 #endif /* STM32F446xx */
-    default:
-        SystemCoreClock = HSI_VALUE;
-        break;
+        default:
+            SystemCoreClock = HSI_VALUE;
+            break;
     }
     /* Compute HCLK frequency --------------------------------------------------*/
     /* Get HCLK prescaler */
@@ -643,7 +643,7 @@ void SystemCoreClockUpdate(void)
  * @param  None
  * @retval None
  */
-static void SetSysClock(void)
+static void SetSysClock (void)
 {
 #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F446xx)
     /******************************************************************************/
@@ -652,7 +652,7 @@ static void SetSysClock(void)
     __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
 
     /* Enable HSE */
-    RCC->CR |= ((uint32_t)RCC_CR_HSEON);
+    RCC->CR |= ((uint32_t) RCC_CR_HSEON);
 
     /* Wait till HSE is ready and if Time out is reached exit */
     do
@@ -663,14 +663,14 @@ static void SetSysClock(void)
 
     if ((RCC->CR & RCC_CR_HSERDY) != RESET)
     {
-        HSEStatus = (uint32_t)0x01;
+        HSEStatus = (uint32_t) 0x01;
     }
     else
     {
-        HSEStatus = (uint32_t)0x00;
+        HSEStatus = (uint32_t) 0x00;
     }
 
-    if (HSEStatus == (uint32_t)0x01)
+    if (HSEStatus == (uint32_t) 0x01)
     {
         /* Select regulator voltage output Scale 1 mode */
         RCC->APB1ENR |= RCC_APB1ENR_PWREN;
@@ -740,11 +740,11 @@ static void SetSysClock(void)
 #endif /* STM32F401xx */
 
         /* Select the main PLL as system clock source */
-        RCC->CFGR &= (uint32_t)((uint32_t) ~(RCC_CFGR_SW));
+        RCC->CFGR &= (uint32_t) ((uint32_t) ~(RCC_CFGR_SW));
         RCC->CFGR |= RCC_CFGR_SW_PLL;
 
         /* Wait till the main PLL is used as system clock source */
-        while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
+        while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
         {
         };
     }
@@ -760,7 +760,7 @@ static void SetSysClock(void)
     __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
 
     /* Enable HSE and HSE BYPASS */
-    RCC->CR |= ((uint32_t)RCC_CR_HSEON | RCC_CR_HSEBYP);
+    RCC->CR |= ((uint32_t) RCC_CR_HSEON | RCC_CR_HSEBYP);
 
     /* Wait till HSE is ready and if Time out is reached exit */
     do
@@ -771,14 +771,14 @@ static void SetSysClock(void)
 
     if ((RCC->CR & RCC_CR_HSERDY) != RESET)
     {
-        HSEStatus = (uint32_t)0x01;
+        HSEStatus = (uint32_t) 0x01;
     }
     else
     {
-        HSEStatus = (uint32_t)0x00;
+        HSEStatus = (uint32_t) 0x00;
     }
 
-    if (HSEStatus == (uint32_t)0x01)
+    if (HSEStatus == (uint32_t) 0x01)
     {
         /* Select regulator voltage output Scale 1 mode */
         RCC->APB1ENR |= RCC_APB1ENR_PWREN;
@@ -809,11 +809,11 @@ static void SetSysClock(void)
         FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_2WS;
 
         /* Select the main PLL as system clock source */
-        RCC->CFGR &= (uint32_t)((uint32_t) ~(RCC_CFGR_SW));
+        RCC->CFGR &= (uint32_t) ((uint32_t) ~(RCC_CFGR_SW));
         RCC->CFGR |= RCC_CFGR_SW_PLL;
 
         /* Wait till the main PLL is used as system clock source */
-        while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
+        while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
             ;
         {
         }
@@ -851,11 +851,11 @@ static void SetSysClock(void)
     FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_2WS;
 
     /* Select the main PLL as system clock source */
-    RCC->CFGR &= (uint32_t)((uint32_t) ~(RCC_CFGR_SW));
+    RCC->CFGR &= (uint32_t) ((uint32_t) ~(RCC_CFGR_SW));
     RCC->CFGR |= RCC_CFGR_SW_PLL;
 
     /* Wait till the main PLL is used as system clock source */
-    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
+    while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
         ;
     {
     }
@@ -878,7 +878,7 @@ static void SetSysClock(void)
  * @param  None
  * @retval None
  */
-void SystemInit_ExtMemCtl(void)
+void SystemInit_ExtMemCtl (void)
 {
     /*-- GPIOs Configuration -----------------------------------------------------*/
     /*
@@ -1034,7 +1034,7 @@ void SystemInit_ExtMemCtl(void)
  * @param  None
  * @retval None
  */
-void SystemInit_ExtMemCtl(void)
+void SystemInit_ExtMemCtl (void)
 {
     register uint32_t tmpreg = 0, timeout = 0xFFFF;
     register uint32_t index;

+ 8 - 8
app/task/app_task.c

@@ -17,20 +17,20 @@ const uint32_t task_ass[8][2] = {
 
 volatile uint32_t sys_run_time_u32 = 0;
 
-void task0(void)
+void task0 (void)
 {
     can_process();
 };
 
-void task1(void) {};
-void task2(void) {};
-void task3(void) {};
-void task4(void) {};
+void task1 (void) {};
+void task2 (void) {};
+void task3 (void) {};
+void task4 (void) {};
 
-void task5(void)
+void task5 (void)
 {
     sys_run_time_u32++;
 };
 
-void task6(void) {};
-void task7(void) {};
+void task6 (void) {};
+void task7 (void) {};

+ 8 - 8
app/task/app_task.h

@@ -4,13 +4,13 @@
 #include <stdint.h>
 extern const uint32_t task_ass[8][2];
 
-void task0(void);
-void task1(void);
-void task2(void);
-void task3(void);
-void task4(void);
-void task5(void);
-void task6(void);
-void task7(void);
+void task0 (void);
+void task1 (void);
+void task2 (void);
+void task3 (void);
+void task4 (void);
+void task5 (void);
+void task6 (void);
+void task7 (void);
 
 #endif

+ 12 - 12
app/task/schedule.c

@@ -1,15 +1,15 @@
 #include "schedule.h"
 #include "app_task.h"
 
-#define task0_mask 0x0000
-#define task1_mask 0x0001
-#define task2_mask 0x0003
-#define task3_mask 0x0007
-#define task4_mask 0x000F
-#define task5_mask 0x001F
-#define task6_mask 0x003F
-#define task7_mask 0x007F
-#define task8_mask 0x00FF
+#define task0_mask   0x0000
+#define task1_mask   0x0001
+#define task2_mask   0x0003
+#define task3_mask   0x0007
+#define task4_mask   0x000F
+#define task5_mask   0x001F
+#define task6_mask   0x003F
+#define task7_mask   0x007F
+#define task8_mask   0x00FF
 
 #define TASK_MAX_QTY 8
 
@@ -41,7 +41,7 @@ typedef union
 tag_task_list task_list[TASK_MAX_QTY];
 tag_tscw      tscw;
 
-void schedule(void)
+void schedule (void)
 {
     if (tscw.bits.task0_flag)
     {
@@ -85,7 +85,7 @@ void schedule(void)
     }
 }
 
-void schedule_init(uint32_t task_period)
+void schedule_init (uint32_t task_period)
 {
     uint32_t i;
     for (i = 0; i < TASK_MAX_QTY; i++)
@@ -95,7 +95,7 @@ void schedule_init(uint32_t task_period)
     }
 }
 
-void schedule_clock(void)
+void schedule_clock (void)
 {
     static volatile uint32_t sys_tick_count = 0;
     uint8_t                  i              = 0;

+ 3 - 3
app/task/schedule.h

@@ -5,10 +5,10 @@
 
 #define TASK_PERIOD (1)
 
-void schedule(void);
+void schedule (void);
 
-void schedule_init(uint32_t task_period);
+void schedule_init (uint32_t task_period);
 
-void schedule_clock(void);
+void schedule_clock (void);
 
 #endif

+ 1 - 1
project/gcc/cmake/gcc-arm-none-eabi.cmake → cmake/gcc-arm-none-eabi.cmake

@@ -21,6 +21,6 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 
 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
   execute_process(
-    COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json
+    COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/build/compile_commands.json
   )
 endif()

+ 9 - 9
dev/boot/dev_boot.c

@@ -2,27 +2,27 @@
 #include "dev_iap.h"
 #include <stdint.h>
 
-void run_app(void)
+void run_app (void)
 {
     pFunction     Jump_To_Application;
     __IO uint32_t JumpAddress;
 
     // CAN_DeInit(CAN1);
 
-    if (((*(__IO uint32_t *)APP_START_ADDR) & 0x2FFE0000) == 0x20000000)
+    if (((*(__IO uint32_t *) APP_START_ADDR) & 0x2FFE0000) == 0x20000000)
     {
-        JumpAddress         = *(__IO uint32_t *)(APP_START_ADDR + 4);
-        Jump_To_Application = (pFunction)JumpAddress;
-        __set_MSP(*(__IO uint32_t *)APP_START_ADDR);
+        JumpAddress         = *(__IO uint32_t *) (APP_START_ADDR + 4);
+        Jump_To_Application = (pFunction) JumpAddress;
+        __set_MSP (*(__IO uint32_t *) APP_START_ADDR);
         Jump_To_Application();
     }
 }
 
-uint8_t check_addr_sp(uint32_t addr)
+uint8_t check_addr_sp (uint32_t addr)
 {
     int ret;
 
-    if (((*(uint32_t *)addr) & 0x2FFE0000) == 0x20000000) // 检查栈顶地址是否合法
+    if (((*(uint32_t *) addr) & 0x2FFE0000) == 0x20000000) // 检查栈顶地址是否合法
     {
         ret = VALID;
     }
@@ -33,11 +33,11 @@ uint8_t check_addr_sp(uint32_t addr)
     return ret;
 }
 
-uint8_t check_addr_pc(uint32_t addr)
+uint8_t check_addr_pc (uint32_t addr)
 {
     int ret;
 
-    if (((*(uint32_t *)(addr + 4)) & 0xFF000000) == 0x08000000) // 检查中断向量表地址是否合法
+    if (((*(uint32_t *) (addr + 4)) & 0xFF000000) == 0x08000000) // 检查中断向量表地址是否合法
     {
         ret = VALID;
     }

+ 4 - 4
dev/boot/dev_boot.h

@@ -9,10 +9,10 @@ typedef enum
     VALID   = !INVALID
 } validity_status;
 
-typedef void (*pFunction)(void);
+typedef void (*pFunction) (void);
 
-void    run_app(void);
-uint8_t check_addr_sp(uint32_t addr);
-uint8_t check_addr_pc(uint32_t addr);
+void    run_app (void);
+uint8_t check_addr_sp (uint32_t addr);
+uint8_t check_addr_pc (uint32_t addr);
 
 #endif

+ 51 - 50
dev/can/dev_can.c

@@ -5,10 +5,10 @@
 #include <stdlib.h>
 #include <string.h>
 
-queue_entry(pdu_tag, 30) can_tx_queue;
-queue_entry(pdu_tag, 30) can_rx_queue;
+queue_entry (pdu_tag, 30) can_tx_queue;
+queue_entry (pdu_tag, 30) can_rx_queue;
 
-double pow_branch(double x, long long N)
+double pow_branch (double x, long long N)
 {
     double ans = 1.0;
     // 贡献的初始值为 x
@@ -28,43 +28,44 @@ double pow_branch(double x, long long N)
     }
     return ans;
 }
-double pow(double x, double N)
+
+double pow (double x, double N)
 {
-    return N >= 0 ? pow_branch(x, N) : 1.0 / pow_branch(x, -N);
+    return N >= 0 ? pow_branch (x, N) : 1.0 / pow_branch (x, -N);
 }
 
 uint8_t recv_can_id = 0;
 
 static uint64_t base_data;
 
-void data_bit_move(uint8_t start_bit, uint8_t bit_len, uint64_t data)
+void data_bit_move (uint8_t start_bit, uint8_t bit_len, uint64_t data)
 {
     uint64_t mask        = 0;
-    uint64_t source_data = (uint64_t)data;
-    mask                 = pow(2, bit_len) - 1;
+    uint64_t source_data = (uint64_t) data;
+    mask                 = pow (2, bit_len) - 1;
     base_data |= (mask & source_data) << start_bit;
 }
 
-void product_array(uint8_t send_array[8])
+void product_array (uint8_t send_array[8])
 {
-    send_array[0] = (uint8_t)base_data;
-    send_array[1] = (uint8_t)(base_data >> 8);
-    send_array[2] = (uint8_t)(base_data >> 16);
-    send_array[3] = (uint8_t)(base_data >> 24);
-    send_array[4] = (uint8_t)(base_data >> 32);
-    send_array[5] = (uint8_t)(base_data >> 40);
-    send_array[6] = (uint8_t)(base_data >> 48);
-    send_array[7] = (uint8_t)(base_data >> 56);
+    send_array[0] = (uint8_t) base_data;
+    send_array[1] = (uint8_t) (base_data >> 8);
+    send_array[2] = (uint8_t) (base_data >> 16);
+    send_array[3] = (uint8_t) (base_data >> 24);
+    send_array[4] = (uint8_t) (base_data >> 32);
+    send_array[5] = (uint8_t) (base_data >> 40);
+    send_array[6] = (uint8_t) (base_data >> 48);
+    send_array[7] = (uint8_t) (base_data >> 56);
     base_data     = 0;
 }
 
-uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
+uint8_t push_can_message_to_queue (uint32_t id, uint8_t len, uint8_t *p_data)
 {
     pdu_tag      response_msg;
     QUEUE_STATUS result_status;
     response_msg.id.r    = id;
     response_msg.reg.dlc = len;
-    memcpy(&response_msg.data.u8_buf[0], p_data, len);
+    memcpy (&response_msg.data.u8_buf[0], p_data, len);
 
     if (id > 0x7FF)
     {
@@ -76,7 +77,7 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
     }
 
     __disable_irq();
-    en_queue(&can_tx_queue, response_msg, result_status);
+    en_queue (&can_tx_queue, response_msg, result_status);
     __enable_irq();
     if (result_status != Q_OK)
     {
@@ -86,45 +87,45 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
     return 1;
 }
 
-static uint8_t can_tx_frame(pdu_tag can_message)
+static uint8_t can_tx_frame (pdu_tag can_message)
 {
     uint8_t result = CAN_TxStatus_NoMailBox;
-    result         = drv_can_msg_tx(can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
+    result         = drv_can_msg_tx (can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
     return result;
 }
 
-void can_tx_callback(void)
+void can_tx_callback (void)
 {
     pdu_tag      tx_data;
     QUEUE_STATUS result_status;
 
-    de_queue(&can_tx_queue, tx_data, result_status);
+    de_queue (&can_tx_queue, tx_data, result_status);
 
     if (result_status == Q_OK) // 返回值为1代表读取成功
     {
-        can_tx_frame(tx_data);
-        CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
+        can_tx_frame (tx_data);
+        CAN_ITConfig (CAN1, CAN_IT_TME, ENABLE);
     }
     else
     {
-        CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE);
+        CAN_ITConfig (CAN1, CAN_IT_TME, DISABLE);
     }
 }
 
-void can_rx_callback(CanRxMsg rx_message)
+void can_rx_callback (CanRxMsg rx_message)
 {
     pdu_tag      data;
     QUEUE_STATUS result;
     switch (rx_message.ExtId)
     {
-    case 0x18DFF4E1:
-        data.id.r    = 0x18DFF4E1;
-        data.reg.dlc = rx_message.DLC;
-        memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
-        en_queue(&can_rx_queue, data, result);
-        break;
-    default:
-        return;
+        case 0x18DFF4E1:
+            data.id.r    = 0x18DFF4E1;
+            data.reg.dlc = rx_message.DLC;
+            memcpy (&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
+            en_queue (&can_rx_queue, data, result);
+            break;
+        default:
+            return;
     }
 }
 
@@ -134,23 +135,23 @@ can_rx_tab can_tab[] = {
 
 };
 
-void can_start_send(void)
+void can_start_send (void)
 {
     pdu_tag      tx_msg;
     QUEUE_STATUS result_status;
 
     if (0 == ((CAN1->IER) & 0x1))
     {
-        de_queue(&can_tx_queue, tx_msg, result_status);
+        de_queue (&can_tx_queue, tx_msg, result_status);
         if (result_status == Q_OK) // 返回值为1代表读取成功
         {
-            can_tx_frame(tx_msg);
-            CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
+            can_tx_frame (tx_msg);
+            CAN_ITConfig (CAN1, CAN_IT_TME, ENABLE);
         }
     }
 }
 
-static uint8_t can_rx_process(void)
+static uint8_t can_rx_process (void)
 {
     uint8_t      i;
     uint8_t      flg = 0;
@@ -160,16 +161,16 @@ static uint8_t can_rx_process(void)
     for (uint8_t j = 0; j < 15; j++)
     {
         __disable_irq();
-        de_queue(&can_rx_queue, rec_msg, result);
+        de_queue (&can_rx_queue, rec_msg, result);
         __enable_irq();
 
         if (Q_OK == result)
         {
-            for (i = 0; i < ARR_SIZE(can_tab); i++)
+            for (i = 0; i < ARR_SIZE (can_tab); i++)
             {
                 if (can_tab[i].id == rec_msg.id.r)
                 {
-                    can_tab[i].p_func(rec_msg);
+                    can_tab[i].p_func (rec_msg);
                     break;
                 }
             }
@@ -177,16 +178,16 @@ static uint8_t can_rx_process(void)
     }
 }
 
-void dev_can_network_init(void)
+void dev_can_network_init (void)
 {
     drv_can_init();
-    queue_init(&can_rx_queue);
-    queue_init(&can_tx_queue);
-    drv_can_rx_back_init(can_rx_callback);
-    drv_can_tx_back_init(can_tx_callback);
+    queue_init (&can_rx_queue);
+    queue_init (&can_tx_queue);
+    drv_can_rx_back_init (can_rx_callback);
+    drv_can_tx_back_init (can_tx_callback);
 }
 
-void can_process(void)
+void can_process (void)
 {
     can_rx_process();
     can_start_send();

+ 5 - 5
dev/can/dev_can.h

@@ -11,19 +11,19 @@ extern uint8_t recv_can_id;
 typedef struct
 {
     uint32_t id;
-    void (*p_func)(pdu_tag);
+    void (*p_func) (pdu_tag);
 } can_rx_tab;
 
 // #define ARR_SIZE(a) sizeof(a) / a[0]
 
-#define ARR_SIZE(a) sizeof(a) / sizeof((a)[0])
+#define ARR_SIZE(a) sizeof (a) / sizeof ((a)[0])
 
 // #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
-void    can_rx_callback(CanRxMsg rx_message);
+void    can_rx_callback (CanRxMsg rx_message);
 void    can_tx_callback();
-void    can_process(void);
+void    can_process (void);
 void    dev_can_network_init();
-uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data);
+uint8_t push_can_message_to_queue (uint32_t id, uint8_t len, uint8_t *p_data);
 
 #endif // __APP_CAN_H

+ 95 - 94
dev/iap/dev_iap.c

@@ -26,6 +26,7 @@ uint8_t  iap_disconnect_count                  = 0;
  ************************************************************************************************/
 iap_type      g_iap;
 upgrade_param upgrade;
+
 /************************************************************************************************
  *                                          implements                                           *
  ************************************************************************************************/
@@ -33,7 +34,7 @@ void invert_uint8()
 {
 }
 
-void iap_connect_clear(void)
+void iap_connect_clear (void)
 {
     iap_disconnect_count = 0;
     send_buff[0]         = 0x00;
@@ -46,7 +47,7 @@ void iap_connect_clear(void)
     send_buff[7]         = 0x00;
 }
 
-void iap_disconnect_check(void)
+void iap_disconnect_check (void)
 {
     if (++iap_disconnect_count >= 5)
     {
@@ -55,7 +56,7 @@ void iap_disconnect_check(void)
 }
 
 // iap相关参数初始化
-void iap_param_init(void)
+void iap_param_init (void)
 {
     g_iap.recv_len         = 0;
     g_iap.total_packages   = 0;
@@ -69,36 +70,36 @@ void iap_param_init(void)
 }
 
 // 清除升级信息标志位
-void set_firmver(void)
+void set_firmver (void)
 {
     fmc_clear_flag_star();
-    fmc_read_n_half_word(UPGRADE_FLAG_START_ADDR, firm_ver_buff, UPGRADE_BUFF_DATA_SIZE);
-    fmc_erase_pages(UPGRADE_FLAG_START_ADDR, 1);
+    fmc_read_n_half_word (UPGRADE_FLAG_START_ADDR, firm_ver_buff, UPGRADE_BUFF_DATA_SIZE);
+    fmc_erase_pages (UPGRADE_FLAG_START_ADDR, 1);
 
-    fmc_write_n_half_word(UPGRADE_FLAG_START_ADDR, firm_ver_buff, UPGRADE_BUFF_DATA_SIZE);
+    fmc_write_n_half_word (UPGRADE_FLAG_START_ADDR, firm_ver_buff, UPGRADE_BUFF_DATA_SIZE);
     fmc_clear_flag_end();
 }
 
-void iap_flag_release(void)
+void iap_flag_release (void)
 {
-    fmc_read_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, UPGRADE_FLAG_DATA_SIZE);
+    fmc_read_n_half_word (UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, UPGRADE_FLAG_DATA_SIZE);
 
     if (upgrade.param.sign == UPGRADE_SIGN)
     {
         fmc_clear_flag_star();
-        fmc_erase_pages(UPGRADE_FLAG_START_ADDR, 1);
-        fmc_write_n_half_word(UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2), firm_ver, UPGRADE_APP_DATA_SIZE);
+        fmc_erase_pages (UPGRADE_FLAG_START_ADDR, 1);
+        fmc_write_n_half_word (UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2), firm_ver, UPGRADE_APP_DATA_SIZE);
         fmc_clear_flag_end();
         for (uint8_t i = 0; i < (UPGRADE_APP_DATA_SIZE * 2); i++)
         {
-            send_buff[i] = fmc_read_byte(UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2) + i);
+            send_buff[i] = fmc_read_byte (UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2) + i);
         }
         // hal_can_msg_tx(0x180000001, CAN_Id_Extended, send_buff, 8);
-        CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
+        CAN_ITConfig (CAN1, CAN_IT_TME, ENABLE);
     }
 }
 
-uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr)
+uint8_t erase_app_flash (uint32_t start_address, uint32_t end_addr)
 {
     uint8_t  status   = 0;
     uint16_t page_len = 0;
@@ -107,11 +108,11 @@ uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr)
 
     if ((start_address == ADDR_FLASH_SECTOR_2))
     {
-        status = fmc_erase_pages(start_address, 5);
+        status = fmc_erase_pages (start_address, 5);
     }
     else if ((start_address == ADDR_FLASH_SECTOR_8))
     {
-        status = fmc_erase_pages(start_address, 3);
+        status = fmc_erase_pages (start_address, 3);
     }
     else
     {
@@ -121,7 +122,7 @@ uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr)
     return status;
 }
 
-void jump_boot_time_ctrl(void)
+void jump_boot_time_ctrl (void)
 {
     if (jump_boot_time > 0)
     {
@@ -129,47 +130,47 @@ void jump_boot_time_ctrl(void)
         if (jump_boot_time == 0)
         {
             // jump_flag = 1;
-            __set_FAULTMASK(1); //  关闭所有中断
-            NVIC_SystemReset(); //  复位
+            __set_FAULTMASK (1); //  关闭所有中断
+            NVIC_SystemReset();  //  复位
         }
     }
 }
 
-void write_app_flash(uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
+void write_app_flash (uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
 {
     static uint32_t w_start_addr = 0;
 
     w_start_addr = pack_num * 6 + APP_START_ADDR;
-    fmc_write_n_half_word(w_start_addr, buf, pack_len);
+    fmc_write_n_half_word (w_start_addr, buf, pack_len);
 }
 
-void read_app_flash(uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
+void read_app_flash (uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
 {
     static uint32_t w_start_addr = 0;
 
     w_start_addr = pack_num * 6 + APP_START_ADDR;
-    fmc_read_n_half_word(w_start_addr, buf, pack_len);
+    fmc_read_n_half_word (w_start_addr, buf, pack_len);
 }
 
-uint8_t write_download_flash(uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
+uint8_t write_download_flash (uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
 {
     uint8_t         status       = 0;
     static uint32_t w_start_addr = 0;
 
     w_start_addr = pack_num * 6 + DOWNLOAD_START_ADDR;
-    status       = fmc_write_n_half_word(w_start_addr, buf, pack_len);
+    status       = fmc_write_n_half_word (w_start_addr, buf, pack_len);
     return status;
 }
 
-void read_download_flash(uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
+void read_download_flash (uint16_t *buf, uint16_t pack_len, uint16_t pack_num)
 {
     static uint32_t w_start_addr = 0;
 
     w_start_addr = pack_num * 6 + DOWNLOAD_START_ADDR;
-    fmc_read_n_half_word(w_start_addr, buf, pack_len);
+    fmc_read_n_half_word (w_start_addr, buf, pack_len);
 }
 
-void iap_rec_handler(pdu_tag rec_msg)
+void iap_rec_handler (pdu_tag rec_msg)
 {
     uint8_t erase_flag = 0x01;
 
@@ -182,8 +183,8 @@ void iap_rec_handler(pdu_tag rec_msg)
         if (rec_msg.id.b.sa == 0xE1)
         {
             g_iap.recv_len         = rec_msg.reg.dlc - 2;
-            g_iap.current_packages = ((uint16_t)(rec_msg.data.u8_buf[0] & 0x7F) << 8) | rec_msg.data.u8_buf[1];
-            memcpy(g_iap.flash_data.u8_buf, &rec_msg.data.u8_buf[2], g_iap.recv_len);
+            g_iap.current_packages = ((uint16_t) (rec_msg.data.u8_buf[0] & 0x7F) << 8) | rec_msg.data.u8_buf[1];
+            memcpy (g_iap.flash_data.u8_buf, &rec_msg.data.u8_buf[2], g_iap.recv_len);
 
             if ((g_iap.count_packages == g_iap.current_packages) && (g_iap.current_packages < g_iap.total_packages))
             {
@@ -196,10 +197,10 @@ void iap_rec_handler(pdu_tag rec_msg)
                 }
 
                 fmc_clear_flag_star();
-                erase_flag = write_download_flash(g_iap.flash_data.u16_buf, g_iap.recv_len / 2, g_iap.count_packages);
+                erase_flag = write_download_flash (g_iap.flash_data.u16_buf, g_iap.recv_len / 2, g_iap.count_packages);
                 fmc_clear_flag_end();
 
-                g_iap.crc16 = firmware_crc16_ccitt_false(g_iap.crc16, g_iap.flash_data.u8_buf, g_iap.recv_len);
+                g_iap.crc16 = firmware_crc16_ccitt_false (g_iap.crc16, g_iap.flash_data.u8_buf, g_iap.recv_len);
 
                 send_buff[0] = IAP_CMD_DATA;
                 send_buff[1] = !erase_flag;
@@ -222,72 +223,72 @@ void iap_rec_handler(pdu_tag rec_msg)
     {
         switch (rec_msg.data.u8_buf[0])
         {
-        case IAP_CMD_VERSION:
-            iap_param_init();
-            for (uint8_t i = 0; i < (UPGRADE_APP_DATA_SIZE * 2); i++)
-            {
-                send_buff[i] = fmc_read_byte(UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2) + i);
-            }
+            case IAP_CMD_VERSION:
+                iap_param_init();
+                for (uint8_t i = 0; i < (UPGRADE_APP_DATA_SIZE * 2); i++)
+                {
+                    send_buff[i] = fmc_read_byte (UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2) + i);
+                }
 
-            send_buff[0] = IAP_CMD_VERSION;
-            send_buff[1] = 0x01;
-            break;
-        case IAP_CMD_INFO:
-            g_iap.total_bytes = (uint16_t)rec_msg.data.u8_buf[1] << 8 | rec_msg.data.u8_buf[2];
-            g_iap.total_bytes <<= 16;
-            g_iap.total_bytes |= (uint16_t)rec_msg.data.u8_buf[3] << 8 | rec_msg.data.u8_buf[4];
-            g_iap.total_packages = (uint16_t)rec_msg.data.u8_buf[5] << 8 | rec_msg.data.u8_buf[6];
-            send_buff[0]         = IAP_CMD_INFO;
-            send_buff[1]         = 0x01;
-            break;
-        case IAP_CMD_ERASE:
-            g_iap.firmware_crc16 = (uint16_t)rec_msg.data.u8_buf[2] << 8 | rec_msg.data.u8_buf[3];
-            if (rec_msg.data.u8_buf[1])
-            {
-                // 喂狗
-                fmc_clear_flag_star();
-                erase_flag = erase_app_flash(DOWNLOAD_START_ADDR, DOWNLOAD_END_ADDR);
-                fmc_clear_flag_end();
-                // 喂狗
-                g_iap.count_bytes    = 0;
-                g_iap.count_packages = 0;
-            }
-            send_buff[0] = IAP_CMD_ERASE;
-            send_buff[1] = !erase_flag;
-            break;
-        case IAP_CMD_CRC:
-            send_buff[0] = IAP_CMD_CRC;
-            send_buff[1] = (g_iap.crc16 == g_iap.firmware_crc16 ? 1 : 0);
-            break;
-        case IAP_CMD_JUMP:
-            if (g_iap.crc16 != g_iap.firmware_crc16)
-            {
-                send_buff[1] = 0x00;
-            }
-            else
-            {
-                fmc_clear_flag_star();
-                fmc_erase_pages(UPGRADE_FLAG_START_ADDR, 1);
-                upgrade.param.sign        = UPGRADE_SIGN;
-                upgrade.param.crc16       = g_iap.crc16;
-                upgrade.param.moving_size = g_iap.total_bytes;
-                fmc_write_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, UPGRADE_FLAG_DATA_SIZE);
-                fmc_clear_flag_end();
-                jump_boot_time = 10;
-                send_buff[1]   = 0x01;
-            }
-            send_buff[0] = IAP_CMD_JUMP;
-            break;
-        case IAP_CMD_MODEL_TYPE:
-            send_buff[0] = IAP_CMD_MODEL_TYPE;
-            send_buff[1] = 0x01;
-
-            send_buff[2] = DEVICE_ID >> 8;
-            send_buff[3] = DEVICE_ID & 0xFF;
+                send_buff[0] = IAP_CMD_VERSION;
+                send_buff[1] = 0x01;
+                break;
+            case IAP_CMD_INFO:
+                g_iap.total_bytes = (uint16_t) rec_msg.data.u8_buf[1] << 8 | rec_msg.data.u8_buf[2];
+                g_iap.total_bytes <<= 16;
+                g_iap.total_bytes |= (uint16_t) rec_msg.data.u8_buf[3] << 8 | rec_msg.data.u8_buf[4];
+                g_iap.total_packages = (uint16_t) rec_msg.data.u8_buf[5] << 8 | rec_msg.data.u8_buf[6];
+                send_buff[0]         = IAP_CMD_INFO;
+                send_buff[1]         = 0x01;
+                break;
+            case IAP_CMD_ERASE:
+                g_iap.firmware_crc16 = (uint16_t) rec_msg.data.u8_buf[2] << 8 | rec_msg.data.u8_buf[3];
+                if (rec_msg.data.u8_buf[1])
+                {
+                    // 喂狗
+                    fmc_clear_flag_star();
+                    erase_flag = erase_app_flash (DOWNLOAD_START_ADDR, DOWNLOAD_END_ADDR);
+                    fmc_clear_flag_end();
+                    // 喂狗
+                    g_iap.count_bytes    = 0;
+                    g_iap.count_packages = 0;
+                }
+                send_buff[0] = IAP_CMD_ERASE;
+                send_buff[1] = !erase_flag;
+                break;
+            case IAP_CMD_CRC:
+                send_buff[0] = IAP_CMD_CRC;
+                send_buff[1] = (g_iap.crc16 == g_iap.firmware_crc16 ? 1 : 0);
+                break;
+            case IAP_CMD_JUMP:
+                if (g_iap.crc16 != g_iap.firmware_crc16)
+                {
+                    send_buff[1] = 0x00;
+                }
+                else
+                {
+                    fmc_clear_flag_star();
+                    fmc_erase_pages (UPGRADE_FLAG_START_ADDR, 1);
+                    upgrade.param.sign        = UPGRADE_SIGN;
+                    upgrade.param.crc16       = g_iap.crc16;
+                    upgrade.param.moving_size = g_iap.total_bytes;
+                    fmc_write_n_half_word (UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, UPGRADE_FLAG_DATA_SIZE);
+                    fmc_clear_flag_end();
+                    jump_boot_time = 10;
+                    send_buff[1]   = 0x01;
+                }
+                send_buff[0] = IAP_CMD_JUMP;
+                break;
+            case IAP_CMD_MODEL_TYPE:
+                send_buff[0] = IAP_CMD_MODEL_TYPE;
+                send_buff[1] = 0x01;
+
+                send_buff[2] = DEVICE_ID >> 8;
+                send_buff[3] = DEVICE_ID & 0xFF;
         }
     }
 
-    push_can_message_to_queue(0x18DFE1F4, 8, send_buff);
+    push_can_message_to_queue (0x18DFE1F4, 8, send_buff);
 }
 
 // void iap_rec_handler(pdu_tag rec_msg)

+ 18 - 17
dev/iap/dev_iap.h

@@ -32,19 +32,19 @@ extern 'C'
      *                                          Defines                                              *
      ************************************************************************************************/
 
-#define UPGRADE_FLAG_DATA_SIZE 4                                                // 升级参数数组元素个数
-#define UPGRADE_APP_DATA_SIZE  4                                                // 升级参数数组元素个数
-#define UPGRADE_BUFF_DATA_SIZE (UPGRADE_FLAG_DATA_SIZE + UPGRADE_APP_DATA_SIZE) // 升级参数数组元素个数
+#define UPGRADE_FLAG_DATA_SIZE  4                                                // 升级参数数组元素个数
+#define UPGRADE_APP_DATA_SIZE   4                                                // 升级参数数组元素个数
+#define UPGRADE_BUFF_DATA_SIZE  (UPGRADE_FLAG_DATA_SIZE + UPGRADE_APP_DATA_SIZE) // 升级参数数组元素个数
 
-#define APP_START_ADDR ((uint32_t)0x08008000)
-#define APP_END_ADDR   ((uint32_t)0x0805FFFF)
+#define APP_START_ADDR          ((uint32_t) 0x08008000)
+#define APP_END_ADDR            ((uint32_t) 0x0805FFFF)
 
-#define UPGRADE_FLAG_START_ADDR ((uint32_t)0x08060000)
-#define UPGRADE_FLAG_END_ADDR   ((uint32_t)0x0807FFFF)
+#define UPGRADE_FLAG_START_ADDR ((uint32_t) 0x08060000)
+#define UPGRADE_FLAG_END_ADDR   ((uint32_t) 0x0807FFFF)
 
-#define DOWNLOAD_START_ADDR  ((uint32_t)0x08080000)
-#define DOWNLOAD_END_ADDR    ((uint32_t)0x080DFFFF)
-#define DOWNLOAD_MIDDLE_ADDR ((uint32_t)0x080A0000)
+#define DOWNLOAD_START_ADDR     ((uint32_t) 0x08080000)
+#define DOWNLOAD_END_ADDR       ((uint32_t) 0x080DFFFF)
+#define DOWNLOAD_MIDDLE_ADDR    ((uint32_t) 0x080A0000)
 
 // 升级命令
 #define IAP_CMD_VERSION    0x71   // 查询版本号
@@ -56,8 +56,8 @@ extern 'C'
 #define IAP_CMD_JUMP_OVER  0x0175 // 执行跳转
 #define IAP_CMD_MODEL_TYPE 0x76   // 执行跳转
 
-#define UPGRADE_SIGN 0x5AA5
-#define DEVICE_ID    0x5AA5
+#define UPGRADE_SIGN       0x5AA5
+#define DEVICE_ID          0x5AA5
 
     typedef union
     {
@@ -95,16 +95,17 @@ extern 'C'
             uint16_t crc16;       // 中地址 buf[1]
             uint32_t moving_size; // 高地址 buf[2] buf[3]
         } param;
+
         uint16_t infor_buf[UPGRADE_FLAG_DATA_SIZE];
     } upgrade_param; // 升级参数使用
 
     extern upgrade_param upgrade;
 
-    void    iap_param_init(void);
-    void    iap_flag_release(void);
-    uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr);
-    void    jump_boot_time_ctrl(void);
-    void    iap_rec_handler(pdu_tag rec_msg);
+    void    iap_param_init (void);
+    void    iap_flag_release (void);
+    uint8_t erase_app_flash (uint32_t start_address, uint32_t end_addr);
+    void    jump_boot_time_ctrl (void);
+    void    iap_rec_handler (pdu_tag rec_msg);
 
 /************************************************************************************************
  *                                          Defines                                              *

+ 33 - 30
dev/queue/queue.h

@@ -10,9 +10,11 @@ typedef struct
         uint8_t rtr;
         uint8_t dlc;
     } reg;
+
     union
     {
         uint32_t r;
+
         struct
         {
             uint8_t sa : 8;
@@ -23,6 +25,7 @@ typedef struct
             uint8_t p  : 3;
         } b;
     } id;
+
     union
     {
         uint8_t  u8_buf[8];
@@ -57,38 +60,38 @@ typedef enum
 
 /* List functions. */
 #define queue_empty(name) ((name)->count == 0)
-#define queue_max(name)   ((sizeof((name)->message)) / (sizeof((name)->message[0])))
-#define queue_full(name)  ((name)->count == ((sizeof((name)->message)) / (sizeof((name)->message[0]))))
-#define en_queue(name, field, ret)                                                \
-    do                                                                            \
-    {                                                                             \
-        if (queue_full(name))                                                     \
-        {                                                                         \
-            ret = Q_FULL;                                                         \
-        }                                                                         \
-        else                                                                      \
-        {                                                                         \
-            (name)->count++;                                                      \
-            (name)->message[(name)->head] = field;                                \
-            (name)->head                  = ((name)->head + 1) % queue_max(name); \
-            ret                           = Q_OK;                                 \
-        }                                                                         \
+#define queue_max(name)   ((sizeof ((name)->message)) / (sizeof ((name)->message[0])))
+#define queue_full(name)  ((name)->count == ((sizeof ((name)->message)) / (sizeof ((name)->message[0]))))
+#define en_queue(name, field, ret)                                                 \
+    do                                                                             \
+    {                                                                              \
+        if (queue_full (name))                                                     \
+        {                                                                          \
+            ret = Q_FULL;                                                          \
+        }                                                                          \
+        else                                                                       \
+        {                                                                          \
+            (name)->count++;                                                       \
+            (name)->message[(name)->head] = field;                                 \
+            (name)->head                  = ((name)->head + 1) % queue_max (name); \
+            ret                           = Q_OK;                                  \
+        }                                                                          \
     } while (0)
 
-#define de_queue(name, field, ret)                               \
-    do                                                           \
-    {                                                            \
-        if (queue_empty(name))                                   \
-        {                                                        \
-            ret = Q_EMPTY;                                       \
-        }                                                        \
-        else                                                     \
-        {                                                        \
-            field        = (name)->message[(name)->tail];        \
-            (name)->tail = ((name)->tail + 1) % queue_max(name); \
-            (name)->count--;                                     \
-            ret = Q_OK;                                          \
-        }                                                        \
+#define de_queue(name, field, ret)                                \
+    do                                                            \
+    {                                                             \
+        if (queue_empty (name))                                   \
+        {                                                         \
+            ret = Q_EMPTY;                                        \
+        }                                                         \
+        else                                                      \
+        {                                                         \
+            field        = (name)->message[(name)->tail];         \
+            (name)->tail = ((name)->tail + 1) % queue_max (name); \
+            (name)->count--;                                      \
+            ret = Q_OK;                                           \
+        }                                                         \
     } while (0)
 
 #endif

+ 1 - 1
driver/board.c

@@ -2,7 +2,7 @@
 
 void drv_board_init()
 {
-    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
+    NVIC_PriorityGroupConfig (NVIC_PriorityGroup_4);
     drv_systick_init();
     drv_gpio_init();
     // dwt_init();

+ 1 - 1
driver/board.h

@@ -6,6 +6,6 @@
 #include "drv_systick.h"
 #include "dwt.h"
 
-void drv_board_init(void);
+void drv_board_init (void);
 
 #endif

+ 24 - 24
driver/can/drv_can.c

@@ -18,27 +18,27 @@ pcan_tx  pcan_tx_back = NULL;
 // Fpclk1的时钟在初始化的时候设置为42M,如果设置CAN1_Mode_Init(CAN_SJW_1tq,CAN_BS2_6tq,CAN_BS1_7tq,6,CAN_Mode_LoopBack);
 // 则波特率为:42M/((6+7+1)*6)=500Kbps
 
-u8 drv_can1_mode_init(uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, uint8_t mode)
+u8 drv_can1_mode_init (uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, uint8_t mode)
 {
     GPIO_InitTypeDef      GPIO_InitStructure;
     CAN_InitTypeDef       CAN_InitStructure;
     CAN_FilterInitTypeDef CAN_FilterInitStructure;
     NVIC_InitTypeDef      NVIC_InitStructure;
 
-    CAN_DeInit(CAN1);
+    CAN_DeInit (CAN1);
 
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // 使能PORTA时钟
-    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);  // 使能CAN1时钟
+    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE); // 使能PORTA时钟
+    RCC_APB1PeriphClockCmd (RCC_APB1Periph_CAN1, ENABLE);  // 使能CAN1时钟
 
     GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
     GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
     GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_11 | GPIO_Pin_12;
-    GPIO_Init(GPIOA, &GPIO_InitStructure); // 初始化IO
+    GPIO_Init (GPIOA, &GPIO_InitStructure); // 初始化IO
 
-    GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
-    GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
+    GPIO_PinAFConfig (GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
+    GPIO_PinAFConfig (GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
 
     // CAN单元设置
     CAN_InitStructure.CAN_TTCM      = DISABLE; // 非时间触发通信模式
@@ -52,7 +52,7 @@ u8 drv_can1_mode_init(uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, ui
     CAN_InitStructure.CAN_BS1       = tbs1;    // Tbs1范围CAN_BS1_1tq ~CAN_BS1_16tq
     CAN_InitStructure.CAN_BS2       = tbs2;    // Tbs2范围CAN_BS2_1tq ~	CAN_BS2_8tq
     CAN_InitStructure.CAN_Prescaler = brp;     // 分频系数(Fdiv)为brp+1
-    CAN_Init(CAN1, &CAN_InitStructure);        // 初始化CAN1
+    CAN_Init (CAN1, &CAN_InitStructure);       // 初始化CAN1
 
     // 配置过滤器0
     CAN_FilterInitStructure.CAN_FilterNumber = 0; // 过滤器0
@@ -69,20 +69,20 @@ u8 drv_can1_mode_init(uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, ui
 
     CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0; // 过滤器0关联到FIFO0
     CAN_FilterInitStructure.CAN_FilterActivation     = ENABLE;           // 激活过滤器0
-    CAN_FilterInit(&CAN_FilterInitStructure);                            // 滤波器初始化
+    CAN_FilterInit (&CAN_FilterInitStructure);                           // 滤波器初始化
 
-    CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); // FIFO0消息挂号中断允许.
+    CAN_ITConfig (CAN1, CAN_IT_FMP0, ENABLE); // FIFO0消息挂号中断允许.
     NVIC_InitStructure.NVIC_IRQChannel                   = CAN1_RX0_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 主优先级为
     NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0; // 次优先级为0
     NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
-    NVIC_Init(&NVIC_InitStructure);
+    NVIC_Init (&NVIC_InitStructure);
 
     NVIC_InitStructure.NVIC_IRQChannel                   = CAN1_TX_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 主优先级为1
     NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0; // 次优先级为0
     NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
-    NVIC_Init(&NVIC_InitStructure);
+    NVIC_Init (&NVIC_InitStructure);
     ////////////////////////////////////////////////
 
     return 0;
@@ -94,18 +94,18 @@ u8 drv_can1_mode_init(uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, ui
  *	形    参: 无
  *	返 回 值: 无
  **********************************************************************************************************/
-void drv_can_init(void)
+void drv_can_init (void)
 {
 #if defined(__CAN_BAUD_500K)
-    drv_can1_mode_init(CAN_SJW_1tq, CAN_BS2_6tq, CAN_BS1_7tq, 6, CAN_Mode_Normal); // CAN1初始化环回模式,波特率500Kbps
+    drv_can1_mode_init (CAN_SJW_1tq, CAN_BS2_6tq, CAN_BS1_7tq, 6, CAN_Mode_Normal); // CAN1初始化环回模式,波特率500Kbps
 #elif defined(__CAN_BAUD_250K)
-    drv_can1_mode_init(CAN_SJW_1tq, CAN_BS2_6tq, CAN_BS1_7tq, 12, CAN_Mode_Normal); // CAN1初始化环回模式,波特率250Kbps
+    drv_can1_mode_init (CAN_SJW_1tq, CAN_BS2_6tq, CAN_BS1_7tq, 12, CAN_Mode_Normal); // CAN1初始化环回模式,波特率250Kbps
 #else
 #error no can baud macro!;
 #endif
 }
 
-uint8_t drv_can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len)
+uint8_t drv_can_msg_tx (uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len)
 {
     uint8_t flg = 0;
     if (id_type)
@@ -121,23 +121,23 @@ uint8_t drv_can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t le
     tx_message.RTR = CAN_RTR_Data; // 消息类型为数据帧
     tx_message.DLC = len;          // 发送两帧信息
 
-    memcpy(tx_message.Data, p_data, len);
-    flg = CAN_Transmit(CAN1, &tx_message);
+    memcpy (tx_message.Data, p_data, len);
+    flg = CAN_Transmit (CAN1, &tx_message);
 
     return flg;
 }
 
-void drv_can_rx_back_init(pcan_rx p_fun)
+void drv_can_rx_back_init (pcan_rx p_fun)
 {
     pcan_rx_back = p_fun;
 }
 
-void drv_can_tx_back_init(pcan_tx p_fun)
+void drv_can_tx_back_init (pcan_tx p_fun)
 {
     pcan_tx_back = p_fun;
 }
 
-void CAN1_TX_IRQHandler(void)
+void CAN1_TX_IRQHandler (void)
 {
     if (pcan_tx_back != NULL)
     {
@@ -145,11 +145,11 @@ void CAN1_TX_IRQHandler(void)
     }
 }
 
-void CAN1_RX0_IRQHandler(void)
+void CAN1_RX0_IRQHandler (void)
 {
-    CAN_Receive(CAN1, CAN_FIFO0, &rx_message);
+    CAN_Receive (CAN1, CAN_FIFO0, &rx_message);
     if (pcan_rx_back != NULL)
     {
-        pcan_rx_back(rx_message);
+        pcan_rx_back (rx_message);
     }
 }

+ 5 - 5
driver/can/drv_can.h

@@ -5,12 +5,12 @@
 
 #define __CAN_BAUD_250K
 
-typedef void (*pcan_tx)(void);
-typedef void (*pcan_rx)(CanRxMsg);
+typedef void (*pcan_tx) (void);
+typedef void (*pcan_rx) (CanRxMsg);
 
 void    drv_can_init(); // CAN初始化
-uint8_t drv_can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len);
-void    drv_can_rx_back_init(pcan_rx p_fun);
-void    drv_can_tx_back_init(pcan_tx p_fun);
+uint8_t drv_can_msg_tx (uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len);
+void    drv_can_rx_back_init (pcan_rx p_fun);
+void    drv_can_tx_back_init (pcan_tx p_fun);
 
 #endif

+ 11 - 11
driver/dwt/dwt.c

@@ -22,10 +22,10 @@
 *                                             寄存器
 *********************************************************************************************************
 */
-#define DWT_CYCCNT *(volatile unsigned int *)0xE0001004
-#define DWT_CR     *(volatile unsigned int *)0xE0001000
-#define DEM_CR     *(volatile unsigned int *)0xE000EDFC
-#define DBGMCU_CR  *(volatile unsigned int *)0xE0042004
+#define DWT_CYCCNT       *(volatile unsigned int *) 0xE0001004
+#define DWT_CR           *(volatile unsigned int *) 0xE0001000
+#define DEM_CR           *(volatile unsigned int *) 0xE000EDFC
+#define DBGMCU_CR        *(volatile unsigned int *) 0xE0042004
 
 #define DEM_CR_TRCENA    (1 << 24)
 #define DWT_CR_CYCCNTENA (1 << 0)
@@ -38,11 +38,11 @@
 *	返 回 值: 无
 *********************************************************************************************************
 */
-void dwt_init(void)
+void dwt_init (void)
 {
-    DEM_CR |= (unsigned int)DEM_CR_TRCENA; /* Enable Cortex-M4's DWT CYCCNT reg.  */
-    DWT_CYCCNT = (unsigned int)0u;
-    DWT_CR |= (unsigned int)DWT_CR_CYCCNTENA;
+    DEM_CR |= (unsigned int) DEM_CR_TRCENA; /* Enable Cortex-M4's DWT CYCCNT reg.  */
+    DWT_CYCCNT = (unsigned int) 0u;
+    DWT_CR |= (unsigned int) DWT_CR_CYCCNTENA;
 }
 
 /*
@@ -82,7 +82,7 @@ void dwt_init(void)
 *              如果A < B  那么A - B = C, C的数值就是0xFFFFFFFF - B + A + 1。这一点要特别注意,正好用于本函数。
 *********************************************************************************************************
 */
-void delay_us(uint32_t us_time)
+void delay_us (uint32_t us_time)
 {
     uint32_t tCnt, tDelayCnt;
     uint32_t tStart;
@@ -97,7 +97,7 @@ void delay_us(uint32_t us_time)
     }
 }
 
-void delay_ms(uint32_t us_time)
+void delay_ms (uint32_t us_time)
 {
-    delay_us(1000 * us_time);
+    delay_us (1000 * us_time);
 }

+ 3 - 3
driver/dwt/dwt.h

@@ -13,8 +13,8 @@
 
 #include <stm32f4xx.h>
 
-void dwt_init(void);
-void delay_us(uint32_t us_time);
-void delay_ms(uint32_t us_time);
+void dwt_init (void);
+void delay_us (uint32_t us_time);
+void delay_ms (uint32_t us_time);
 
 #endif

+ 22 - 22
driver/flash/drv_flash.c

@@ -17,7 +17,7 @@
 /************************************************************************************************
  *                                          implements                                           *
  ************************************************************************************************/
-uint16_t fmc_get_flash_sector(u32 addr)
+uint16_t fmc_get_flash_sector (u32 addr)
 {
     if (addr < ADDR_FLASH_SECTOR_1)
         return FLASH_Sector_0;
@@ -45,38 +45,38 @@ uint16_t fmc_get_flash_sector(u32 addr)
 }
 
 // 解除写保护,清除fmc特定寄存器
-void fmc_clear_flag_star(void)
+void fmc_clear_flag_star (void)
 {
-    FLASH_Unlock();              // 解锁
-    FLASH_DataCacheCmd(DISABLE); // FLASH擦除期间,必须禁止数据缓存
-    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
+    FLASH_Unlock();               // 解锁
+    FLASH_DataCacheCmd (DISABLE); // FLASH擦除期间,必须禁止数据缓存
+    FLASH_ClearFlag (FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
 }
 
 // 设置写保护,清除fmc特定寄存器
-void fmc_clear_flag_end(void)
+void fmc_clear_flag_end (void)
 {
-    FLASH_DataCacheCmd(ENABLE); // FLASH擦除结束,开启数据缓存
-    FLASH_Lock();               // 上锁
+    FLASH_DataCacheCmd (ENABLE); // FLASH擦除结束,开启数据缓存
+    FLASH_Lock();                // 上锁
 }
 
 // 读取一字节, 读取无需考虑字节对齐
-uint8_t fmc_read_byte(uint32_t read_addr)
+uint8_t fmc_read_byte (uint32_t read_addr)
 {
-    return *(vu8 *)read_addr;
+    return *(vu8 *) read_addr;
 }
 
 // 读取两字节, 读取需考虑字节对齐
-uint16_t fmc_read_half_word(uint32_t read_addr)
+uint16_t fmc_read_half_word (uint32_t read_addr)
 {
-    return *(vu16 *)read_addr;
+    return *(vu16 *) read_addr;
 }
 
 // 读取N字节, 读取必须需考虑字节对齐
-uint8_t fmc_read_n_half_word(uint32_t read_addr, uint16_t *buff, uint16_t count)
+uint8_t fmc_read_n_half_word (uint32_t read_addr, uint16_t *buff, uint16_t count)
 {
     uint16_t i = 0;
 
-    vu16 *addr = (vu16 *)read_addr;
+    vu16 *addr = (vu16 *) read_addr;
 
     if (read_addr % 2 != 0)
         return 1; // 错误返回
@@ -89,11 +89,11 @@ uint8_t fmc_read_n_half_word(uint32_t read_addr, uint16_t *buff, uint16_t count)
 }
 
 // 读取1页, 地址必须对齐页首
-uint8_t fmc_read_one_page(uint32_t read_addr, uint16_t *buff)
+uint8_t fmc_read_one_page (uint32_t read_addr, uint16_t *buff)
 {
     uint16_t i = 0;
 
-    vu16 *addr = (vu16 *)read_addr;
+    vu16 *addr = (vu16 *) read_addr;
 
     if (read_addr % FMC_PAGE_SIZE != 0)
         return 1; // 错误返回
@@ -106,14 +106,14 @@ uint8_t fmc_read_one_page(uint32_t read_addr, uint16_t *buff)
 }
 
 // 擦出N页, 地址必须对齐页首
-uint8_t fmc_erase_pages(uint32_t erase_addr, uint16_t len)
+uint8_t fmc_erase_pages (uint32_t erase_addr, uint16_t len)
 {
 
     uint8_t status = 0;
     uint8_t i = 0, j = 0;
     for (i = 0; i < len; i++)
     {
-        status = FLASH_EraseSector(fmc_get_flash_sector(erase_addr), VoltageRange_3);
+        status = FLASH_EraseSector (fmc_get_flash_sector (erase_addr), VoltageRange_3);
         if (status != FLASH_COMPLETE)
         {
             return 1;
@@ -166,7 +166,7 @@ uint8_t fmc_erase_pages(uint32_t erase_addr, uint16_t len)
 }
 
 // 只写入,写入前需擦除,地址必须两字节对齐
-uint8_t fmc_write_n_half_word(uint32_t write_addr, uint16_t *buff, uint16_t len)
+uint8_t fmc_write_n_half_word (uint32_t write_addr, uint16_t *buff, uint16_t len)
 {
 
     uint32_t end_addr = write_addr + len * 2;
@@ -177,8 +177,8 @@ uint8_t fmc_write_n_half_word(uint32_t write_addr, uint16_t *buff, uint16_t len)
     while (write_addr < end_addr)
     {
 
-        FLASH_ProgramHalfWord(write_addr, *buff); // 写入数据
-        if (*(vu16 *)write_addr != *buff)
+        FLASH_ProgramHalfWord (write_addr, *buff); // 写入数据
+        if (*(vu16 *) write_addr != *buff)
         {
             return 1;
         }
@@ -188,7 +188,7 @@ uint8_t fmc_write_n_half_word(uint32_t write_addr, uint16_t *buff, uint16_t len)
     return 0;
 }
 
-uint16_t firmware_crc16_ccitt_false(uint16_t init_value, uint8_t *pbuff, uint32_t len)
+uint16_t firmware_crc16_ccitt_false (uint16_t init_value, uint8_t *pbuff, uint32_t len)
 {
     uint16_t temp = 0;
     uint16_t crc  = init_value;

+ 38 - 39
driver/flash/drv_flash.h

@@ -1,9 +1,13 @@
 #ifndef __DRV_FLASH_H
 #define __DRV_FLASH_H
 
+/************************************************************************************************
+ *                                          Includes                                             *
+ ************************************************************************************************/
+#include "stm32f4xx_flash.h"
+
 #ifdef __cplusplus
-extern 'C'
-{
+extern "C" {
 #endif
 #ifdef __DRV_FLASH_H_GLOBAL
 #define __DRV_FLASH_H_EXTERN
@@ -23,49 +27,44 @@ extern 'C'
  *                                          Enable config                                         *
  ************************************************************************************************/
 
-/************************************************************************************************
- *                                          Includes                                             *
- ************************************************************************************************/
-#include "stm32f4xx_flash.h"
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
-#define FMC_PAGE_SIZE     ((uint16_t)0x800)
-#define FMC_PAGE_SIZE_U16 ((uint16_t)0x400)
-#define FMC_FLASH_BASE    ((uint32_t)0x08000000)
+#define FMC_PAGE_SIZE         ((uint16_t) 0x800)
+#define FMC_PAGE_SIZE_U16     ((uint16_t) 0x400)
+#define FMC_FLASH_BASE        ((uint32_t) 0x08000000)
 
-#define FMC_PAGE_SIZE_16K  ((uint32_t)0x4000)
-#define FMC_PAGE_SIZE_32K  ((uint32_t)0x8000)
-#define FMC_PAGE_SIZE_64K  ((uint32_t)0x10000)
-#define FMC_PAGE_SIZE_128K ((uint32_t)0x20000)
+#define FMC_PAGE_SIZE_16K     ((uint32_t) 0x4000)
+#define FMC_PAGE_SIZE_32K     ((uint32_t) 0x8000)
+#define FMC_PAGE_SIZE_64K     ((uint32_t) 0x10000)
+#define FMC_PAGE_SIZE_128K    ((uint32_t) 0x20000)
 
-// FLASH 扇区的起始地址
-#define ADDR_FLASH_SECTOR_0   ((u32)0x08000000) // 扇区0起始地址, 16 Kbytes
-#define ADDR_FLASH_SECTOR_1   ((u32)0x08004000) // 扇区1起始地址, 16 Kbytes
-#define ADDR_FLASH_SECTOR_2   ((u32)0x08008000) // 扇区2起始地址, 16 Kbytes
-#define ADDR_FLASH_SECTOR_3   ((u32)0x0800C000) // 扇区3起始地址, 16 Kbytes
-#define ADDR_FLASH_SECTOR_4   ((u32)0x08010000) // 扇区4起始地址, 64 Kbytes
-#define ADDR_FLASH_SECTOR_5   ((u32)0x08020000) // 扇区5起始地址, 128 Kbytes
-#define ADDR_FLASH_SECTOR_6   ((u32)0x08040000) // 扇区6起始地址, 128 Kbytes
-#define ADDR_FLASH_SECTOR_7   ((u32)0x08060000) // 扇区7起始地址, 128 Kbytes
-#define ADDR_FLASH_SECTOR_8   ((u32)0x08080000) // 扇区8起始地址, 128 Kbytes
-#define ADDR_FLASH_SECTOR_9   ((u32)0x080A0000) // 扇区9起始地址, 128 Kbytes
-#define ADDR_FLASH_SECTOR_10  ((u32)0x080C0000) // 扇区10起始地址,128 Kbytes
-#define ADDR_FLASH_SECTOR_11  ((u32)0x080E0000) // 扇区11起始地址,128 Kbytes
-#define ADDR_FLASH_SECTOR_END ((u32)0x080FFFFF)
-    /************************************************************************************************
-     *                                          Defines                                              *
-     ************************************************************************************************/
+#define ADDR_FLASH_SECTOR_0   ((u32) 0x08000000) // 扇区0起始地址, 16 Kbytes
+#define ADDR_FLASH_SECTOR_1   ((u32) 0x08004000) // 扇区1起始地址, 16 Kbytes
+#define ADDR_FLASH_SECTOR_2   ((u32) 0x08008000) // 扇区2起始地址, 16 Kbytes
+#define ADDR_FLASH_SECTOR_3   ((u32) 0x0800C000) // 扇区3起始地址, 16 Kbytes
+#define ADDR_FLASH_SECTOR_4   ((u32) 0x08010000) // 扇区4起始地址, 64 Kbytes
+#define ADDR_FLASH_SECTOR_5   ((u32) 0x08020000) // 扇区5起始地址, 128 Kbytes
+#define ADDR_FLASH_SECTOR_6   ((u32) 0x08040000) // 扇区6起始地址, 128 Kbytes
+#define ADDR_FLASH_SECTOR_7   ((u32) 0x08060000) // 扇区7起始地址, 128 Kbytes
+#define ADDR_FLASH_SECTOR_8   ((u32) 0x08080000) // 扇区8起始地址, 128 Kbytes
+#define ADDR_FLASH_SECTOR_9   ((u32) 0x080A0000) // 扇区9起始地址, 128 Kbytes
+#define ADDR_FLASH_SECTOR_10  ((u32) 0x080C0000) // 扇区10起始地址,128 Kbytes
+#define ADDR_FLASH_SECTOR_11  ((u32) 0x080E0000) // 扇区11起始地址,128 Kbytes
+#define ADDR_FLASH_SECTOR_END ((u32) 0x080FFFFF)
+/************************************************************************************************
+ *                                          Defines                                              *
+ ************************************************************************************************/
 
-    void     fmc_clear_flag_star(void);
-    void     fmc_clear_flag_end(void);
-    uint8_t  fmc_read_byte(uint32_t read_addr);
-    uint16_t fmc_read_half_word(uint32_t read_addr);
-    uint8_t  fmc_read_n_half_word(uint32_t read_addr, uint16_t * buff, uint16_t count);
-    uint8_t  fmc_read_one_page(uint32_t read_addr, uint16_t * buff);
-    uint8_t  fmc_erase_pages(uint32_t erase_addr, uint16_t len);
-    uint8_t  fmc_write_n_half_word(uint32_t write_addr, uint16_t * buff, uint16_t len);
-    uint16_t firmware_crc16_ccitt_false(uint16_t init_value, uint8_t * pbuff, uint32_t len);
+void     fmc_clear_flag_star (void);
+void     fmc_clear_flag_end (void);
+uint8_t  fmc_read_byte (uint32_t read_addr);
+uint16_t fmc_read_half_word (uint32_t read_addr);
+uint8_t  fmc_read_n_half_word (uint32_t read_addr, uint16_t *buff, uint16_t count);
+uint8_t  fmc_read_one_page (uint32_t read_addr, uint16_t *buff);
+uint8_t  fmc_erase_pages (uint32_t erase_addr, uint16_t len);
+uint8_t  fmc_write_n_half_word (uint32_t write_addr, uint16_t *buff, uint16_t len);
+uint16_t firmware_crc16_ccitt_false (uint16_t init_value, uint8_t *pbuff, uint32_t len);
 
 #ifdef __cplusplus
 };

+ 12 - 12
driver/gpio/drv_gpio.c

@@ -1,8 +1,8 @@
 #include "drv_gpio.h"
 
-void drv_beep_init(void)
+void drv_beep_init (void)
 {
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
+    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOF, ENABLE);
 
     GPIO_InitTypeDef GPIO_StructInit;
     GPIO_StructInit.GPIO_Mode  = GPIO_Mode_OUT;
@@ -11,12 +11,12 @@ void drv_beep_init(void)
     GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
     GPIO_StructInit.GPIO_Pin   = DRV_GPIO_BEEP_PIN;
 
-    GPIO_Init(DRV_GPIO_BEEP_PORT, &GPIO_StructInit);
+    GPIO_Init (DRV_GPIO_BEEP_PORT, &GPIO_StructInit);
 }
 
-void drv_led_init(void)
+void drv_led_init (void)
 {
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
+    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOF, ENABLE);
 
     GPIO_InitTypeDef GPIO_StructInit;
     GPIO_StructInit.GPIO_Mode  = GPIO_Mode_OUT;
@@ -25,13 +25,13 @@ void drv_led_init(void)
     GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
     GPIO_StructInit.GPIO_Pin   = DRV_GPIO_LED0_PIN | DRV_GPIO_LED1_PIN;
 
-    GPIO_Init(DRV_GPIO_LED0_PORT, &GPIO_StructInit);
+    GPIO_Init (DRV_GPIO_LED0_PORT, &GPIO_StructInit);
 }
 
-void drv_key_init(void)
+void drv_key_init (void)
 {
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
+    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);
+    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOE, ENABLE);
 
     GPIO_InitTypeDef GPIO_StructInit;
     GPIO_StructInit.GPIO_Mode  = GPIO_Mode_IN;
@@ -40,14 +40,14 @@ void drv_key_init(void)
     GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
     GPIO_StructInit.GPIO_Pin   = DRV_GPIO_KEY0_PIN | DRV_GPIO_KEY1_PIN | DRV_GPIO_KEY2_PIN;
 
-    GPIO_Init(DRV_GPIO_KEY0_PORT, &GPIO_StructInit);
+    GPIO_Init (DRV_GPIO_KEY0_PORT, &GPIO_StructInit);
 
     GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_DOWN;
     GPIO_StructInit.GPIO_Pin  = DRV_GPIO_KEY_UP_PIN;
-    GPIO_Init(DRV_GPIO_KEY_UP_PORT, &GPIO_StructInit);
+    GPIO_Init (DRV_GPIO_KEY_UP_PORT, &GPIO_StructInit);
 }
 
-void drv_gpio_init(void)
+void drv_gpio_init (void)
 {
     drv_led_init();
     drv_key_init();

+ 18 - 18
driver/gpio/drv_gpio.h

@@ -3,25 +3,25 @@
 
 #include "stm32f4xx.h"
 
-#define DRV_GPIO_BEEP_PORT   GPIOF
-#define DRV_GPIO_BEEP_PIN    GPIO_Pin_8
-#define DRV_GPIO_LED0_PORT   GPIOF
-#define DRV_GPIO_LED0_PIN    GPIO_Pin_9
-#define DRV_GPIO_LED1_PORT   GPIOF
-#define DRV_GPIO_LED1_PIN    GPIO_Pin_10
-#define DRV_GPIO_KEY_UP_PORT GPIOA
-#define DRV_GPIO_KEY_UP_PIN  GPIO_Pin_0
-#define DRV_GPIO_KEY0_PORT   GPIOE
-#define DRV_GPIO_KEY0_PIN    GPIO_Pin_4
-#define DRV_GPIO_KEY1_PORT   GPIOE
-#define DRV_GPIO_KEY1_PIN    GPIO_Pin_3
-#define DRV_GPIO_KEY2_PORT   GPIOE
-#define DRV_GPIO_KEY2_PIN    GPIO_Pin_2
+#define DRV_GPIO_BEEP_PORT         GPIOF
+#define DRV_GPIO_BEEP_PIN          GPIO_Pin_8
+#define DRV_GPIO_LED0_PORT         GPIOF
+#define DRV_GPIO_LED0_PIN          GPIO_Pin_9
+#define DRV_GPIO_LED1_PORT         GPIOF
+#define DRV_GPIO_LED1_PIN          GPIO_Pin_10
+#define DRV_GPIO_KEY_UP_PORT       GPIOA
+#define DRV_GPIO_KEY_UP_PIN        GPIO_Pin_0
+#define DRV_GPIO_KEY0_PORT         GPIOE
+#define DRV_GPIO_KEY0_PIN          GPIO_Pin_4
+#define DRV_GPIO_KEY1_PORT         GPIOE
+#define DRV_GPIO_KEY1_PIN          GPIO_Pin_3
+#define DRV_GPIO_KEY2_PORT         GPIOE
+#define DRV_GPIO_KEY2_PIN          GPIO_Pin_2
 
-#define DRV_GPIO_LED0(on_off)      ((on_off == 0) ? (GPIO_ResetBits(DRV_GPIO_LED0_PORT, DRV_GPIO_LED0_PIN)) : (GPIO_SetBits(DRV_GPIO_LED0_PORT, DRV_GPIO_LED0_PIN)))
-#define DRV_GPIO_LED1(on_off)      ((on_off == 0) ? (GPIO_ResetBits(DRV_GPIO_LED1_PORT, DRV_GPIO_LED1_PIN)) : (GPIO_SetBits(DRV_GPIO_LED1_PORT, DRV_GPIO_LED1_PIN)))
-#define DRV_GPIO_BEEP(beep_status) ((beep_status == 0) ? (GPIO_ResetBits(DRV_GPIO_BEEP_PORT, DRV_GPIO_BEEP_PIN)) : (GPIO_SetBits(DRV_GPIO_BEEP_PORT, DRV_GPIO_BEEP_PIN)))
+#define DRV_GPIO_LED0(on_off)      ((on_off == 0) ? (GPIO_ResetBits (DRV_GPIO_LED0_PORT, DRV_GPIO_LED0_PIN)) : (GPIO_SetBits (DRV_GPIO_LED0_PORT, DRV_GPIO_LED0_PIN)))
+#define DRV_GPIO_LED1(on_off)      ((on_off == 0) ? (GPIO_ResetBits (DRV_GPIO_LED1_PORT, DRV_GPIO_LED1_PIN)) : (GPIO_SetBits (DRV_GPIO_LED1_PORT, DRV_GPIO_LED1_PIN)))
+#define DRV_GPIO_BEEP(beep_status) ((beep_status == 0) ? (GPIO_ResetBits (DRV_GPIO_BEEP_PORT, DRV_GPIO_BEEP_PIN)) : (GPIO_SetBits (DRV_GPIO_BEEP_PORT, DRV_GPIO_BEEP_PIN)))
 
-void drv_gpio_init(void);
+void drv_gpio_init (void);
 
 #endif // __DRV_GPIO_H

+ 9 - 7
driver/systick/drv_systick.c

@@ -6,25 +6,26 @@ static u8  fac_us = 0; // us延时倍乘数
 static u16 fac_ms = 0; // ms延时倍乘数
 
 volatile uint32_t systick_ms = 0;
+
 // 初始化延迟函数
 // 当使用ucos的时候,此函数会初始化ucos的时钟节拍
 // SYSTICK的时钟固定为HCLK时钟的1/8
 // SYSCLK:系统时钟
 void drv_systick_init()
 {
-    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
-    if (SysTick_Config(SystemCoreClock / 1000))
+    SysTick_CLKSourceConfig (SysTick_CLKSource_HCLK);
+    if (SysTick_Config (SystemCoreClock / 1000))
     {
         while (1)
         {
         }
     }
-    NVIC_SetPriority(SysTick_IRQn, 0x00);
+    NVIC_SetPriority (SysTick_IRQn, 0x00);
 }
 
 // 延时nus
 // nus为要延时的us数.
-void drv_delay_us(uint32_t nus)
+void drv_delay_us (uint32_t nus)
 {
     uint32_t temp;
     SysTick->LOAD = nus * fac_us;             // 时间加载
@@ -37,16 +38,17 @@ void drv_delay_us(uint32_t nus)
     SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // 关闭计数器
     SysTick->VAL = 0X00;                       // 清空计数器
 }
+
 // 延时nms
 // 注意nms的范围
 // SysTick->LOAD为24位寄存器,所以,最大延时为:
 // nms<=0xffffff*8*1000/SYSCLK
 // SYSCLK单位为Hz,nms单位为ms
 // 对72M条件下,nms<=1864
-void drv_delay_ms(u16 nms)
+void drv_delay_ms (u16 nms)
 {
     uint32_t temp;
-    SysTick->LOAD = (uint32_t)nms * fac_ms;   // 时间加载(SysTick->LOAD为24bit)
+    SysTick->LOAD = (uint32_t) nms * fac_ms;  // 时间加载(SysTick->LOAD为24bit)
     SysTick->VAL  = 0x00;                     // 清空计数器
     SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // 开始倒数
     do
@@ -57,7 +59,7 @@ void drv_delay_ms(u16 nms)
     SysTick->VAL = 0X00;                       // 清空计数器
 }
 
-uint32_t get_systick_ms(void)
+uint32_t get_systick_ms (void)
 {
     uint32_t tick, tick_ms;
     __disable_irq();

+ 4 - 5
driver/systick/drv_systick.h

@@ -5,10 +5,9 @@
 
 #define SYSTICK_EXT_CLOCK_1MS_CNT (SystemCoreClock / 1000)
 
-void drv_systick_init(void);
-
-uint32_t get_systick_ms(void);
-void     drv_delay_us(uint32_t nus);
-void     drv_delay_ms(uint16_t nms);
+void     drv_systick_init (void);
+uint32_t get_systick_ms (void);
+void     drv_delay_us (uint32_t nus);
+void     drv_delay_ms (uint16_t nms);
 
 #endif

+ 0 - 0
project/gcc/STM32F417IG_FLASH.ld → ldscripts/STM32F417IG_FLASH.ld


+ 0 - 0
project/gcc/startup_stm32f40xx.s → startup/startup_stm32f40xx.s