你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

SuperIMU Circle - AdaIMU - 13x 6DoF IMU BMI088传感器

[复制链接]
木木&点点 发布时间:2019-3-12 23:33
本帖最后由 点点&木木 于 2019-4-12 23:57 编辑 7 T/ R7 t! Z: ^2 _* c

4 _2 `3 d' U9 ]4 |2 i5 i1 V
5 |0 j% c  z( X# d1 U$ ^0 w; d
硬件组件
STM32 Nucleo-F746ZG  ×    1      
博世BMI088   ×          13     
跳线(通用)     ×  1      

& E. A/ Y) \& l; F3 _; a$ R7 |+ t
手动工具和制造机器
烙铁(通用)         
焊料空气流动站
信号分析仪
1 g5 h' _5 K3 g6 \

6 k- N/ q4 M$ V/ n' N( b
介绍
在这个项目中,我描述了我在Ada中的小型奥德赛,用于嵌入式ARM从头开始创建冗余IMU(使用多个6DoF陀螺仪/加速传感器)和软件环境来控制它。
我还将向您展示我用来达到目标​​的工具和方法(调试,分析器......)来估算一组6DoF IMU的音高和滚动:

* v' L; l# j+ M
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png 1.jpg

+ L6 k% T7 R5 F4 s% Q  c, }+ v, R
% z) a* |/ Y) L2 t* c

1 a  }; T$ x0 x2 I
局限性:
在本教程中,我没有描述控制火箭副翼或如何减少偏航旋转的PID过程,而只描述如何获取数据并估算滚转和俯仰。工作正在进行中,将在单独的教程中进行描述。
# P% ?4 P9 b9 F; v; X2 @
动机:
对于正在进行的业余火箭项目,我们需要一个能够容忍各种加速度(和陀螺仪)的IMU,而无需在飞行范围内重新配置。此外,我们希望有一个多IMU板用于可靠性和过滤目的。
出于这个原因,我设计了一个冗余的BMI088(13x IMU),试图在高振动环境中获得最佳结果,一个业余火箭和高精度无人机。
在我们的使用案例中,它将被放置在如下的火箭中,连接到托管微控制器的板,该微控制器能够控制和处理来自传感器的数据。

- i, f; w6 B# m: @# n
2.jpg

, u5 }: O; x3 R" k2 Q( Q* J$ Y6 H
使用AdaCore框架和工具链将使我们能够从他们提供的强大编码环境中受​​益(在安全/可靠性导向的行业中得到高度认可,如航空航天和运输)。
我注意到在代码实现过程中,Ada代码,特别是在AdaCore GitHubrepo中编辑的代码很容易阅读。对于像我这样习惯于C /C ++和java环境的人来说,使用Ada并不是特别难。
2 z5 c& F7 H, H& S8 Z# }
语境:
SuperIMU已被开发用于CNRS PlaneteScience的业余火箭队。它将有助于在高速和变化的振动环境中计算精确俯仰/滚转,以在飞行期间使用副翼稳定火箭。
/ ?9 v& u" z$ A  b! a
3.jpg
火箭的第一个目标

+ z) {0 A2 o2 l. r" H4 @# O
SuperIMU必须嵌入芯径小于90mm中。
. j, r3 [# o+ u5 x
4.jpg

. z1 |: \% f9 \6 {0 I' F4 Y+ K0 t  g  j
第1步:系统描述
SuperIMU具有13倍冗余6DoF IMU,可以直径50mm。它将使用SPI接口与微控制器通信,以获取原始数据(加速度和陀螺仪数据)。

5 @- n0 d' B5 h, f
5.jpg
板载配置

& o# G4 g$ P% B% X3 V7 X% P$ K
我们使用简单的架构来可视化和测试SuperIMU。
微控制器使用SPI端口从SuperIMU过滤原始数据(加速度,角度速率),并估算角度。出于测试目的,它使用UART端口发送角度值。
) W! E8 q8 R& ?6 I) P3 r' F1 X
6.jpg
测试configuartion
6 f  M' y, c/ Z& C" n$ ~1 h
UART端口连接到计算机,以串行到USB模块可视化数据。
该项目的下一步是为SuperIMU创建一个特定的主机板。主机板将是圆形的,并嵌入STM32F746微控制器。
IMU按以下方式分布,呈星形:

9 `' l$ _( S' W
7.jpg
角度分布遵循45°模式:

6 A* n6 S. u9 B+ _2 H0 Z
8.jpg
, r7 o! _- S. U5 {4 E& N
选择了先前的模式以最大化表面上IMU的存在。根据在德克萨斯大学(RedundantIMU Configurations:paper)进行的几何研究,其中测试了不同的几何配置:
6 [! C$ B) `' S# A# }
传感器的3D空间中的几何分布比计划中的分布更好的结果(我们的情况)
分布对加速度没有影响(aDOP Accelaration Dilution of Precision)
分布对旋转精度有影响(wDOP角精度稀释)
我们添加的IMU越多,我们的精确度就越高
IMU的方向对结果没有显着影响

- G& r8 r: u# A0 W
9.jpg
2 I* S) c; g- ]# z  h4 r
我们记住这个研究,为了达到像配置这样的立方体,我们可以将两个SuperIMU并行叠加。目前我们继续使用UnitCircle配置,尝试从中获取最大值。
7 ^  z  ]. w2 G; `1 }' j
10.jpg

4 \; z; t( w' z0 G+ ^
灵敏度范围配置:火箭模式
在业余火箭中,在飞行的最初几秒内,加速度可以达到8到9克。我们在滑槽开口和落地时观察到了一阵骚动。
这是一个典型的飞行日志(加速度/速度)的业余火箭与三个阶段(推进,上升无推进,滑槽开放,潜水与滑槽,地面接触):
11.jpg
1 h* @, I% x( M& }$ E! A8 h, N# J
在短途飞行期间,典型的加速曲线如下:
发射<7秒:加速度> 6g
在降落伞开启前<11s,无推进上升:<3g
用降落伞潜水<50s:<3
12.jpg

8 B" O, B2 {8 u2 x8 H
在飞行期间,感应范围需要容忍低和高,以无缝地进行精确控制。IMU的范围将在发布前配置。目前我将尝试四种不同的配置,当然这些配置不是确定的,它们需要通过实验进行调整:
13.jpg
1 n1 G6 r6 g7 {
IMU分布,范围和名称
在飞行期间,将根据配置的范围忽略传感器原始值:
14.jpg
4 A4 p! G1 n) h: d) x% X
过滤过程
在开始使用它们的俯仰/滚转估计之前,根据它们的范围过滤来自IMU的采集数据(加速度,角速度)。
范围过滤器:
过滤器获取原始数据,并根据每个IMU的配置范围,仅输出低于阈值的值:配置范围的95%。
范围滤波器还根据配置的范围提供每个测量数据的权重。权重用于取消高范围值的影响,它由平均过滤器使用。
权重具有以下值:0,1 / 2,1 / 4,1 / 8。
例如,如果IMU的范围是3G并且测量的加速度是2.9G,则范围滤波器输出来自该IMU的值为0的权重。
15.jpg
7 m& K. y; D0 ^3 O1 a+ ~8 t
例如,如果测量的加速度<1G,则最准确的IMU是配置有3G范围的IMU。3G IMU的重量为1,6G IMU的重量为1/2,12G IMU的重量为1/4,24G IMU的重量为1/8。
权重根据下表计算:
16.jpg

2 B9 q9 _. [; B/ {* O
例外,当测量数据> 24%> 95%时,它不会为零加权。它会避免产生价值。
范围滤波器的输出值是每个IMU的四倍(加速度,加速度,陀螺仪,陀螺仪等)。
6 ]# Z' G, `; D9 E* s
平均过滤器:
该过滤器根据每个重量计算平均值。当权重为空时,不考虑测量值。
平均滤波器输出滤波数据,该数据是3轴的耦合(accel_filtered-xyz,gyro_filtered-xyz)。

. k# D- A7 b! P
滚动/间距估算器:
然后使用经过滤的数据来估计滚转角和俯仰角。使用众所周知的互补滤波器来估计飞行角度。
17.jpg
# E' w" ]  T0 r5 p
TimeSampling
目标st具有估计角度@ 1ms的采样率。这意味着我们需要测量所有13xIMU,在1ms的时间范围内进行滤波和补充估计。
第2步:使用硬件
IMU传感器BMI088
使用的传感器是BMI088,它专为无人机和机器人设计:
它可以承受24g的加速度。
SPI运行速度最高为10Mhz。
分辨率:0.09mg,0.004°/ s
低TCO为0.2 mg / K,低光谱噪声仅为230 pg / sqrt(Hz)最大值
输出数据速率:1.6kHz - 每个加速度为0.6ms - 陀螺仪最大为2000Hz - 每个0.5ms
Nucleo-F746ZG的描述:
核板最有趣的是它们嵌入了ST Link V2-1编程接口以允许调试(例如使用OpenOCD或St-Util)。
它运行@ 216Mhz,非常适合需要快速采集和计算以获得最佳采样时间的用例。
您只需使用micro usb电缆将电路板连接到计算机。对于我的情况,我使用Ubuntu 18.x,自动检测到电路板,无需安装任何驱动程序。

  w6 b" m" ^/ e% o5 x. |, ?
18.jpg

- g& s1 ]5 E; C4 K
Nucleo主板的另一个有趣之处在于它们与ArduinoUno标头保持兼容。在下面以绿色(D0 ... D13)呈现。
19.jpg

; L4 f# r, `& N* X. b* N/ i
资料来源:https://os.mbed.com/platforms/ST-Nucleo-F746ZG/
. V/ Z8 ^# @1 f3 V4 m  k
由于我们需要在读取BMI088传感器(13x IMU)时将延迟降至最大,因此我们使用SPI端口获取Accel和Gyro数据(在这种情况下,I2C不适用)。
0 ?! R0 D) l+ O4 q, s& n
对于代码,我们将使用STM32F746的SPI1:
SCK:PA_5
MISO:PA_6
MOSI:PA_7
Super IMU的描述:
SuperIMU基于BMI088,它使用SPI接口配置和获取IMU的数据。从数据表中,用户电路如下:
20.jpg

+ p& v- z, G0 H! E2 u! j# x- O% i
在SuperIMU的情况下,没有使用中断,它按顺序获取数据。ACCEL和GYRO的SDO在电路板中输出相同的输出。
我必须单独选择每个Gyro和Accel。
21.jpg
3 Q" }: w6 w5 |/ k' a
AdaIMU BMI088 Circle(SuperIMU)的原理图
SuperIMU的设计可以使用单个SPI获取数据(下一个版本将使用多个SPI),它具有13x BMI088:
22.jpg

; |0 c& n! N0 C+ `( S
这是它的样子。我需要焊接接头以连接杜邦线:
23.jpg
在后面有引脚的描述,SPI(SDO / SCK / SDI)以及用于选择陀螺仪和引脚的引脚:
24.jpg
  s! G# E. R( n3 v8 S

; ?  N: B9 z6 j
25.jpg
  K2 L9 S/ }0 k, N9 L: L9 Z
8 X3 z! ^0 t: d7 q0 E, ~
26.jpg
完成焊接后的样子如下:
27.jpg
La pieuvre:
28.jpg
- e" X  K0 k3 o- H" C) r: v

8 d6 Q' f/ c, W6 K8 U% [2 O
29.jpg
SuperIMU使用3v3电源和SPI端口1连接到Nucleo板。
30.jpg
% V+ d6 ?; S- ~; c7 @" H- C

5 }# W' J7 k. n' c& w9 O
GPIO引脚用于选择Gyro,13x IMU的Accel将按如下方式完成:
31.jpg
# F$ Y1 e. f, _8 @1 s4 M3 m

8 v! A6 C5 z6 m3 ~. x0 p
用于选择IMU的陀螺仪/加速度计的GPIO引脚的定义:
-- IMU select
  IMU1_SPI1_SELC    : GPIO_Point renames PC8;
  IMU1_SPI1_SELG    : GPIO_Point renames PC9;
  IMU2_SPI1_SELC    : GPIO_Point renames PC10;
  IMU2_SPI1_SELG    : GPIO_Point renames PC11;
  IMU3_SPI1_SELC    : GPIO_Point renames PC12;
  IMU3_SPI1_SELG    : GPIO_Point renames PD2;
  IMU4_SPI1_SELC    : GPIO_Point renames PG2;
  IMU4_SPI1_SELG    : GPIO_Point renames PG3;
  IMU5_SPI1_SELC    : GPIO_Point renames PD7;
  IMU5_SPI1_SELG    : GPIO_Point renames PD6;
  IMU6_SPI1_SELC    : GPIO_Point renames PD5;
  IMU6_SPI1_SELG    : GPIO_Point renames PD4;
  IMU7_SPI1_SELC    : GPIO_Point renames PD3;
  IMU7_SPI1_SELG    : GPIO_Point renames PE2;
  IMU8_SPI1_SELC    : GPIO_Point renames PE4;
  IMU8_SPI1_SELG    : GPIO_Point renames PE5;
  IMU9_SPI1_SELC    : GPIO_Point renames PE6;
  IMU9_SPI1_SELG    : GPIO_Point renames PE3;
  IMU10_SPI1_SELC   : GPIO_Point renames PF8;
  IMU10_SPI1_SELG   : GPIO_Point renames PF7;
  IMU11_SPI1_SELC   : GPIO_Point renames PF9;
  IMU11_SPI1_SELG   : GPIO_Point renames PG1;
  IMU12_SPI1_SELC   : GPIO_Point renames PA3;
  IMU12_SPI1_SELG   : GPIO_Point renames PC0;
  IMU13_SPI1_SELC   : GPIO_Point renames PC3;
  IMU13_SPI1_SELG   : GPIO_Point renames PF3;
  IMU_SPI1_SEL_Points : constant STM32.GPIO.GPIO_Points := (IMU1_SPI1_SELC,
                                                            IMU1_SPI1_SELG,
                                                            IMU2_SPI1_SELC,
                                                            IMU2_SPI1_SELG,
                                                            IMU3_SPI1_SELC,
                                                            IMU3_SPI1_SELG,
                                                            IMU4_SPI1_SELC,
                                                            IMU4_SPI1_SELG,
                                                            IMU5_SPI1_SELC,
                                                            IMU5_SPI1_SELG,
                                                            IMU6_SPI1_SELC,
                                                            IMU6_SPI1_SELG,
                                                            IMU7_SPI1_SELC,
                                                            IMU7_SPI1_SELG,
                                                            IMU8_SPI1_SELC,
                                                            IMU8_SPI1_SELG,
                                                            IMU9_SPI1_SELC,
                                                            IMU9_SPI1_SELG,
                                                            IMU10_SPI1_SELC,
                                                            IMU10_SPI1_SELG,
                                                            IMU11_SPI1_SELC,
                                                            IMU11_SPI1_SELG,
                                                            IMU12_SPI1_SELC,
                                                            IMU12_SPI1_SELG,
                                                            IMU13_SPI1_SELC,
                                                            IMU13_SPI1_SELG);
  IMU_SPI1_Accel_SEL_Points : array (1 .. 13) of access GPIO_Point'Class := (
                                                            IMU1_SPI1_SELC'Access,
                                                            IMU2_SPI1_SELC'Access,
                                                            IMU3_SPI1_SELC'Access,
                                                            IMU4_SPI1_SELC'Access,
                                                            IMU5_SPI1_SELC'Access,
                                                            IMU6_SPI1_SELC'Access,
                                                            IMU7_SPI1_SELC'Access,
                                                            IMU8_SPI1_SELC'Access,
                                                            IMU9_SPI1_SELC'Access,
                                                            IMU10_SPI1_SELC'Access,
                                                            IMU11_SPI1_SELC'Access,
                                                            IMU12_SPI1_SELC'Access,
                                                            IMU13_SPI1_SELC'Access
                                                           );
  IMU_SPI1_Gyro_SEL_Points : array (1 .. 13) of access GPIO_Point'Class := (
                                                            IMU1_SPI1_SELG'Access,
                                                            IMU2_SPI1_SELG'Access,
                                                            IMU3_SPI1_SELG'Access,
                                                            IMU4_SPI1_SELG'Access,
                                                            IMU5_SPI1_SELG'Access,
                                                            IMU6_SPI1_SELG'Access,
                                                            IMU7_SPI1_SELG'Access,
                                                            IMU8_SPI1_SELG'Access,
                                                            IMU9_SPI1_SELG'Access,
                                                            IMU10_SPI1_SELG'Access,
                                                            IMU11_SPI1_SELG'Access,
                                                            IMU12_SPI1_SELG'Access,
                                                            IMU13_SPI1_SELG'Access
                                                            );
- f- K' v" T  w- ^# F. c! V

. F5 B! i$ z) V( v1 Z
2 R" D6 `6 e+ C0 R8 V& H$ @

3 O+ o( L8 o+ r3 [
第3步:软件设置/ IDE
使用Adacore GPS IDE
我从Adacore网站安装了GPS IDE:gnat-community-2018-20180528-x86_64-linux-bin,它有一个很酷的编辑器,包括debuging界面和Ada和SPARK的所有检查环境。
我从Adacore网站安装了Arm-ELF编译器:gnat-community-2018-20180524-arm-elf-linux64-bin,它为ARM(以及bb-runtimes)提供编译器和构建器工具链。
5 d8 a. _  L& x- t6 _$ p6 n/ E
使用项目的代码
要使用该软件,您需要克隆此分支http://github.com/LaetitiaEl/Ada_Drivers_Library,此存储库基于Ada驱动程序库:AdaCore /Ada_Drivers_Library
5 {8 _" E, d: b
使用./GNAT/2018/bin/gps 打开项目文件:Ada_Drivers_Library / examples /STM32F746_Nucleo / SuperIMU.gpr
你编译/上传,这就是全部!
8 v. |/ {% M6 I& ]5 w% _
该项目针对STM32F746,如果需要可以轻松移植到STM32F4(通过github或黑客联系我寻求帮助)。

( l, T: f1 F- n  \0 @. t7 [; l
第4步:首先进行眨眼测试!
在继续之前,我需要确保可以正确编程电路板。
" e- r3 n' i% _8 @3 F0 t; [3 _" I
我保留了现有文件:blinky_f7disco.gpr,并修改了以下路径。继续使用stm32f746_discovery_full.gpr没问题

2 F+ p% g9 u4 i9 R2 x& x$ H
with "../../boards/stm32f746_nucleo/stm32f746_discovery_full.gpr";
blinky_f7disco使用以下主条目:
Ada_Drivers_Library/examples/shared/hello_world_blinky/src/blinky.adb

" L! l  r% H3 a& I& i* ?
blinky的内容如下:
with STM32.Board;   use STM32.Board;
5 \, X$ W+ O. |with STM32.GPIO;    use STM32.GPIO;
. @* o% K& S  Vwith Ada.Real_Time; use Ada.Real_Time;
7 s" ]* ?/ A. Q. b5 J. |8 x& Dprocedure Blinky is
  b; `: g, c# @0 R. ~  Period : constant Time_Span := Milliseconds (200);  -- arbitrary2 v/ s% L: Z  h, G
  Next_Release : Time := Clock;0 t: ]4 }+ w1 x+ G
begin9 s5 |5 h1 l- {) C! w, n) J  \
  STM32.Board.Initialize_LEDs;$ V, H# Z# G* i! C
  loop
$ B+ X, ~/ Z! R9 U2 O/ q' D     Toggle (All_LEDs);
9 n, D7 {7 B1 D3 d. I     Next_Release := Next_Release + Period;# p7 ]+ M; |4 U2 L! H
     delay until Next_Release;
$ T5 K# z9 k& ~  end loop;1 e9 v2 o1 R, X: e8 a0 W
end Blinky;
9 m8 `5 c/ j/ C7 H' Z. u
0 t1 e- E4 U- y$ ]# S* K! |1 j
- F4 [) i4 @! S% n! I4 b4 }

- v- M6 K+ O/ o1 \* U) B8 n9 ]
似乎这个代码对所有主板都是通用的。使用GPS IDE我遵循All_LED的定义,它定义于:
Ada_Drivers_Library/boards/stm32_common/stm32f746disco/stm32-board.ads
& e7 g9 h* Z% r" c
值All_LEDs是索引为1的集合,指向PI1:
  Green_LED : User_LED renames PI1;& V6 p1 a7 `0 Y( v
  LED1      : User_LED renames Green_LED;
* p$ F8 s3 k4 o- U$ m" Z  LCH_LED   : User_LED renames Green_LED;+ H- a5 I  p& k  C, h6 m
  All_LEDs : GPIO_Points := (1 => Green_LED);
: M" y2 A, a* F7 I. O8 u7 F  s4 H5 c1 |% p' j6 j
2 K0 T! m* @- c) G+ @3 t
在Nucleo板上没有LED连接到PI1,找出我可以使用的输出,简单的方法是检查核板的原理图http://www.st.com/resource/en/sc ... leo_144pins_sch.zip

' e* I8 t( i, b) m. x
32.jpg

' h, E$ Q+ V8 |! L3 v2 D/ Q4 [$ Y
我把蓝色LED连接到PB7。然后代码更新为蓝色:Blue_LED : User_LED renames PB7;* D3 O+ `, {( c, x
  LED1      : User_LED renames Blue_LED;
; D  j' H. B) l  LCH_LED   : User_LED renames Blue_LED;& w! g0 I0 M; {6 H' K
  All_LEDs : GPIO_Points := (1 => Blue_LED);
' j5 p: L8 v6 V  [4 }  W" Z* ^" l3 b6 W
* X$ n9 q) e: s% l! g" ~8 j" \

4 k3 Y/ }7 n- c9 I) N5 [7 \9 K6 I2 b8 Z9 d1 Q0 K
然后使用上传按钮上传代码(重要的是您需要配置上传/调试,在我的情况下,我使用OpenOCD,如下所述)
33.jpg
代码编译得很好,正确上传并且蓝色LED闪烁:
34.jpg

4 o  t6 c7 }( D+ @: q
让我们开始认真的工作。为BMI088制作SPI驱动程序。

" L  s% ^; M9 q5 N
第5步:为BMI088制作驱动程序
很酷的是,Ada_Drivers_Library已经在“components / src / motion”目录中提供了一些SPI IMU示例。
我只需要使用l3gd20来启动bmi088的驱动程序以获得灵感。
35.jpg
要正确选择寄存器和协议特性,请使用以下资源: - BST-BMI088-DS001- officiel C驱动程序:有助于获得时间
有关信息,现有驱动程序的演示位于路径中:Ada_Drivers_Library/ arch / ARM / STM32 / driver_demos /
更新板定义:定义SPI1在STM32.Board包体中的文件stm32-board.ads中,我们添加:
  ---------------------------------0 {" H8 K- A* {0 p+ P2 }9 Y
  --  SPI1 / IMU BMI088 example  --' Q1 C, S: ^2 ~3 b* s- n9 A
  ---------------------------------" `3 Z) \/ @" g5 c( _
  -- SPI Port
; b. d" o: m% x8 {3 x  IMU_SPI : SPI_Port renames SPI_1;
. R' t# V8 u. C& a1 t% Z( @3 n9 n  -- SPI IOs
5 w4 U; C8 f5 f2 M) c  SPI1_SCK     : GPIO_Point renames PA5; -- D13 in connector CN10" ]8 @6 w  i% u  @
  SPI1_MISO    : GPIO_Point renames PA6; -- D14 in connector CN107 Q3 A* ^  u/ U" D8 g
  SPI1_MOSI    : GPIO_Point renames PA7; -- D15 in connector CN107 N2 B- v% u$ N5 k1 f* _. X# N7 D( _& }
  -- IMU select& _3 B; m2 d) n) r
  IMU_SEL1    : GPIO_Point renames PG9; -- D0 in connector CN10' r& p5 P9 p5 g" d
  -- To initialize the SPI1 port for the BMI088
& M/ M1 w2 w5 z8 ?, L) j7 [$ {  procedure Initialize_SPI1_For_BMI088;6 @% b6 b4 Z; u3 k+ q

8 o2 i9 l0 z7 [1 X* P
) x) @- ]5 c6 }% k) P* p5 n' ~
STM32F7中使用8SPI的技巧
BIM088与8位通信非常重要。但是数据tx / rx DR寄存器是16位,默认情况下它发送16位。首先写入/读取:NOK
36.jpg

" a9 P, D3 [! K) o3 i
根据参考手册,诀窍是将寄存器DS(数据大小)配置为4位,并正确格式化DR寄存器中写入的数据。
37.jpg
7 g- Z* Y5 ~$ d3 r
这就是为什么我更新了SPI(stm32-spi.adb)的默认驱动程序,如下面的写/读8位模式。
3 s" a& I& m9 \' ?  r
procedure Configure (This : in out SPI_Port; Conf : SPI_Configuration) is$ C9 z/ E4 t- d8 B
  begin
8 @$ r$ J0 |8 A& {...; n4 D4 K* S: y8 D
    This.Periph.CR1.DFF     := Conf.Data_Size = HAL.SPI.Data_Size_16b;# c! y0 t2 A1 n7 Y) Y2 s
     This.Periph.CR2.DS      := STM32_SVD.SPI.Size_4Bit; -- add this line
, c- o! T, }4 {     This.Periph.CR1.CPOL     := Conf.Clock_Polarity = High;
- |# {5 u" u# h- l/ M2 v+ ^+ u...
1 s0 K. x+ x$ J. b# F& ?) T, R* Cprocedure Send_8bit_Mode% C6 S# H, V' _* V% z9 E7 m1 `8 \* \
    (This     : in out SPI_Port;
4 |; {2 T9 r6 U' e5 @' \0 R     Outgoing : HAL.SPI.SPI_Data_8b)5 n0 T4 ~# s* ^8 ^4 G+ v' e$ D
  is& h8 t  G0 R1 t3 S, |
     Tx_Count : Natural := Outgoing'Length;' G9 l  f/ w+ B& i: b+ c* L; W/ C
     Index    : Natural := Outgoing'First;! y7 B8 v+ u5 ?8 r7 B7 ~' O5 j
     Tmp : UInt16;
+ e/ r: E  T/ |/ n5 C2 _/ ?0 B/ c  begin: k" w* n  r2 e0 l) A  I( {$ N  W
     if Current_Mode (This) = Slave or else Tx_Count = 1 then0 L: ~0 t6 ~4 _: l: D! P. e
        Tmp := UInt16 ((Outgoing (Index) and 16#0F#))*256 + UInt16((Outgoing (Index) and 16#F0#))/16;8 l  e! K' {. s! |+ P. ^
        This.Periph.DR.DR := Tmp;
0 u; x; V: y( z) O        Index := Index + 1;! }' B) |  Z4 x) p3 m
        Tx_Count := Tx_Count - 1;
& l- d- c0 u# u+ c: u     end if;( f! K. C4 v, O% m. l( \
...1 W/ x4 u, h) \& f- C. }
procedure Receive_8bit_Mode
! _9 C4 ^# y# K/ b1 V    (This     : in out SPI_Port;: v1 |; G  P6 s+ B" [' \, G* C
     Incoming : out HAL.SPI.SPI_Data_8b)( F. ~) i& M4 F. D' K. M+ `
  is0 \  K" A( D9 V$ }% L& f2 F) \7 y3 g/ o5 n
     Generate_Clock : constant Boolean := Current_Mode (This) = Master;8 n$ C$ u- e' p$ U) s1 ^
     Tmp : Uint16;
8 g+ p7 K( Q1 E$ L8 M  begin
$ w9 b- d: `5 V, W* Q- m0 w) x     for K of Incoming loop# l& e* W# L( w" A
        if Generate_Clock then
; ~2 Q+ F( f7 {. P9 w/ A: x5 {2 X           This.Periph.DR.DR := 0;* r7 C. J/ @8 Y! L- z6 V
        end if;" ?' R9 L2 x4 K- c
        while Rx_Is_Empty (This) loop
& n) Y$ D8 J' k( X2 \* v- w- u) \           null;% {. m6 T& G1 [: {4 |( q
        end loop;: h; c4 r/ V" s' a
        Tmp := This.Periph.DR.DR;5 c4 n4 W; o( X, U2 X
        K := UInt8 (Tmp and 16#000F#)*16+ UInt8 ((Tmp and 16#0F00#)/256);& ^: N% n, M- Y# }; |" w! L$ ^
...0 T2 r  C7 h3 ]) M
; S5 O8 o9 z6 L) Q
0 N$ \/ D7 b2 z

7 |1 `; j) X" N' w( D, o6 V/ l: A+ {, h! L

% ]# X% Z0 Y! u% @2 C) ^+ L# t1 y
这样我获得了更好的时钟,BMI088寄存器中的读/写在8位模式下工作正常:
38.jpg
+ I2 J, o7 @* @& w. Y6 H0 U% d
但还是不行:
因为我们需要在读取加速度计时(不是陀螺仪的情况)总是丢弃BMI088中的第一个接收字节。这就是为什么每次我进行读取时,我都必须先读取虚拟字节。通过此更新,我获得了更好的结果。

: {0 O5 q9 i4 A4 k
在BMI088.adb中:
  ----------
  -- Read --
  ----------
  procedure Accel_Read
    (This : Six_Axis_Imu;
     Addr : Register;
     Data : out UInt8)
  is
     Status : SPI_Status;
     Tmp_Data : SPI_Data_8b (1 .. 1);
  begin
     SPI_Mode (This, Enabled => True);  -- select the chip
     This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD),
                        Status);
     if Status /= Ok then
        raise Program_Error;
     end if;
     This.Port.Receive (Tmp_Data, Status); -- dummy constraint BMI088
     This.Port.Receive (Tmp_Data, Status);
     if Status /= Ok then
        raise Program_Error;
     end if;
     Data := Tmp_Data (Tmp_Data'First);
     SPI_Mode (This, Enabled => False); -- unselect the chip
  end Read;
  ----------------
  -- Read_UInt8s --
  ----------------
  procedure Accel_Read_UInt8s
    (This   : Six_Axis_Imu;
     Addr   : Register;
     Buffer : out SPI_Data_8b;
     Count  : Natural)
  is
     Index : Natural := Buffer'First;
     Status : SPI_Status;
     Tmp_Data : SPI_Data_8b (1 .. 1);
  begin
     SPI_Mode (This, Enabled => True);
     This.Port.Transmit
       (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD),
        Status);
     if Status /= Ok then
        raise Program_Error;
     end if;
     This.Port.Receive (Tmp_Data, Status); -- dummy constraint BMI088
     for K in 1 .. Count loop
        This.Port.Receive (Tmp_Data, Status);
        if Status /= Ok then
           raise Program_Error;
        end if;
        Buffer (Index) := Tmp_Data (Tmp_Data'First);
        Index := Index + 1;
     end loop;
     SPI_Mode (This, Enabled => False);
  end Read_UInt8s;
$ E- e! A' o% q
0 k+ t) ]9 B: ]4 `& i
7 C. z7 R! G$ ~# R# O1 K
最好从寄存器中读取加速数据。在下图中,我们仅表示SDO和时钟(SDI未表示,我只有2个探测......:'():
39.jpg
对于陀螺仪数据,虚拟字节没有问题。
这就是为什么必须要有Accel_Read和Gyro_Read不同的程序。
初始化BMI088的步骤
首先,您需要通过调用以下过程正确初始化SPI以与BMI088通信:

& e7 r6 _( u2 ^( v5 ~# N
procedure Initialize_SPI1_For_BMI088 is5 o8 y  M; k' ^
     Config : GPIO_Port_Configuration;
+ r' _& Q" k( v6 `4 z- S' F9 \; g     Config_SPI : SPI_Configuration;! ?. t( q$ \* ~' u3 K! E' e0 g
  begin
7 t, v9 k2 l, G% w     -- Enable the clocks
/ d6 ?) [9 z4 q# S( M, w+ L6 `     Enable_Clock (IMU_SPI);/ l" ^' l  \" A9 n9 P6 \6 O+ f% @* n4 H
     Enable_Clock (SPI1_Points);
; u5 j; f0 O% G7 d& o# C4 k     Enable_Clock (IMU_SEL1);2 Z$ V: t# R8 P
     -- Configure the SPI IOs* u* b7 _2 N4 {/ }6 i
     Config := (Mode           => Mode_AF,
6 n5 A' ?- o+ J7 G! ~! L3 _. S                   AF             => GPIO_AF_SPI1_5,& `7 y) o; h; t( b8 c. C) l, h+ e7 _
                   AF_Speed       => Speed_100MHz,3 m" G0 \1 M7 |
                   AF_Output_Type => Push_Pull,# _5 ~5 D, y% Q5 E9 H  ~3 O
                Resistors      => Floating);! Q7 ]  @* |9 _$ m- |$ p
     Configure_IO(SPI1_Points, Config);
8 C/ e) T, v7 M" Y+ @; n: o     -- Configure the SPI select chip IOs! n5 L" ^# M( }% C. |, U
     Config := (Mode        => Mode_Out,) W+ {8 F$ X3 A% d
                   Speed       => Speed_25MHz,
# I3 _, C' w, N  t, P                   Output_Type => Push_Pull,
9 p5 V6 b' H$ E1 z( q* H2 K* G                   Resistors   => Pull_Up);
% Q9 b* j: @7 N1 m4 k/ Z1 Y) i     Configure_IO(IMU_SEL_Points, Config);( }2 H7 i/ I. @4 ^; S
     -- Configure the SPI1 port5 C# P/ k: \- |- d: y: L
     Config_SPI :=
- U8 X+ X4 R) q, D# T3 f          (Direction           => D2Lines_FullDuplex,
4 `: v9 h! @9 G7 a           Mode                => Master,
0 A- [* `+ c, y4 O0 I: e/ o           Data_Size           => HAL.SPI.Data_Size_8b,
# y. H. U1 X+ k0 ^: b2 I           Clock_Polarity      => Low,. _7 E: N4 M, U% I; U7 ?, V6 w5 h+ K6 N
           Clock_Phase         => P1Edge,+ A2 ^3 l2 h! T
           Slave_Management    => Software_Managed,
1 t" ~7 M( H. I           Baud_Rate_Prescaler => BRP_32
4 y  p# A, \& H4 ?5 z4 W  F           First_Bit           => MSB,
' D, E- M& F6 [+ }! v           CRC_Poly            => 7);
5 r4 v) o- q6 o, [4 W     Configure (IMU_SPI, Config_SPI);
' M1 Y1 p, a& P' S+ F     STM32.SPI.Enable (IMU_SPI);8 ]8 k% p; W( i; ]
  end Initialize_SPI1_For_BMI088;
, S5 p3 K9 S2 u  O2 g; M3 r
, f7 s0 m# ^& j0 n" p. @
然后按照以下步骤获取加速度计(寄存器和命令的值在数据表中定义,您可以在最后的驱动程序中找到它们):
# Y- u" g/ L+ ?% b  l4 V& K
---- check the device ID7 z  u7 @& U/ J8 j- j
  Bmi.Read(ACC_CHIP_ID_ADDR, Result);; A3 w( g  x. C' \: F# X
  while Result /= ACC_CHIP_ID loop
: o1 @7 c& W* y0 |) Y5 M     Bmi.Read(ACC_CHIP_ID_ADDR, Result);- N3 ?1 D% V. [4 t% {* s
     delay until Clock + Milliseconds (1);/ V& T0 ]& X0 {, L
  end loop;
3 v& j- H1 ~1 C3 F" Y$ w: C& a3 x$ n---- reset the accel
) }6 i0 O3 ~6 r! |4 f% U  Bmi.Write(ACC_SOFT_RESET_ADDR,ACC_RESET_CMD);
/ A% Q8 q3 F( d! U' N2 X. K5 X* g  delay until Clock + Milliseconds (50);
6 E* r" Z: S7 `2 S' x8 L/ i! f  Turn_ON(IMU_SEL1);
* n7 R$ ]* Y) W+ [5 ^* n; @3 u8 T2 h  delay until Clock + Milliseconds (5);
6 X  a1 U4 x7 @" s( i( ^  Turn_Off(IMU_SEL1);
# w2 R# D( c& i. G# V% S4 ?  delay until Clock + Milliseconds (5);3 |0 @1 m( R' P# Q" O
---- enable the accel (rundandant to make sure it works)" u' `* Q% \1 X1 n
  Bmi.Write(ACC_PWR_CNTRL_ADDR,ACC_ENABLE_CMD);
: s/ Q  u7 w9 T/ ~% M! k6 o' Z5 o  delay until Clock + Milliseconds (50);  
+ ?* ]' V3 X. P1 k! V  Bmi.Read(ACC_PWR_CNTRL_ADDR, Result);
" j3 G5 c0 b0 Q! d7 |  while Result /= ACC_ENABLE_CMD loop
/ J7 c/ ?8 f& Z4 H/ X' j     Bmi.Write(ACC_SOFT_RESET_ADDR,ACC_RESET_CMD);
- t6 A: K# C+ A! i     --delay until Clock + Milliseconds (1);& s( X" ?* Z5 F* q/ D5 W
     Bmi.Write(ACC_PWR_CNTRL_ADDR,ACC_ENABLE_CMD);' O! b6 u( n" {4 f+ N$ L
     --delay until Clock + Milliseconds (50);* p* M5 q! U, R+ a# e6 L
     Bmi.Read(ACC_PWR_CNTRL_ADDR, Result);
. ^& n0 d: V6 _5 P9 W     delay until Clock + Microseconds (4);
0 U$ a) y. H, Z/ u4 E  end loop;- ?/ F* V& y# u! G
---- enter active mode
1 p. A; }2 C( l6 [' @/ e  Bmi.Write(ACC_PWR_CONF_ADDR,ACC_ACTIVE_MODE_CMD);  _( E" r& p1 S& E
  delay until Clock + Milliseconds (5);
% B0 k, \% ]% H2 h  ^$ M$ u  Bmi.Read(ACC_PWR_CONF_ADDR, Result);3 C: R: j- `' a5 T# u
  while Result /= ACC_ACTIVE_MODE_CMD loop
) @" {% x4 f9 @" c4 W) N4 a5 p     Bmi.Write(ACC_PWR_CONF_ADDR,ACC_ACTIVE_MODE_CMD);
, j( I2 x. a: U* G' r     delay until Clock + Milliseconds (5);
( o: X. y- A8 {& o, I! W* y  r     Bmi.Read(ACC_PWR_CONF_ADDR, Result);
9 {, x/ J- f5 u6 H3 D0 y  end loop;
, w$ [- ^9 @. m/ B. @) ?% a---- set range 24G+ `! C9 i* i& c' V
  Bmi.Write(ACC_RANGE_ADDR,RANGE_24G);# E/ w4 J- K9 L. |
  delay until Clock + Milliseconds (1);
6 Q1 I# B0 d1 j5 {( w4 |  Bmi.Read(ACC_RANGE_ADDR, Result);4 @+ }* w- c/ Y7 V
  while Result /= RANGE_24G loop
+ Z' V+ G& S7 k  I     Bmi.Read(ACC_RANGE_ADDR, Result);
2 e, O) D5 X% T5 w' I: A/ H  end loop;
  `4 N! c. m$ T1 O0 y3 N( J: g4 [  I---- set default ODR
2 l3 X. y9 b9 a1 D' l  Bmi.Write(ACC_ODR_ADDR,ODR_1600HZ_BW_280HZ);' s9 D' E; R/ d, T2 l1 H5 l
  delay until Clock + Milliseconds (1);
9 x" R# K4 j, C: J; l  Bmi.Read(ACC_ODR_ADDR, Result);
0 T$ k  B9 @+ N- h  while Result /= ODR_1600HZ_BW_280HZ loop( A9 o2 m1 u9 u
     Bmi.Read(ACC_ODR_ADDR, Result);* y$ ^; g# w7 j) }% J3 t
  end loop;% y  x' y- D" m4 J( F6 s
---- check if there is an error: A$ Q3 S: A: F  R0 q7 L: e3 ^
  Bmi.Read(ACC_ERR_CODE_ADDR, Result);
1 E7 V* l9 N. [1 ^3 K" \" O2 N  while Result /= 16#0# loop
( M4 r5 ?' ^) Q! I% ]* i) h: z     Bmi.Read(ACC_ERR_CODE_ADDR, Result);& G: p# U( F  X% p3 D
  end loop;! c8 s* h; i, m  B2 i2 f! ?
  ---- read the value
& d9 W7 X9 o. ]9 T" }+ f$ K  loop9 p  W- y( O; \3 l
     Bmi.Read_UInt8s(ACC_ACCEL_DATA_ADDR,Received,6);
5 r& s. h  u$ Z% ^$ w" D     delay until Clock + Microseconds (100);
; \! W. k  B5 F& B  end loop;( C  C8 t( c" I) p# m$ A

3 m' k$ n# O0 \
按照上面的步骤,我使用来自BMI088的SPI获取值。
0 k3 G9 ]) k4 G: o( z! P: R. \9 m
步骤6:过滤和估计描述
应用几何变换:
SuperIMU中IMU的配置不一样,它们被旋转(45°和90°):
40.jpg
只有加速度X和Y受到旋转的影响。陀螺仪没有受到影响(转速是相对的)。
% u+ [3 y) ?  l3 N+ Q. B
根据每个IMU位置完成旋转变换。旋转按以下过程编码:

, h5 _/ i* b1 B) I' J" l, P+ L
--------------------
  -- Accel rotation --
  --------------------
  Sqrt2 : constant Float := 1.41421356237;
  IMU_Alpha_Index : constant array (1 .. 3) of Integer := (1,3,7);
  IMU_Beta_Index  : constant array (1 .. 2) of Integer := (5,11);
  IMU_Gamma_Index : constant array (1 .. 2) of Integer := (4,9);
  IMU_Delta_Index : constant array (1 .. 2) of Integer := (2,13);     
  procedure ApplyIMURotation(i : Integer;xf : in out Float; yf : in out Float) is
  begin
     if i in IMU_Alpha_Index'range then
        null; -- we don't change
     elsif i in IMU_Beta_index'range then
        xf := -xf;
        yf := -yf;
     elsif i in IMU_Gamma_Index'range then
        xf := yf;
        yf := xf;
     elsif i in IMU_Delta_Index'range then
        xf := -yf;
        yf := -xf;
     elsif i = 8 then
        xf := Sqrt2*(-yf + xf);
        yf := Sqrt2*(yf + xf);
     elsif i = 6 then
        xf := Sqrt2*(-yf - xf);
        yf := Sqrt2*(-yf + xf);
     elsif i = 10 then
        xf := Sqrt2*(yf + xf);
        yf := Sqrt2*(yf - xf);
     elsif i = 12 then
        xf := Sqrt2*(yf - xf);
        yf := Sqrt2*(-yf - xf);
     end if;
  end;  

4 j" n7 K; D" o; `
3 w, z$ f) h0 u, B- d2 O9 c! e& v1 Y

7 |5 A" }1 y: C( C- d: ]  K- f
使用范围:
IMU的范围不同。每组IMU都有一个特定的范围:
41.jpg
IMU分布,范围和名称
, z5 V# n- {& S$ t
配置中使用的范围使用以下代码计算:
  g7 a# E2 Q* m; ^% H$ W+ f$ J
--------------------------% \% R7 V1 R2 `
  -- Get the range to use --* |  H) b! n8 B
  --------------------------; Z) K3 S0 ]# r' m" V) l; n
  Range_3G_Index : constant array (1 .. 5) of Integer := (1,3,4,5,2);
" S8 e, s7 M; c2 S3 [4 u  Range_6G_Index : constant array (1 .. 4) of Integer := (8,6,12,10);- v" `+ f. }5 y/ {
  Range_12G_Index : constant array (1 .. 2) of Integer := (9,13);0 j4 f" G8 @% P
  Range_24G_Index : constant array (1 .. 2) of Integer := (7,11);4 Y: {( s$ X$ T  l
  function GetAccelRangeConf(i : Integer) return Accel_Range is! q) F4 q% A& `! y; }; M
  begin
+ F# k- P9 l5 f/ J     if i in Range_3G_Index'Range then
. ]8 b2 h. g+ |% T; F9 `        return ACCEL_RANGE_3G;/ P6 L6 h& X6 D
     elsif i in Range_6G_Index'Range then
- D& s5 L# O5 y8 j8 z        return ACCEL_RANGE_6G;7 u$ _' u" a* q
     elsif i in Range_12G_Index'Range then% y3 c, |2 ]2 d: j9 X
        return ACCEL_RANGE_12G;
- L1 P( }( e) [* ^. D- y. u+ x     elsif i in Range_24G_Index'Range then
* p9 n( y$ L$ J( \        return ACCEL_RANGE_24G;4 ~* h. X' N. b, f
     else- G4 o* K4 o5 i' O. W
        return ACCEL_RANGE_24G;  [+ q; _6 u9 ^6 [! `
     end if;# V$ t6 t4 E/ D0 _) D. `1 e' \" b
  end;8 l, P8 l. g' u& f! l
  Range_125DPS_Index : constant array (1 .. 5) of Integer := (1,3,4,5,2);
0 ]7 E  n$ S0 Y, e  Range_500DPS_Index : constant array (1 .. 4) of Integer := (8,6,12,10);& v* O9 D7 P/ ~6 J" k) `( {. P
  Range_1000DPS_Index : constant array (1 .. 2) of Integer := (9,13);% Y8 m5 V  B8 X0 e1 J" k; B. n
  Range_2000DPS_Index : constant array (1 .. 2) of Integer := (7,11);
  S9 u- S$ k* A4 M% d/ i  function GetGyroRangeConf(i : Integer) return Gyro_Range is* I: S: ?/ E( a- B+ i
  begin
! d$ ^6 |( c+ i, u# G     if i in Range_125DPS_Index'Range then& T7 N: z% O$ {4 }1 h
        return GYRO_RANGE_125DPS;
' N* z+ {" h  }1 ?) D" b0 J5 |: l     elsif i in Range_500DPS_Index'Range then
# q9 I/ F* A+ `  A# y) M        return GYRO_RANGE_500DPS;
& P' y8 K6 I9 O& F     elsif i in Range_1000DPS_Index'Range then
: \" {, Q  y# k8 Z6 k! `' _, W        return GYRO_RANGE_1000DPS;) Z( D/ E+ @( B
     elsif i in Range_2000DPS_Index'Range then
- y- k* w1 ]2 y, u/ H) c* ?        return GYRO_RANGE_2000DPS;$ E& g5 t6 A1 g) `% C0 b
     else
" ^7 n3 Q# {% G5 Y        return GYRO_RANGE_500DPS;
7 L# h' D& B0 |6 S, G     end if;        4 \3 ]3 T: I) c: C
  end;
- O. S. }5 {7 O8 f( m( y+ q2 t; c6 Y; b. s$ T9 G

( U. o$ w1 b! C+ P5 I7 O) L
过滤代码:
根据每个IMU的配置范围对加速度和陀螺仪速率进行滤波。
权重使用以下代码计算:

; |) E1 ~) h( o( B3 U6 N% e+ k% |
-- IMUs filter, filters the Gyro/Accel according to the range# m% f4 {1 e/ s, e! v
  function GetAccelWeight(rng : Accel_Range; val : Sensor_Accel_Data) return Float is  q) e2 u* y/ o) P
     weight : Float := 0.0;5 ~. o3 R4 m- T3 |
     refaccel : Float := 3.0;6 a( M% o* L9 i0 l2 }: _3 `3 j( u$ O
     refrange : Float := 3.0;9 }& @( t! J# L( }  r, A# c  q
  begin
$ A+ G* U& B- T  @9 A4 M1 k     if ((abs(val(X))<3.0*0.95*G and abs(val(Y))<3.0*0.95*G and abs(val(Z))<3.0*0.95*G)) then4 c# D5 G* L( `+ A" @; {
        refaccel := 3.0;
1 R( |. t- A8 d' S1 ]6 N     elsif ((abs(val(X))<6.0*0.95*G and abs(val(Y))<6.0*0.95*G and abs(val(Z))<6.0*0.95*G)) then7 k! j5 U/ x- O
        refaccel := 6.0;8 Y* J+ N; A- ^4 m8 T3 o
     elsif ((abs(val(X))<12.0*0.95*G and abs(val(Y))<12.0*0.95*G and abs(val(Z))<12.0*0.95*G)) then# f+ u& P) u4 g3 d
        refaccel := 12.0;" H$ l" q+ E# u4 W* f
     elsif ((abs(val(X))<24.0*0.95*G and abs(val(Y))<24.0*0.95*G and abs(val(Z))<24.0*0.95*G)) then
# i3 Z# T- M* [' c( W0 D3 z& m* e! d. T        refaccel := 24.0;( f6 Z) ]8 d; C* [
     end if;' R% h) Y# B+ e0 K0 L% ]9 i) a
     if rng = ACCEL_RANGE_3G then5 D0 ~% D( T  W3 O0 B5 q6 O
        refrange := 3.0;. ?% v  \2 d" o4 l
     elsif rng = ACCEL_RANGE_6G then9 B8 Y$ z) y/ H: g! s
        refrange := 6.0;: {1 C; R  N" x+ Z0 q
     elsif rng = ACCEL_RANGE_12G then% n$ L9 l8 I2 `$ b* V
        refrange := 12.0;* M1 g$ X0 q4 y
     elsif rng = ACCEL_RANGE_24G then1 H" {: K' k' U+ [1 r
        refrange := 24.0;
' Z: Z4 W& _' X     end if;
# g7 J1 ]) m( A; l/ {" v     weight := refaccel / refrange;" W4 R2 u: {- X/ o
     if weight > 1.0 then6 v3 w. z, l! r
        return 0.0;
" T; `8 _- k& u. [1 A" }. L     end if;
/ [* H: N) b5 @     return refaccel/refrange;; `- k- g+ }) y
  end GetAccelWeight;3 K/ Z) j' L7 ^' |0 e1 ^3 ^! ?
function GetGyroWeight(rng : Gyro_Range; val : Sensor_Gyro_Data) return Float is3 y5 f. Z  j* j* t. g
     weight : Float := 0.0;
& N4 v1 T  v# H. o     refgyr : Float := 125.0;( H2 |. |2 l+ h# X* N* y) X# r* ?
     refrange : Float := 125.0;- a6 G$ B" s) ]  P; y
  begin; X2 Z& U+ {; `, C! J
     if ((abs(val(X))<125.0*0.95 and abs(val(Y))<125.0*0.95 and abs(val(Z))<125.0*0.95)) then1 p$ k& r  b, T. _
        refgyr := 125.0;
! _8 }# Y0 R9 P: t7 n5 Q: E     elsif ((abs(val(X))<250.0*0.95 and abs(val(Y))<250.0*0.95 and abs(val(Z))<250.0*0.95)) then0 |1 G' B; G3 ~1 y
        refgyr := 250.0;/ I- _' n+ s; ?$ j+ ]! J6 y9 n" v
     elsif ((abs(val(X))<500.0*0.95 and abs(val(Y))<500.0*0.95 and abs(val(Z))<500.0*0.95)) then
/ `8 B6 Z* P: ]* b0 A% l9 Z        refgyr := 500.0;8 e, Z+ F* |1 [$ }
     elsif ((abs(val(X))<1000.0*0.95 and abs(val(Y))<1000.0*0.95 and abs(val(Z))<1000.0*0.95)) then
4 ]: _5 x8 C$ n+ r0 L; R+ {/ l        refgyr := 1000.0;
, t7 O3 b) X& E, Q; o  I     elsif ((abs(val(X))<2000.0*0.95 and abs(val(Y))<2000.0*0.95 and abs(val(Z))<2000.0*0.95)) then
! h8 ?) M% E+ m. @3 z3 H6 g. Y5 m        refgyr := 2000.0;
: y; \- c. i$ G# `0 c. V4 ^3 K" v     end if;6 \) i1 F" l- `. B  z
     if rng = GYRO_RANGE_125DPS then
1 k1 C! a! y8 H! {, a& D        refrange := 125.0;; {& ?% j  D, K0 u) I; W, w9 y) E
     elsif rng = GYRO_RANGE_250DPS then
, b4 G( Y! |2 w' ?0 i- _  A4 R        refrange := 250.0;
) s7 ]) v7 `2 I: H     elsif rng = GYRO_RANGE_500DPS then
" ~3 k" o: [. ]        refrange := 500.0;
! M$ G# D5 _+ K. [0 D$ g     elsif rng = GYRO_RANGE_250DPS then3 n) E8 t: H* y; }+ Y: ^3 G
        refrange := 1000.0;- P: C' O0 ?- D# F
     elsif rng = GYRO_RANGE_125DPS then
* f6 r) }3 g/ n" s        refrange := 2000.0;  I, k+ w' T9 J
     end if;  d2 q. x/ R" A" q% y8 _
     weight := refgyr / refrange;" o% Z8 k) z% d: U5 h6 k5 E
     if weight > 1.0 then
! [* I# j8 P( e# I' [2 A9 M) k        return 0.0;
* {; c3 T/ A7 ^2 x2 _) v! S     end if;
, ]/ U6 p$ X' e2 Z4 v     return refgyr/refrange;8 e) A! P( h  z' o1 M
  end GetGyroWeight;
- q7 L! f8 ]: v0 g4 H
" [& n# v4 E8 h1 n2 g' A2 D8 R- e7 ^; e! O( ^( [
使用权重,加速度值是所有值的加权平均值:
procedure FilterSuperIMU(facc   : out Sensor_Accel_Data;8 }1 [* _: x) w* z
                           fgyr   : out Sensor_Gyro_Data) is1 F' w* }$ N/ R0 \% {5 O: L& P) ]! J; N
     sumacc  : Sensor_Accel_Data;  -- cumulated accel value: \7 \9 `& |' Q! l
     sumgyr  : Sensor_Gyro_Data;  -- cumulated gyro value
6 y2 J% C  ^% |. z     sumwacc : Float := 0.0;  -- cumulated accel weight
) S2 K( v, U( f" ~5 b     sumwgyr : Float := 0.0;  -- cumulated accel weight) H7 y! j+ [1 W; ~
     macc    : Sensor_Accel_Data;  -- measured accel value. |7 R5 s8 P: F" s/ u
     mgyr    : Sensor_Gyro_Data;  -- measured accel value
% w  E: {: r+ \; l+ L* P) f6 ^" g- ]     mwacc   : Float := 0.0;  -- measured accel weight
. A( U# t$ Q1 I% I& k1 G: q- R     mwgyr   : Float := 0.0;  -- measured accel weight7 v2 z) c. d, L7 P! v) f
  begin, g; H( ^7 O6 l" E7 R1 I
     sumacc := NullAccelRate;$ F" n/ r4 W: g  L$ p
     sumgyr := NullGyroRate;
# o- }# h4 n2 U5 |     for i in Integer range 1 .. BMIs'Length loop         1 m2 d; j# K  `1 ]8 |
        -- get accelerartion
8 j* P  H7 r, n" X: L# Z9 [6 m5 s1 C        BMIs(i).ReadAccelRates(macc);* r3 j( Q9 M3 ]- q5 ^! |, s; r5 W" p
        -- get weight according to the range
& M! H; b: G1 b) f5 s        mwacc := GetAccelWeight(BMIs(i).GetCurrentAccelRange, macc);$ Y# ]+ j) r) H# R: Z- x, N  [
        -- apply 45° and inversion tranformation (geometry of the IMU)
/ ~$ I. U, @  C6 y        ApplyIMURotation(i,macc(X),macc(Y));
4 P$ p' S4 d, u  R0 l( Q        -- update the cumulated sum) U& P3 f8 s8 g+ R  b" i+ D/ i
        sumacc(X) := sumacc(X) + macc(X)*mwacc;
1 [9 `( t/ x, u/ X+ x        sumacc(Y) := sumacc(Y) + macc(Y)*mwacc;) i7 K; i0 D* ~5 y
        sumacc(Z) := sumacc(Z) + macc(Z)*mwacc;/ D. z+ g- r* i( Q
        sumwacc := sumwacc + mwacc;
1 o2 S) L: G. T        -- get the gyro rate, S; h* i9 j+ q" d& J; Z0 {  r
        -- we don't rotate the gyro rate, no need7 P; }1 x  ~) A% K) Z
        BMIs(i).ReadGyroRates(mgyr);
, C) [. [( Y; e        -- compute the weight according to the range" h  t7 J: h+ \9 A7 j$ |
        mwgyr := GetGyroWeight(BMIs(i).GetCurrentGyroRange, mgyr);% C. G* y+ t! M; `
        -- update the cummulated weighted sum
# M# N) B6 }( g- x: {        sumgyr(X) := sumgyr(X) + mgyr(X)*mwgyr;4 d0 |. W2 X# d; m3 Y  j& s
        sumgyr(Y) := sumgyr(Y) + mgyr(Y)*mwgyr;4 w* r; `6 K5 F9 _- s& C
        sumgyr(Z) := sumgyr(Z) + mgyr(Z)*mwgyr;
9 e( a& E( a% \" W3 x        -- . f3 r! O5 c# u1 I
        sumwgyr := sumwgyr + mwgyr;' w3 O( C9 P$ M6 y: L
     end loop;
4 q; H" L$ ~8 Y) E     facc(X) := sumacc(X) / sumwacc;
% m4 }5 g9 e& a7 ^+ I& \% u     facc(Y) := sumacc(Y) / sumwacc;; R8 k' w4 K6 _- t
     facc(Z) := sumacc(Z) / sumwacc;
. F( u, e7 ^  y- A     fgyr(X) := sumgyr(X) / sumwgyr;/ Y5 T7 V% x5 |& x8 c$ Q7 y5 h1 q7 \
     fgyr(Y) := sumgyr(Y) / sumwgyr;
0 Y# p* _3 h2 C2 v  N/ K1 ^     fgyr(Z) := sumgyr(Z) / sumwgyr;, y) |# N* U" U+ {. y2 |; E
  end FilterSuperIMU;
6 P. o4 m+ J" k
  Z$ x4 J5 Z- q0 n5 p, X0 G; M9 {% x1 p: u2 s  P
估算代码:
我用一个简单的互补滤波器来估算音高和滚动。我们从IMU获得加速度和陀螺仪速率数据。
代码在这里:

5 R  \0 T7 \" m
procedure ComplementaryFilter(accelData : Sensor_Accel_Data; gyroData : Sensor_Gyro_Data) is
     pitchAccel : Float := 0.0; -- pitch computed from the accel
     rollAccel  : Float := 0.0; -- roll computed from the accel
  begin
     -- integrate the gyroscope data
     estimatedPitch := estimatedPitch + gyroData(X)*dt;
     estimatedRoll := estimatedRoll + gyroData(Y)*dt;
     -- compensate the drift using the acceleration
     pitchAccel := Ada.Numerics.Elementary_Functions.Arctan(accelData(Y),accelData(Z))*RadToDeg;
     estimatedPitch :=  estimatedPitch * 0.98 + pitchAccel * 0.02;
     rollAccel := Ada.Numerics.Elementary_Functions.Arctan(accelData(X),accelData(Z))*RadToDeg;
     estimatedRoll := estimatedRoll * 0.98 + rollAccel * 0.02;
     null;
  end ComplementaryFilter;
2 W. ^7 L$ h# E1 s
第7步:退役
使用OpenOCD
您也可以使用st-util,我已经在其他项目中完成了openocd的工作,这就是我使用它的原因。
重要(3小时获取时间评论)你需要在sudo模式下运行gnat gps,否则openocd无法访问usb端口。
安装OpenOCD
在ubuntu上使用OpenOCD的最佳方法是构建它。这样你就拥有了最新版本。我使用了gnu-mcu-eclipse/ openocd的最新版OpenOCD 。
要构建它很简单,只需确保安装了通用的C / C ++构建工具:
you need to install libusb dev v1.0 then# ./configure --enable-stlink # make # sudo make install  - ]- M* I; g% [* R: A  H- _# @
用于OpenOCD的配置:
- 本地主机的端口为3333
- 我使用了来自openocd github 的stm32f 74discovery的配置文件。
42.jpg
用于OpenOCD的配置
  H  K' ?9 _' r
使用带有Analyzer2goCYUSB3KIT-003SPI进行分配
Analyzer2Go只是一个用于小预算的神奇工具。结合电路板CYUSB3KIT-003(45 $),您可以在200MHz采样率下使用功能强大的16x通道分析仪!
对于我的情况,与SPI / UART的交换低于10Mhz,并且读取Nucleo板的MCO(在100MHz下的PLL),这就足够了。
SPI测试
SPI的速度配置为STM32F746的6MHz(波特率DIV 32)。
我可以使用来自BMI088实例的SPI使用以下过程正确获取IMU运动数据:
( |8 ?2 K5 u3 I# W) d
  procedure ReadAccelRates (This : in out Six_Axis_Imu;                            Result   : out Sensor_Accel_Data);- D' Y2 X- I5 C$ w' R
  procedure ReadGyroRates (This : in out Six_Axis_Imu;
% L* R9 e4 U2 ^6 B" z2 h3 R/ V                            Result   : out Sensor_Gyro_Data);2 ]& W% C* @* ^1 i
0 W& z' I( w' x
0 u1 H5 j! }- d' c. g
第8步:PLL时钟测试:+ Z) p$ c/ A1 F; p

1 q  s0 A  j6 k5 q& j5 o% W2 ]
9 X- n6 h, B7 |1 v/ i
在核板中,外部高速时钟(HSE)不是来自25MHz晶体(如Adacore内置STM32F746Disco),而是来自ST-Link芯片@ 8MHz。" e9 O3 q( v5 p% E
经过数小时的调试后,我最终修改了adl_config.ads和s-bbbopa.ads(作为workarround)文件以设置HSE时钟的正确值。我终于为Nucleo-F746创建了一个新的BSP,而不是因为这种差异而使用stm32f746disco。
) \. ?# T( y) H8 g! u/ D现在时钟正常运行,测量显示时间:
3 L8 I( I* n- [9 V在调试模式下读取加速值需要35us 。1 q: n+ o9 V. s& V
8 |+ c7 q9 B6 h9 K0 \3 C+ m; g
6 a9 J* u( H  m$ p; _* F
43.jpg
  A6 A4 A2 ]: z5 Y6 q3 M" o/ b' j
在从IMU读取值结束时,我使用流动代码切换引脚PG1:

  ~9 I+ R9 V/ J( T' g7 H; q' R$ ?
  --------------------
/ E2 U$ A; K# D" x7 i5 y  -- ReadAccelRates --- b# \% v/ u- B! }0 M
  --------------------
4 y9 T& k: p0 K/ b' C$ z  procedure ReadAccelRates (This : in out Six_Axis_Imu;
6 D  m' k" v& E0 A2 x& |                            Result   : out Sensor_Data)
( h2 B" N) b7 H) G& J9 V- g) [' n  is
6 \& s9 f7 w" u9 q8 e+ f. f# A     Received        : SPI_Data_8b (1 .. 6); -- 2 bytes per axis
3 H: _+ y6 x( V' z6 T     AccelRates : BMI088.IMU_Rates;-- todo create AccelRate type1 Y( |* ]% M% Z5 L( p
  begin
- ~. i) E/ `. W0 O7 u7 Z     PG1.Set;. M: L  k1 g5 N* ^( W+ m
     This.AccelRead_UInt8s(ACC_ACCEL_DATA_ADDR,Received,6);( }( [8 B7 a7 U  [( ]
     AccelRates.X := As_IMU_Rates_Pointer (Received (1)'Address).all;
$ p) ~, B* [' I+ b( b  k9 ?$ y     AccelRates.Y := As_IMU_Rates_Pointer (Received (3)'Address).all;( K0 A( a) I' ^+ T: v
     AccelRates.Z := As_IMU_Rates_Pointer (Received (5)'Address).all;
# i# u" r9 i' k; l4 m# [/ a  @     Result(X) := Float (AccelRates.X) / 32768.0 * Accel_Range_MSS;
: g+ s! V  A" Z. z& W6 u& x     Result(Y) := Float (AccelRates.Y) / 32768.0 * Accel_Range_MSS;
/ x: A2 @- G$ T, t0 U- V     Result(Z) := Float (AccelRates.Z) / 32768.0 * Accel_Range_MSS;0 a* T( j) H  f  i$ F3 K( f& T; s
     PG1.Clear;1 `5 N# p! R. L" R5 u
  end ReadAccelRates;% u3 u- ]% v" _6 ]9 G

$ x3 t! p2 g, \5 \1 g. z
Reading在调试模式下,完整的陀螺仪值需要34us
44.jpg

$ U* P8 x1 e, F1 b4 E0 ^: Q) u7 M9 f
   -------------------
- t$ t" m4 p1 |& H- M  -- ReadGyroRates --8 e) A6 j2 R/ K3 e7 w8 v
  -------------------
/ \5 z& I! t- j, p& Y. [  procedure ReadGyroRates (This : in out Six_Axis_Imu;5 ]1 |3 c7 Q9 C' o7 z
                            Result   : out Sensor_Data)
* V1 f" N, e- V( v  is
; Z) `$ f; H# |" a5 D# Q     Received        : SPI_Data_8b (1 .. 6); -- 2 bytes per axis0 |- G- I8 c& }- M$ }
     GyroRates : BMI088.IMU_Rates;-- todo create AccelRate type8 |" J! @0 K4 n  H
  begin
' T  |0 C9 J$ b  A- C1 {7 xPG1.Set;
1 t& u5 e# ?( t     This.AccelRead_UInt8s(ACC_ACCEL_DATA_ADDR,Received,6);
+ K. f2 x9 J( X* c2 r2 k9 E     GyroRates.X := As_IMU_Rates_Pointer (Received (1)'Address).all;, h8 P  M5 O2 {! r6 C9 U6 K
     GyroRates.Y := As_IMU_Rates_Pointer (Received (3)'Address).all;
; p$ E6 a! o9 ]# S  B* a     GyroRates.Z := As_IMU_Rates_Pointer (Received (5)'Address).all;
, ~3 {, L  h4 j1 a/ W) ]7 v     Result(X) := Float (GyroRates.X) / 32768.0 * Gyro_Range_Rads;* ^1 B" z& V5 Q1 J* }
     Result(Y) := Float (GyroRates.Y) / 32768.0 * Gyro_Range_Rads;' o( [% m5 i/ e& O7 @! a
     Result(Z) := Float (GyroRates.Z) / 32768.0 * Gyro_Range_Rads;% b' _! `& ~1 H1 p
PG1.Clear;
# m9 L" ]; q$ {8 Z# C8 h) P5 d  end ReadGyroRates;
8 p$ [6 z+ J/ F6 s" L8 F. h4 C5 P: J: s1 X) X* k' t
Of 对于真实用例,我需要将编译模式设置为生产以进行正确的优化。

0 u' X* |: Y' {$ s& `* `) c9 j
步骤9:使用UART绘制数据
为了可视化输出数据,我想使用UART在超级惊人的酷系列绘图仪中可视化它:https://github.com/CieNTi/serial_port_plotter
45.png
" O3 y" g* \4 j5 i7 {" R) P
现在的问题是将Float转换为String ..以使用UART将其发送到Serial_Port_Plotter工具。
为此,我在这里使用神奇的单词'Img in Ada 将Float转换为String。然后我逐字节地将字符串发送到UART。
如果要发送一个值:
( t9 a  c8 R$ J2 ~# u0 a' ]- 发送“$”
. K) R( d  |' \! f+ ^- 发送浮点值' P& S1 D  b" R9 G
- 发送“;”
如果你想发送多个值:# I( `$ X/ G. g; ]
- 发送“$”开始& g7 k9 r9 x$ D) _7 _1 P
- 发送浮点数值1
. m; z! [: r( D- 发送空格“”
1 m  L& }# h( d, Z( T...
5 K3 h  V8 B8 X, u$ H2 I$ u1 [- 发送浮点值i 9 w/ m3 ?& f- A8 ]" @
- 发送空格“” ! E7 V$ _  [( d6 G; S4 N
- 发送“;” 终止
6 L& Y$ k' @  X7 I7 F1 p
为了能够向绘图仪发送加速度,我使用了以下代码:
1 o% Z/ j$ b4 f  w. f% s* A
  type FixedFloat is delta 0.00001 digits 18;---
% o* C/ p9 [" J$ ^8 E% Z     data_1B(0) := UInt8(36); -- '$'6 w: s! _7 x( p* }$ P' t
     UART_OUT.Transmit(data_1B,status);
/ P% S2 ^. b9 N) ^1 A1 l     for ch of FixedFloat(AccelRates(X))'Img loop. F. V. d  e5 h3 l$ e( F
        c := Character(ch);: b/ m7 \9 _7 C5 T. R
        data_1B(0) := Character'Pos(c);& I$ {: y+ P. p$ J4 ~; T
        UART_OUT.Transmit(data_1B,status);" l6 O8 K$ B  W: S: [, Y/ R* n
     end loop;
" A- T8 u6 b% S4 m( N1 Z4 r; Y) Q     data_1B(0) := UInt8(59); -- ';'( `; V. d9 e  B4 J9 p% m; B
     UART_OUT.Transmit(data_1B,status);
1 N4 u  E- v+ c
6 z3 l" @* I) }( z
* q& {5 G# w% x
结果非常令人满意,在下面的快照中我实时可视化Accelerometer(X)值:
46.jpg
' f* h* l% c  ~6 D3 D9 `2 v) ^
创建驱动程序后,该数据通过UART端口正确发送:
47.jpg
$ J# P7 U( ~9 }  c+ L4 D6 u# n/ h
UART制作驱动程序
不幸的是,在STM32F7器件中还没有UART驱动器(仅适用于STM32F4)。
要为UART创建驱动程序,我从STM32 F4 的stm32-usarts.ads/adb开始。我修改了文件以符合STM32 F7 的SVD 。我还要修改STM32-Device.ads/adb以包含STM32F7的UART / USART定义。
它适用于传输9或8位大小的字节。我没有测试它的DMA风格(因为从未做过
7 ]0 S+ u7 P$ ?6 d+ Y
代码广告:
------------------------------------------------------------------------------
7 i5 s5 P8 P( T9 m: M' h. Z2 q--                                                                          --) T9 b3 ^; Y9 [
--                  Copyright (C) 2015-2016, AdaCore                        --- L/ u6 ~2 }6 _& \! u/ m) e
--                                                                          --
4 K* P8 A# E! E" Q( `% ?* N2 d' c8 L--  Redistribution and use in source and binary forms, with or without      --
9 a- G7 @5 V$ h--  modification, are permitted provided that the following conditions are  --% j" T0 J7 p" @0 `
--  met:                                                                    --* n- f" ^$ G( `
--     1. Redistributions of source code must retain the above copyright    --9 C9 h# m$ [" ]
--        notice, this list of conditions and the following disclaimer.     --
: f% j4 b8 s+ R  v! u$ M3 _8 k--     2. Redistributions in binary form must reproduce the above copyright --
1 p. U0 s( Z6 T% O& s% @3 p--        notice, this list of conditions and the following disclaimer in   --
  v0 {$ H' u1 y) U0 Z6 F--        the documentation and/or other materials provided with the        --
2 p5 P: \; {, l* ]% E4 ~--        distribution.                                                     --
' ]/ T/ _; C+ G  ]+ P--     3. Neither the name of STMicroelectronics nor the names of its       --
6 P9 ~, T3 W+ ?/ J/ d3 Z8 v. {' H# B--        contributors may be used to endorse or promote products derived   --, v6 A* d  _4 Z. h- N+ L
--        from this software without specific prior written permission.     --
$ [8 }  q# ?" |--                                                                          --
. A+ F, q5 h9 ?--   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    --6 R4 n+ {* c" S1 F
--   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      --4 e% L, F* w3 @8 @& O2 [2 H
--   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  --. K1 d7 r3 F0 r5 j# _# q0 y
--   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   --- P3 R% o) `* s' F9 T( [% V7 M
--   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
, N% N% {* `2 x' |0 |' a--   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       --1 ]1 Q  v) Y: `5 Z* }$ b
--   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  --
8 h; p9 b8 W& A! w8 \' |--   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  --
: }  R, R! U! w, ^$ r--   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    --
$ ]3 w% S6 P7 b+ _6 c--   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  --
7 V7 {) C6 P, Y# R" \--   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   --
" _  G! C- W' a/ |8 t--                                                                          --
+ T" e% V% F6 Q+ w--                                                                          --1 p; a# _( K4 N5 v4 [0 B. \  w8 O
--  This file is based on:                                                  --2 u; N4 x) X$ p7 l; r4 P5 x
--                                                                          --7 _& I. e/ R- x- {2 V$ g+ J
--   @file    stm32f4xx_hal_usart.h                                         --- C( o& y% D. y8 O2 @7 t* r5 ^8 A
--   @author  MCD Application Team                                          --( e9 I4 J, o2 n/ \
--   @version V1.1.0                                                        --
6 h2 v- X8 E6 z  M6 |--   @date    19-June-2014                                                  --
1 V" Q% T) _" I, @3 R# S--   @brief   Header file of USARTS HAL module.                             --( M0 m  i6 f; P# W. X. l, \
--                                                                          --
; F$ V6 o" G, h8 t--   COPYRIGHT(c) 2014 STMicroelectronics                                   --0 `! R6 {; h* P  f8 B8 w( k
------------------------------------------------------------------------------
- Y9 j7 P6 S" [5 a6 Z  H, B--  This file provides register definitions for the STM32F4 (ARM Cortex M4F)) e( R: ?! N+ s2 y! q
--  USART from ST Microelectronics.
8 A5 {. A. q0 E# |. O--  Note that there are board implementation assumptions represented by the
9 Q0 Y9 B+ u: g! D8 y* c/ O--  private function APB_Clock.
( H1 r/ g$ p, n4 a% D9 _  b  M3 Uwith System;
! \: v8 S. k& K7 w* e2 |9 Bwith HAL.UART; use HAL.UART;) x9 e3 j5 l4 S0 c1 w: u
private with STM32_SVD.USART;9 m! {& e; k7 A* t: O9 |
package STM32.USARTs is
: X) J7 s7 }: w$ \  type Internal_USART is limited private;
( B% d* K8 l; [8 k* d  type USART (Periph : not null access Internal_USART) is
3 _( c! n. M& F5 d7 _+ b/ v    limited new HAL.UART.UART_Port with private;9 G8 j9 T9 n/ k5 h4 `; k8 `
  procedure Enable (This : in out USART) with
3 \" @0 w5 R* x* @7 o4 \9 {9 x    Post => Enabled (This),
' ]! x- R! f3 y) ~" f2 H5 k    Inline;8 x; C/ P# C; t9 w- O+ r
  procedure Disable (This : in out USART) with4 R' ?4 t$ S* i" z
    Post => not Enabled (This),
. c# h1 H( ^) ~7 k1 a/ n    Inline;# d. I  N, X% m( t# U
  function Enabled (This : USART) return Boolean with Inline;
. X0 P" K# y' g; b( M& n2 K7 |& f  procedure Receive (This : USART;  Data : out UInt9) with Inline;
/ U. W$ g' q) h1 T* f9 l  --  reads Device.DR into Data; X9 I3 l) m; @9 N- {
  function Current_Input (This : USART) return UInt9 with Inline;" e% J/ ^5 M7 M$ W# y! t
  --  returns Device.DR
' y; m0 g2 E+ [  i3 u) O# y  procedure Transmit (This : in out USART;  Data : UInt9) with Inline;8 e; F9 W% g. Y! g
  function Tx_Ready (This : USART) return Boolean with Inline;
- ~& O/ f& V: \0 }0 N  function Rx_Ready (This : USART) return Boolean with Inline;( ^" q: O$ Z  e/ o
  type Stop_Bits is (Stopbits_1, Stopbits_2) with Size => 2;3 [' a' `! ^) u2 \, X+ x5 a
  for Stop_Bits use (Stopbits_1 => 0, Stopbits_2 => 2#10#);
6 C2 g# V4 b0 |2 h) m  procedure Set_Stop_Bits (This : in out USART;  To : Stop_Bits);
; q8 y5 T9 O, ~6 Q% r! u  type Word_Lengths is (Word_Length_8, Word_Length_9);
; L8 \, M# l; o* D  procedure Set_Word_Length (This : in out USART;  To : Word_Lengths);8 m3 K! S/ ~; M  q' i& ^
  type Parities is (No_Parity, Even_Parity, Odd_Parity);2 e) |5 n5 K4 K$ T. f
  procedure Set_Parity (This : in out USART;  To : Parities);
+ H8 l, ^+ l3 D. A8 F* A, ?  subtype Baud_Rates is UInt32;
# Z) Y, w' C' |5 X2 D) p4 t  procedure Set_Baud_Rate (This : in out USART;  To : Baud_Rates);' }6 a/ N6 E& b. x* X% _. o
  type Oversampling_Modes is (Oversampling_By_8, Oversampling_By_16);
: {" f, j4 S* T! X: P7 g8 }8 b( w  --  oversampling by 16 is the default) a+ j, F% d$ g5 D% A7 i' r
  procedure Set_Oversampling_Mode
3 X" S# @: M2 ~$ A0 x3 o) E: q    (This : in out USART;' I( }4 z' _. c6 ^: g0 q
     To   : Oversampling_Modes);3 e# ~* W, K4 o8 S( u" S
  type UART_Modes is (Rx_Mode, Tx_Mode, Tx_Rx_Mode);
% b# z5 N/ k/ d1 T8 b3 k* [" _6 ?4 w  procedure Set_Mode (This : in out USART;  To : UART_Modes);* W7 |6 M3 _( E# ^  r5 {# Q. E7 p
  type Flow_Control is
# l: V. |! ]) y    (No_Flow_Control,
" W9 o+ C; C1 V# ?* J     RTS_Flow_Control,
# c9 n2 z+ B. I! r1 x! L' L     CTS_Flow_Control,6 m% r7 F; e  _0 U4 i
     RTS_CTS_Flow_Control);
5 n" w' v: Z/ ^) n: K) z  procedure Set_Flow_Control (This : in out USART;  To : Flow_Control);8 M, `: Z1 c: R/ A  u
  type USART_Interrupt is' r/ a; z3 o/ Z" S8 ~$ N( q
    (Parity_Error,& Q0 R) g% W7 n: v! J
     Transmit_Data_Register_Empty,
9 Q$ U4 d* l1 ^& w. P9 T5 a! h1 [     Transmission_Complete,
2 y3 ~& K5 p7 V! ]  \& \: u6 x     Received_Data_Not_Empty,
' K0 ], _; y2 y* A     Idle_Line_Detection,5 j" Y8 @% |& E0 [6 \
     Line_Break_Detection,: L1 N4 u! l& W! \
     Clear_To_Send,6 Z$ d# O. t8 Y7 W+ i4 t8 ^
     Error);9 }! }! t6 Q% G; _9 N" y4 ^4 j$ V
  procedure Enable_Interrupts. [+ ?& L2 f' `2 K: r+ B
    (This   : in out USART;9 ]; L6 t+ C' E+ k: N, {
     Source : USART_Interrupt)$ f6 S! D9 q9 N) n4 U1 p
    with4 V1 H# B& p  P1 f  T% v
      Post => Interrupt_Enabled (This, Source),
6 G: N$ v$ n! I      Inline;
. f+ r4 q8 e# m, `! ]7 w* [+ a4 F  procedure Disable_Interrupts
% w  ?& t% N( K, D$ m; Z    (This   : in out USART;' d5 F7 s) L% S
     Source : USART_Interrupt)
; i7 B/ g' A5 k$ ]  {: ^    with: `* Y, |2 W/ G* P- y( P+ T- S
      Post => not Interrupt_Enabled (This, Source),$ P7 |( C4 Y+ u; J4 r) }
       Inline;
; b! b) ^* Y* g4 A  function Interrupt_Enabled
0 F0 d* ~8 v5 P0 L& R    (This   : USART;
3 S6 ^6 J( ?$ K9 Z     Source : USART_Interrupt)/ C. ~# \, J0 }, s! B
     return Boolean* c+ Q4 D( U5 e8 n& l% h5 M/ G
    with Inline;
) `. d7 F- ?2 H1 p% `* L  type USART_Status_Flag is
8 q6 m& ?8 r! _4 c7 ?1 C    (Parity_Error_Indicated,, d( t* i! V, s% F' p) U4 H
     Framing_Error_Indicated,
5 I1 w% I; i/ r. V( C" \6 g     USART_Noise_Error_Indicated,
6 N! U/ ], z" _& g- `     Overrun_Error_Indicated,
  }1 C  k# z- j9 N9 @$ [4 s' _     Idle_Line_Detection_Indicated,
+ Q9 b: X1 e; r* H     Read_Data_Register_Not_Empty," x( l8 b! e0 S& i1 X2 T
     Transmission_Complete_Indicated,8 T, X9 ?! P/ _" L8 p0 K
     Transmit_Data_Register_Empty,
( l) }, n; B9 |  q& ^+ o0 l1 g% R     Line_Break_Detection_Indicated,5 L4 [: q- b5 X5 d
     Clear_To_Send_Indicated);1 z$ c; o* O+ }# C
  function Status (This : USART; Flag : USART_Status_Flag) return Boolean
% x& y/ _% p( W/ ~2 y; W    with Inline;
- n$ L) l( e! ?$ a6 R  procedure Clear_Status (This : in out USART; Flag : USART_Status_Flag)& M, H+ w/ N; O. J0 t" S+ o- |: C
    with Inline;
6 T8 V9 B3 X0 t% o  W  procedure Enable_DMA_Transmit_Requests (This : in out USART) with
, P; c$ g; V( ~8 j+ o3 q$ j) v    Inline,/ T* F9 t+ g3 ?. e4 M3 j, m
    Post => DMA_Transmit_Requests_Enabled (This);
5 |! u! R0 ]: _7 d2 [$ h5 {  procedure Disable_DMA_Transmit_Requests (This : in out USART) with7 u( V+ g3 C4 N) ~5 B
    Inline,
/ z. i: e$ S5 S/ ?' ]& R' t    Post => not DMA_Transmit_Requests_Enabled (This);- V9 o! `9 y( J4 i2 j" U
  function DMA_Transmit_Requests_Enabled  (This : USART) return Boolean with
( [; ^7 \: H! ]* J    Inline;- p1 v# W& P  r. {0 A! b8 f8 }4 W
  procedure Enable_DMA_Receive_Requests (This : in out USART) with$ G5 E  ^5 `- A, C
    Inline,6 @. r+ h+ y" @* A$ a3 ]  B
    Post => DMA_Receive_Requests_Enabled (This);: _# G' ~9 a) \2 K1 B
  procedure Disable_DMA_Receive_Requests (This : in out USART) with  o; x* M9 J" ~7 n9 B
    Inline,/ D4 M# u' f! _% ]
    Post => not DMA_Receive_Requests_Enabled (This);9 T+ i( q& }8 V1 z) n7 @. E
  function DMA_Receive_Requests_Enabled  (This : USART) return Boolean with
2 @( b& c- ^( f1 K# j) o  U- }    Inline;
/ q9 }, \( m% F3 |6 S  procedure Pause_DMA_Transmission (This : in out USART)
9 E1 @) g8 i9 k0 s    renames Disable_DMA_Transmit_Requests;
- b+ S* p$ p; g' j7 ]3 l  procedure Resume_DMA_Transmission (This : in out USART) with
( j) m2 b5 U8 P1 _: P    Inline,
- l7 A2 ?0 g) D  W# |; i7 o5 R    Post => DMA_Transmit_Requests_Enabled (This) and* H0 ^( A* u2 T
            Enabled (This);
+ c0 W- u+ e, r, |- f2 x* z  procedure Pause_DMA_Reception (This : in out USART)
3 `) ]8 f% L$ s9 ^$ n% s1 T  W    renames Disable_DMA_Receive_Requests;
4 R* k3 _( z9 U/ S5 I: G$ a4 _- ]  procedure Resume_DMA_Reception (This : in out USART) with
6 z% W4 z7 K1 @) G    Inline,
, _8 O# |# n6 B3 E9 T    Post => DMA_Receive_Requests_Enabled (This) and+ L% h$ d$ w" t0 F) s. d
            Enabled (This);
: y* ?/ q' G  O  function Data_Receive_Register_Address (This : USART) return System.Address with& T. @! b6 w0 P! L6 y" k
    Inline;
) B( U. `& m( c& @  P6 X5 x1 w6 A  function Data_Transmit_Register_Address (This : USART) return System.Address with+ V* ~% M7 D+ e
    Inline;  h% M# o# x9 Z" v$ h/ _
  --  Returns the address of the USART Data Register. This is exported- \& \4 ~/ P4 z2 y+ g6 |/ Y7 P
  --  STRICTLY for the sake of clients driving a USART via DMA. All other; _7 M$ h0 b+ [8 B
  --  clients of this package should use the procedural interfaces Transmit, ?) k* v8 {2 y; {" n/ @
  --  and Receive instead of directly accessing the Data Register!2 i' V) Z7 z2 P7 f) s0 o
  --  Seriously, don't use this function otherwise.% A! @5 |" H; G, x  S% {8 r& Z6 _
  -----------------------------) x" t- [  Q( m6 p! d2 p% {6 d6 J
  -- HAL.UART implementation --9 T* F3 J. ~( t) T) U/ t+ p
  -----------------------------
8 Y3 \( z; l8 e! T$ X/ ?: l9 S  overriding
& s7 T& ?3 o* [0 G: A! P9 X  function Data_Size (This : USART) return HAL.UART.UART_Data_Size;4 g; l+ }" L, o  y. O5 o3 B
  overriding
0 Q, h; n5 |4 k4 [- V  procedure Transmit
" o! E/ {0 W, M' o    (This    : in out USART;
$ O' M+ \, i: ?* P4 d9 l     Data    : UART_Data_8b;6 Z3 U* Y3 \. n5 k, J* A1 w9 v
     Status  : out UART_Status;
9 G; [% b  G8 y4 p/ Y) t/ k     Timeout : Natural := 1000)/ w( w: `8 ?9 q% M5 ]% v
    with
& q3 r) ^2 x, R      Pre'Class => Data_Size (This) = Data_Size_8b;6 C% J; z5 c& P6 p) Q! X: k0 s
  overriding, U) T6 w. g7 I9 `9 ]" i" c
  procedure Transmit
  ~" Q% K* M, Q& p- S8 Q0 G2 \9 C    (This    : in out USART;
; h2 [; t2 c1 v" V" r     Data    : UART_Data_9b;0 U+ D* {1 }- P/ j
     Status  : out UART_Status;
( I1 i. Z1 f6 r7 }5 H+ I     Timeout : Natural := 1000)% O/ C0 j& F% o7 t
    with& ^$ h$ |$ _' {7 Z
      Pre'Class => Data_Size (This) = Data_Size_9b;5 C! k/ O* b/ `0 t- g
  overriding
6 z/ v3 m; ~# K2 V0 W. u% E: y    (This    : in out USART;9 I" n7 p3 e; i0 W8 ^, k6 @. e4 C( \+ n
     Data    : out UART_Data_8b;
2 u4 H0 |- u3 ^- V0 ?     Status  : out UART_Status;, Z6 t0 J' N, F
     Timeout : Natural := 1000)
/ p$ A/ Y, x$ \! R3 B* S    with
  L' `6 D8 S9 }3 |* W" K- ]  @      Pre'Class => Data_Size (This) = Data_Size_8b;
. Z. o6 e# ^/ l' F4 p  overriding! L4 m/ n" @; q. h0 i5 d& {- V( u9 R
  procedure Receive
- W" K  B. D4 k- c- [    (This    : in out USART;
( M8 }" I1 C' l8 {: o$ i1 D     Data    : out UART_Data_9b;
  P' h, S3 A5 G1 U6 b. t     Status  : out UART_Status;
2 c, ^6 w5 @5 f; a& h     Timeout : Natural := 1000)
  j& [& N$ `, @# i    with
% ~( B" j: s$ d. X% P      Pre'Class => Data_Size (This) = Data_Size_9b;; i7 C6 [& s: b. z( o
private
6 W2 d) t/ r. w. M! K% O" t  function APB_Clock (This : USART) return UInt32 with Inline;
( A% J2 n" }7 |, D. }' n9 k" F  --  Returns either APB1 or APB2 clock rate, in Hertz, depending on the$ Z  ]# X# \  d: l
  --  USART. For the sake of not making this package board-specific, we assume
0 h, f# r  G8 G. e' t& f% J  --  that we are given a valid USART object at a valid address, AND that the
5 O# f+ {( `  u; f3 ?1 E+ H  --  USART devices really are configured such that only 1 and 6 are on APB2.6 E% }+ B5 V$ R: {6 L
  --  Therefore, if a board has additional USARTs beyond USART6, eg USART8 on
7 ]/ v) b  D. E; X, U" Y1 d4 c5 V  --  the F429I Discovery board, they better conform to that assumption.
' j% [0 E- d) ?7 H5 A  --  See Note # 2 in each of Tables 139-141 of the RM on pages 970 - 972.5 l! Y, |6 k; n6 M- P* v; y
  type Internal_USART is new STM32_SVD.USART.USART_Peripheral;5 V2 Q( H9 [: w; ?+ l
  type USART (Periph : not null access Internal_USART) is
6 b5 W$ t7 Z$ H) H    limited new HAL.UART.UART_Port with null record;
' D% g3 A. E& h2 b/ q8 D" y% mend STM32.USARTs;   m" Q1 r8 n8 b* w

3 }1 r4 u- |) y9 n/ ^9 G' L+ I
代码adb:
------------------------------------------------------------------------------
% `# o$ f4 M8 X+ C--                                                                          --3 [' h9 P) T$ Q) y1 S  |
--                  Copyright (C) 2015-2017, AdaCore                        --$ F1 E* |7 F6 u7 s
--                                                                          --
0 U) P. Y9 _3 M" n2 I. E& q--  Redistribution and use in source and binary forms, with or without      --
- B3 S% d1 ~& k! l--  modification, are permitted provided that the following conditions are  --4 z) [7 K" F! ^# m7 z/ d
--  met:                                                                    --
1 y* _4 M0 e7 l( c" @) ^--     1. Redistributions of source code must retain the above copyright    --( }6 \2 j, T, L% c# D* ?  t( Y
--        notice, this list of conditions and the following disclaimer.     --, A8 I# x+ I( ?# ?0 ?& x% Q
--     2. Redistributions in binary form must reproduce the above copyright --2 z1 c( ^) O  k; g6 X9 w: M4 P
--        notice, this list of conditions and the following disclaimer in   --0 C+ U9 Q$ K9 f
--        the documentation and/or other materials provided with the        --3 A7 `5 U+ b' N1 j0 d+ x, R
--        distribution.                                                     --
* m( e# d0 J+ {--     3. Neither the name of STMicroelectronics nor the names of its       --/ C) C5 O% ]8 P) b2 F
--        contributors may be used to endorse or promote products derived   --
  b5 u9 `2 L/ U7 C--        from this software without specific prior written permission.     --
6 P! `8 Y! b" O/ t6 f6 Y! v% B) j--                                                                          --. Q$ a; M6 O9 U; ^. d1 q. C
--   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    --; b9 J4 F, }1 B* m7 B
--   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      --8 ~" T7 t& H  D( \
--   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  --
8 Z5 h& U. P/ N/ _6 r- I1 V--   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   --) o: W# C; ~* F5 B, B( N
--   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --- I/ H% U$ F5 g. u
--   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       --
* T7 t/ s6 M+ ?4 ~& F: y+ f--   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  --
5 U: v% w" \8 ?, U" Z--   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  --; C6 w; I$ a' u
--   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    --' X/ y: J  x1 G& w
--   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  --# n( {: z: [; D1 }
--   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   --
0 Y. ?. `7 }0 y) p9 i--                                                                          --7 {* E. I8 b9 K0 w
--                                                                          --! S! \0 r+ y+ L+ O: M
--  This file is based on:                                                  --
9 M% E  y7 K- D* n! D* p: ?--                                                                          --
& o( ^3 W8 ?% X" c4 k2 m9 t1 p4 e2 M7 L--   @file    stm32f4xx_hal_usart.c                                         --" l' w1 l# f( o# g. M$ q
--   @author  MCD Application Team                                          --8 @5 L; }$ J+ t6 E' }) X
--   @version V1.1.0                                                        --
3 v& z6 Y2 i  w3 \* e9 P: I--   @date    19-June-2014                                                  --9 |/ G1 z! S$ C
--   @brief   USARTS HAL module driver.                                     --
; B/ i% E- O7 E2 S6 S' P--                                                                          --" U3 y! X! D" a6 H3 f+ Y3 O, y
--   COPYRIGHT(c) 2014 STMicroelectronics                                   --* f1 s9 R% ], ^  }+ G, u
------------------------------------------------------------------------------
: B7 `( d; i! B3 E$ t2 iwith System;          use System;; r$ `2 M! v' @/ |/ S5 F* d& X2 \
with STM32_SVD.USART; use STM32_SVD, STM32_SVD.USART;
. _% X, U+ Z% Q( v3 m1 Q2 Lwith STM32.Device;    use STM32.Device;, Q+ ~8 M" w$ Q
package body STM32.USARTs is3 F3 @/ _% N- v% m+ f" ?9 T
  ---------------
* G' v2 y3 b. E! a% E  -- APB_Clock --
: D. H" W% j3 A4 [0 O1 F  ---------------' T2 @# Z: D, @' A6 c
  function APB_Clock (This : USART) return UInt32 is
* p) [1 N8 R+ a     Clocks : constant RCC_System_Clocks := System_Clock_Frequencies;# M6 G3 Z$ |$ ~: n6 Q
  begin5 V9 K1 j* T7 |! w1 O# x7 o% m
     if This.Periph.all'Address = USART1_Base% ]2 m) w4 a  M* J! O
       or
; V1 p4 x. N$ r( V9 n        This.Periph.all'Address = USART6_Base2 o6 r* r( l4 c( e
     then
2 k+ Z& P# E- m! d! C7 y        return Clocks.PCLK2;
' B4 N2 q! y3 c     else
; M! G1 s( K1 p# U        return Clocks.PCLK1;& t8 m) C( R  y7 s9 D( ^7 i
     end if;8 U: _& B6 n  f
  end APB_Clock;- j4 K2 J$ R# Q/ e! r
  ------------
+ F% g3 L# E9 Y$ q- @# A  -- Enable --9 M2 a$ G" {: o7 j; ]
  ------------+ Q& E* b1 q3 m8 j
  procedure Enable (This : in out USART) is
0 e4 U9 C: }2 e5 n  begin$ r% K" P, S* F  w) l
     This.Periph.CR1.UE := True;
- H$ D: g& C+ E0 M# D# E  end Enable;! K7 Z& m; x8 X5 X7 Y& r( @
  -------------6 ?( Z6 T2 Y7 G" I! R: c
  -- Disable --
0 f; @7 U3 A% W" ^+ H  -------------6 x- Y1 d( [. P0 @) d- a  I' @
  procedure Disable (This : in out USART) is
9 ?1 @9 g5 s" P# |6 I$ x7 V  begin* m  B2 j$ ]5 M6 ^2 e! o
     This.Periph.CR1.UE := False;. W( Z  v- _1 Q1 Q& k
  end Disable;3 V: s: C% R+ G) T
  -------------
4 F" a' t. }, Y% @' L  -- Enabled --* H+ k( \+ E! L+ Y: N6 d7 ]
  -------------9 g# T/ t( B' P) [9 ^) t3 t* {' D
  function Enabled (This : USART) return Boolean is
( |7 K; E# ?3 W( F3 w% B2 d* x    (This.Periph.CR1.UE);, P" `3 r$ d# U/ d: u0 p# W3 T
  -------------------+ b9 V  u7 H5 G5 |7 g
  -- Set_Stop_Bits --2 k- [: j9 i' ^( A: Q& S- r0 T
  -------------------9 ~; V/ c" o8 M& @, |4 `) j4 {
  procedure Set_Stop_Bits (This : in out USART; To : Stop_Bits)
0 I, j/ J' p: @3 e3 \3 D/ }  is
7 B3 ~8 ~# G2 A% S; z; i  begin
( W! J* F0 X, g' Z+ v3 F4 ?     This.Periph.CR2.STOP := Stop_Bits'Enum_Rep (To);* a0 ~7 y+ \$ K4 c' H: l
  end Set_Stop_Bits;4 W- n# w7 _) R4 X5 a- A
  ---------------------* q0 T/ B) t$ V
  -- Set_Word_Length --
- Z$ e5 T! u+ r  ---------------------& t6 D4 Q2 V9 x% f- L
  procedure Set_Word_Length6 L: @8 @" B% G. A% p& L0 J/ [
    (This : in out USART;
( @% N4 l6 d; s  S# z     To : Word_Lengths)
3 z/ H$ M' C7 P6 ^2 p0 ]  is
3 E6 D4 m# ]4 J& c  ?  begin  ]( z! M5 H' f7 e) m7 D" f/ T
     This.Periph.CR1.M0 := To = Word_Length_9;
1 \9 Q$ y7 B* P" l5 _2 z7 [% k  end Set_Word_Length;
' b$ C8 p/ i) @  ----------------
$ g) E! K% [3 y/ r( D5 f8 _( P  -- Set_Parity --
: i4 G$ R7 H9 A/ W/ L) W( s  ----------------
4 g: W: \4 i! Q9 S7 |  procedure Set_Parity (This : in out USART; To : Parities) is0 `5 b4 W3 d: [0 u' j) [
  begin
/ S$ F2 G; Q! ?5 @4 O7 K! ~     case To is- D# [- e  C7 Z3 T
        when No_Parity =>
3 u# o$ p8 W& J0 C, C3 |  o/ h           This.Periph.CR1.PCE := False;
, U" S$ D6 O( P3 |- j* `           This.Periph.CR1.PS  := False;" M) p$ v9 ~% s. I: b; @1 `
        when Even_Parity =>$ Q& F: T# E! ~* s
           This.Periph.CR1.PCE := True;
4 I+ |$ Q# j+ ^6 E6 c           This.Periph.CR1.PS  := False;2 d( l4 i8 h* ^  n0 k
        when Odd_Parity =>
8 Z, L2 v  g& E8 j6 P           This.Periph.CR1.PCE := True;
$ a* s; X3 Y* }           This.Periph.CR1.PS  := True;
! e: {( d9 [% w     end case;% T+ q' ?- X* L; F; A, c
  end Set_Parity;
* _1 y1 m+ t3 o; F: {  -------------------
" b2 h  ]* U; P0 ~; t. m5 D7 ~  -- Set_Baud_Rate --
  C) b' J7 n+ i+ V  -------------------- L* b7 K2 f9 J0 p+ R4 o* w' Q
  procedure Set_Baud_Rate (This : in out USART; To : Baud_Rates)( j1 w, y+ X& X7 y' y) F
  is6 X/ b' ]& d  t4 j( c% p
     Clock        : constant UInt32 := APB_Clock (This);5 o, v% `2 n0 B0 O* p: J' U
     Over_By_8    : constant Boolean := This.Periph.CR1.OVER8;
9 P8 V1 @9 \: p- z8 E4 Q( l3 C     Int_Scale    : constant UInt32 := (if Over_By_8 then 2 else 4);
; i; _7 w6 E4 K1 U( C; L/ F     Int_Divider  : constant UInt32 := (25 * Clock) / (Int_Scale * To);5 p' y9 E7 i, F& Y$ Q9 E
     Frac_Divider : constant UInt32 := Int_Divider rem 100;
- z1 @1 i5 K2 ~% |. r$ E# v  begin
" y' I6 \  L1 v2 w4 E' w     --  the integer part of the divi2 z2 s( e' p6 z& }/ w
     if Over_By_8 then: Z% k4 B- c2 f$ R
        This.Periph.BRR.DIV_Fraction :=
& Y; b- I1 V5 M( c; v# m" J          BRR_DIV_Fraction_Field (((Frac_Divider * 8) + 50) / 100 mod 8);
; B* F4 K. q/ J& G& E( K  q0 N) b     else
& ~- K) c5 b: \; g; U, T        This.Periph.BRR.DIV_Fraction :=; F8 w8 Y6 c* ^6 E3 B
          BRR_DIV_Fraction_Field (((Frac_Divider * 16) + 50) / 100 mod 16);
5 D3 D& a& E+ \5 N6 k6 a     end if;
9 o# B% C3 z( `% r     This.Periph.BRR.DIV_Mantissa :=
6 g  c7 a2 N# e2 _9 Y# I6 ]5 D6 {1 N' P       BRR_DIV_Mantissa_Field (Int_Divider / 100);  F! V4 w9 t8 L. R
  end Set_Baud_Rate;
6 r/ e8 T/ S8 M, L! J( @! L! U2 _0 K  ---------------------------/ _5 i5 I2 g- w4 c4 d
  -- Set_Oversampling_Mode --
8 E* E' o- ]0 @7 \/ [0 N! P4 w  ---------------------------3 F* R( o5 K2 j/ d3 S5 }
  procedure Set_Oversampling_Mode# G. z4 V* S4 V
    (This : in out USART;
" o1 p" @1 A/ I) X     To   : Oversampling_Modes). I, N8 X6 ~; u) `6 S# J9 ]1 `
  is
. j# ]( X. v1 s, ~5 z  L  R* G  begin, X' ~* ^- R- |( G5 E
     This.Periph.CR1.OVER8 := To = Oversampling_By_8;& n/ k0 ?4 Q6 F  A: @
  end Set_Oversampling_Mode;. H) u+ Y3 F* T
  --------------
+ g; Y" K& F1 q+ S  -- Set_Mode --
* [- u" d+ P5 ?  --------------5 X3 @& |8 Z0 j# `' H7 T
  procedure Set_Mode (This : in out USART;  To : UART_Modes) is
% ]. P, V5 w$ p9 r- d9 E% [# ^  begin
% B- C9 S( s$ S     This.Periph.CR1.RE := To /= Tx_Mode;% ?) E0 T6 y( w; }0 i
     This.Periph.CR1.TE := To /= Rx_Mode;1 `/ ~: g" r# S2 E
  end Set_Mode;$ s; J2 |  k! K& H
  ----------------------! E2 n5 ^$ K. i2 y+ \: S5 ~7 r0 |2 w( n# g
  -- Set_Flow_Control --7 c* }5 L; C$ p4 U* H5 V
  ----------------------+ u. g3 K5 L! A( r
  procedure Set_Flow_Control (This : in out USART;  To : Flow_Control) is; P8 {( v/ @! ?: T/ U/ Y" J
  begin" W' E2 ^5 \# q  x0 T
     case To is5 c- `0 \( M* E7 k  R0 G
        when No_Flow_Control =>
$ O  d0 n' q( }# |" d           This.Periph.CR3.RTSE := False;1 ?: ]/ X4 I' x/ g3 w
           This.Periph.CR3.CTSE := False;/ a- T, F' h; b1 s
        when RTS_Flow_Control =>& m% m& m. Z) ^
           This.Periph.CR3.RTSE := True;
" D# T; W5 H$ X( R           This.Periph.CR3.CTSE := False;
4 \0 ~; H9 O6 {3 m, k+ a' [        when CTS_Flow_Control =>
7 Q, w) ?( {! A( V# X2 v           This.Periph.CR3.RTSE := False;
# n4 f9 P5 W6 A; n           This.Periph.CR3.CTSE := True;
# I! C$ L, F) M" f2 M4 M' C8 I! |        when RTS_CTS_Flow_Control =>5 F: D  k: ~4 r# o4 `
           This.Periph.CR3.RTSE := True;
4 A* v1 ~" U. S6 o' J           This.Periph.CR3.CTSE := True;% z& w- e" |4 X' T" g3 X
     end case;
" v6 {$ F8 N9 Z  end Set_Flow_Control;# B8 H0 z5 T) [
  ---------
9 [4 q3 Y. S9 x8 E( [  -- Put --
7 a) b) @- i4 p+ `2 m  ---------
- ?1 ?$ g3 ^4 n" e$ Y8 W- e; a  procedure Transmit (This : in out USART;  Data : UInt9) is
. n: Q6 x/ C# ]7 v, i  begin1 j1 A7 E* Y* }  P0 `! i
     This.Periph.TDR.TDR := TDR_TDR_Field (Data);
- G9 ]# D! D7 ^  end Transmit;0 _9 p# ]1 x7 G# ~
  ---------! D. S/ j+ G: N* W& A4 N
  -- Get --
6 I' @1 r* ~, h& `: N2 t  N8 i% M: P  ---------
1 Y* `0 F9 A5 d2 n: {4 h: U* t  procedure Receive (This : USART;  Data : out UInt9) is# ?& w9 w; l- I1 E! j6 h
  begin
, |( x" [! A5 z$ `9 Z  ?- d" @     Data := Current_Input (This);
: s# g3 n( f  ?3 n* `) B  ?3 I4 g  end Receive;' ~" t! ^3 C) A% l- x& S8 k/ k
  -------------------$ I7 ]* y7 J3 x
  -- Current_Input --
# w0 u0 [' W# ?# {6 x  -------------------
2 P0 V% Z4 c$ e0 M7 P- [  function Current_Input (This : USART) return UInt9 is (Uint9 (This.Periph.RDR.RDR));
; F7 ]9 s9 f( E  --------------* v' w  s5 {9 V
  -- Tx_Ready --
% i2 l+ K4 e; X  --------------+ _+ y& d/ U. k6 e: _3 r
  function Tx_Ready (This : USART) return Boolean is8 I: o6 d) B5 q; u
  begin
! x2 ]9 X5 ?# Y$ b% b$ S     return This.Periph.ISR.TXE;  T/ S' N" M+ U0 V, v8 j
  end Tx_Ready;
& L9 `; T6 f7 ]" g- ~; ]# V- R, W  --------------
& ]  b1 }$ T1 z, I9 L' x% B  -- Rx_Ready --
. B0 t2 X1 A9 b9 h  `  --------------
/ r8 v2 g) ]8 d  ~/ R" s8 B- x  function Rx_Ready (This : USART) return Boolean is  r( g  p* J  P4 J! Y" {
  begin
3 I' w& i1 v: _; }' c! N& {  Q2 I+ @     return This.Periph.ISR.RXNE;
3 `1 z1 v. m( k  end Rx_Ready;
8 K0 t" p2 x- @% L9 D  ------------
( ]$ |+ [- @7 m$ R) O4 U7 `  -- Status --
, m# D4 c& m/ q; q  ------------
, t9 f; X1 Q  C) {1 T* o  function Status (This : USART; Flag : USART_Status_Flag) return Boolean is
# ]% z6 \, w% n$ z  begin
0 f& ~+ e: ~( D7 m( c; a     case Flag is5 H0 v7 V! R5 F" p: ^1 I
        when Parity_Error_Indicated =># g4 m+ Q, r* r4 E) C/ l8 t
           return This.Periph.ISR.PE;
. d( A/ m5 E1 V0 }3 E        when Framing_Error_Indicated =>
3 c3 H. S9 o" I0 Y$ [/ q3 a           return This.Periph.ISR.FE;
3 K- _6 J7 K1 U. V$ ~        when USART_Noise_Error_Indicated =>
4 w/ B# v. g) S7 X           return This.Periph.ISR.NF;
# ]$ }: r3 w0 o        when Overrun_Error_Indicated =>( K- K: }9 o' J  |3 T, `
           return This.Periph.ISR.ORE;
. x' D" O& g  }1 ?* P; [7 V        when Idle_Line_Detection_Indicated =>
$ l5 \$ G1 A/ I           return This.Periph.ISR.IDLE;- E4 J: U4 R* ?4 y
        when Read_Data_Register_Not_Empty =># Y& W8 G6 q5 h
           return This.Periph.ISR.RXNE;4 a/ L+ z2 H! t- P7 s
        when Transmission_Complete_Indicated =>/ q( M4 F5 u) y8 O
           return This.Periph.ISR.TC;
1 [0 ~/ {0 R1 _+ \- x        when Transmit_Data_Register_Empty =>% [' d# I. g2 f6 A* I+ a, Y  r0 Y
           return This.Periph.ISR.TXE;
( N6 L0 L7 g+ t% K$ X+ h/ H+ ?        when Line_Break_Detection_Indicated =>
! j" A3 b9 w* m; ]% A           return This.Periph.ISR.LBDF;2 u+ C2 `/ w& L0 I7 F! P
        when Clear_To_Send_Indicated =>' J( N+ I& h' B; ~9 m
           return This.Periph.ISR.CTS;
* D* U% E$ U+ k     end case;
1 R. A% s& l$ W0 j  end Status;! A8 [6 V1 ^+ Q& d2 F1 c2 o
  ------------------! m. O+ T& P  a- m
  -- Clear_Status --
* j- r3 S& |# Y5 i9 w8 c- {3 y' L  ------------------
6 [3 A+ H6 k% y  procedure Clear_Status (This : in out USART;  Flag : USART_Status_Flag) is9 ?8 A  \; Z' w8 I
  begin
8 m# B% o4 V4 f  o3 _. q! b     case Flag is! x0 p$ u7 M0 k1 e8 h) g- n" _4 I
        when Parity_Error_Indicated =>
! t5 S; [9 Z5 Z$ J- z           This.Periph.ISR.PE := False;
. n6 ]" H3 @! }1 _" o- e        when Framing_Error_Indicated =>
9 W8 w- e0 g7 c; C           This.Periph.ISR.FE := False;* G% h" s- Y1 _  v8 k( r
        when USART_Noise_Error_Indicated =>
! L& j+ W( r1 M6 I# W4 k           This.Periph.ISR.NF := False;7 g8 g0 `5 o: m% b6 G9 E" J
        when Overrun_Error_Indicated =>
; G8 o& F4 e  `% |- ], X; ?7 T           This.Periph.ISR.ORE := False;; M+ A& i, Z* B0 M  U  L, q
        when Idle_Line_Detection_Indicated =>& d8 J9 e" \! V
           This.Periph.ISR.IDLE := False;
7 G' }6 g/ S7 G4 ]- I' w        when Read_Data_Register_Not_Empty =>
# M0 T! u! v3 j2 p0 C4 k           This.Periph.ISR.RXNE := False;
8 _, z5 ^  G+ A9 J( Z        when Transmission_Complete_Indicated =>; Q! |' Y: f- y/ A
           This.Periph.ISR.TC := False;
5 L6 e' g4 D; R; }        when Transmit_Data_Register_Empty =>. K5 M# S' N, ?! W6 r3 w
           This.Periph.ISR.TXE := False;
0 l. |7 g( M) B$ R  O+ ]        when Line_Break_Detection_Indicated =># F8 h5 K& a2 J$ z
           This.Periph.ISR.LBDF := False;
- O3 j4 S2 s5 x9 p3 N" a" C        when Clear_To_Send_Indicated =>5 [0 b: z* }" J$ a# E
           This.Periph.ISR.CTS := False;
$ H" |. D, i* b! C     end case;
) w, N. t5 B4 A7 m  end Clear_Status;
6 |  |. b1 I/ n5 U0 J  -----------------------
  \  |; A3 M3 Q. _  A% L- B$ p  -- Enable_Interrupts --& O2 k* l! I, g) I2 D% I+ }
  -----------------------! K8 B, z! ], h+ _+ X5 P& u
  procedure Enable_Interrupts8 p9 A+ J  R9 U+ q
    (This   : in out USART;! B4 B8 U  F( }
     Source : USART_Interrupt); t. y( t1 i4 B& ^, T: B; Y
  is
+ b. q! g  y; h2 e& M) v8 x4 g) \6 r9 ]  begin. U1 u3 K5 n& k/ |/ R& ]
     case Source is, T; L) }# s9 v/ }
        when Parity_Error =>
: Z( N6 ]: ~8 z! o           This.Periph.CR1.PEIE := True;# C7 u' l# f& @0 M# U
        when Transmit_Data_Register_Empty =>
& H6 n' o5 q' H. U$ B           This.Periph.CR1.TXEIE := True;; e! q5 h8 ~2 i( ]$ `9 Y
        when Transmission_Complete =>- r1 u0 @% S  d# C( Q/ C, h+ r
           This.Periph.CR1.TCIE := True;" W  x2 f3 J  M7 R) x3 Q9 w) X
        when Received_Data_Not_Empty =>
" A. ^) Y4 B8 ^4 U/ ?: w1 b4 V           This.Periph.CR1.RXNEIE := True;
. g) |4 R! V$ {. W# R# I        when Idle_Line_Detection =>* t  u' |7 O2 O" i
           This.Periph.CR1.IDLEIE := True;; v0 p) J2 e8 t6 X$ E/ f
        when Line_Break_Detection =>
/ H! M' s0 B7 ^8 Z           This.Periph.CR2.LBDIE := True;
4 n$ ?& l1 X. M" U2 g) V0 R        when Clear_To_Send =>
, m9 c" F3 |' I5 z" s           This.Periph.CR3.CTSIE := True;" n/ F# s6 \7 k5 m. j8 p+ U
        when Error =>
( O  T: i7 K0 k, I8 f           This.Periph.CR3.EIE := True;# Q' X5 v3 B: w+ P
     end case;0 F: ?* C/ m3 r0 h2 e
  end Enable_Interrupts;$ Y" r# M* {$ P) K  G
  ------------------------
4 i* ]0 K8 J# W0 E& Z, O$ P- C+ `  -- Disable_Interrupts --
* @7 Y/ I% n1 T) d2 T  g  ------------------------
4 Y6 e( m, v( w. Z9 X0 }2 o  procedure Disable_Interrupts
$ I7 [" @, t4 O$ b" g    (This   : in out USART;
% ]8 B* G  I+ e& j8 L- v     Source : USART_Interrupt)9 M+ j- V  c7 O
  is: ~4 M/ q* v3 `" Q5 F6 z: ]  Q) J" I
  begin
3 L! ?6 {  u9 J9 h( f     case Source is
* ^9 q( s: I; t/ l+ o1 d        when Parity_Error =>: ]# O+ @# m' x5 j
           This.Periph.CR1.PEIE := False;* |6 b$ E4 R4 d  z( n. ?
        when Transmit_Data_Register_Empty =>. ~  b5 n4 f7 p8 e( R
           This.Periph.CR1.TXEIE := False;: d$ ], e8 O3 z! @3 G6 [: C8 ^8 V1 \
        when Transmission_Complete =>
; N/ z3 `  a; \: t7 F) Z           This.Periph.CR1.TCIE := False;
6 o! l* l4 `% z! u( T; i        when Received_Data_Not_Empty =>
9 H9 V# D3 U7 `9 z( s$ P$ s8 e           This.Periph.CR1.RXNEIE := False;& d- @  o3 o- w; E9 L& e
        when Idle_Line_Detection =>
1 E2 T; C' i7 L: U) t           This.Periph.CR1.IDLEIE := False;
' j9 ?4 A5 b2 N, T& V        when Line_Break_Detection =>
8 k4 Z7 h. j+ M* \9 o, |           This.Periph.CR2.LBDIE := False;: R5 }% k* L5 }8 n
        when Clear_To_Send =>
7 ^; F4 T, S( [1 p$ w           This.Periph.CR3.CTSIE := False;* D8 E: `* |' C1 {# O
        when Error =>
7 w# Q) Z. w& r" W6 N3 z9 _# Z           This.Periph.CR3.EIE := False;/ |& r9 c( p7 H" w
     end case;
$ U4 k! D- F7 o- V  end Disable_Interrupts;5 m- j5 z0 t1 \9 {% B7 o  _
  -----------------------
# u: p) F/ q; Y. r0 A. }  -- Interrupt_Enabled --
9 @7 Y% y2 _4 `! X8 }! a$ G  -----------------------
" d  i9 T: U  l) S- I2 G2 f  function Interrupt_Enabled
4 |% `4 @8 C1 B2 i    (This   : USART;
2 I' I- J" _0 V+ K6 v4 [     Source : USART_Interrupt)0 c' `* r, j$ T: w/ w- b
     return Boolean; R- q+ c6 H, L# y' W
  is
) A) X( x+ P6 _) f  x  begin
7 c! Y% J# h* T& s  y' F     case Source is
1 f  x) `5 c2 w3 ]0 C' {/ ]        when Parity_Error =>* ]& a- t7 k5 V1 W0 P
           return This.Periph.CR1.PEIE;
' I: Y' B2 ]% t& `% J; C        when Transmit_Data_Register_Empty =>( {, Y( j1 F6 O: b$ j/ T( x
           return This.Periph.CR1.TXEIE;
6 t/ ?/ h* w- `        when Transmission_Complete =>
3 s+ W4 N& G! j( l' j           return This.Periph.CR1.TCIE;
- W- {1 N; E8 a' J5 d        when Received_Data_Not_Empty =>' B3 v1 {2 ~0 T3 t9 ?
           return This.Periph.CR1.RXNEIE;
3 X6 B4 @5 X3 V% e1 J8 B1 U+ z        when Idle_Line_Detection =>* Y* h( {, E- G. Q
           return This.Periph.CR1.IDLEIE;
3 |( q' x9 k" T; f        when Line_Break_Detection =>
* o; W+ \  d+ W# K4 j" Q           return This.Periph.CR2.LBDIE;  n# w! ]5 G: d5 q
        when Clear_To_Send =>
6 x. O& v% q. G! n           return This.Periph.CR3.CTSIE;" W( Y1 F% S6 a7 u4 {" q
        when Error =>) C, x: ^7 W( H# C9 M; l# M
           return This.Periph.CR3.EIE;$ i& O" _% r5 g' H* Y! @, T' y
     end case;
8 y; Y/ o) M6 o: ~; q  end Interrupt_Enabled;* D: L8 L# ]1 T% D2 h
  ----------------------------------( M& D  r9 t% C8 g
  -- Enable_DMA_Transmit_Requests --8 J7 `. @- K, U' b1 e+ r
  ----------------------------------
5 f3 H* r# O5 e2 p4 ]) U) ]9 F  procedure Enable_DMA_Transmit_Requests (This : in out USART) is
( f1 k$ v4 A. N$ v" ^  begin
9 d6 R1 @' r& \# s+ g+ z     This.Periph.CR3.DMAT := True;
% P) e3 G" N) A* X  end Enable_DMA_Transmit_Requests;
7 ]% x7 ~- C  p/ i9 B" U) x# a  ---------------------------------# n8 G7 c1 q% H, e" \
  -- Enable_DMA_Receive_Requests --' N4 M5 a5 J# X# r
  ---------------------------------# [  |& z. D' T: y4 f' W# e
  procedure Enable_DMA_Receive_Requests (This : in out USART) is7 J) H6 |4 W4 H0 H$ a
  begin
* y9 w1 J8 L+ ^2 y; \! m     This.Periph.CR3.DMAR := True;
+ o6 B, @) @1 t  Y* u3 ?& M  end Enable_DMA_Receive_Requests;; _% ~- B2 f4 E1 v6 L
  -----------------------------------
$ X( E" i: |+ t( C: k3 E. e, e3 a  -- Disable_DMA_Transmit_Requests --4 \5 L( X* `2 E# p1 R; [- }- c! @7 U
  -----------------------------------* ^, u% ]7 g' Y, |, X0 L
  procedure Disable_DMA_Transmit_Requests (This : in out USART) is" U+ K0 O, l: F( X9 b# A* a9 `# h
  begin/ A+ l1 K5 A% c% \- w# y: |; I+ h
     This.Periph.CR3.DMAT := False;
" E% O9 o: c3 b1 E- v4 A$ q  end Disable_DMA_Transmit_Requests;
% I% U2 n. A3 G- H" N  ----------------------------------" ?4 ?. `1 I" H4 L# Q
  -- Disable_DMA_Receive_Requests --. N) R4 v- z/ i# c0 L. [& @
  ----------------------------------
; r$ G: r4 n- Y* `! o  procedure Disable_DMA_Receive_Requests (This : in out USART) is/ T9 C" k& i4 x5 p1 \
  begin- t* V: W# V4 `1 ^4 S( m. f8 E
     This.Periph.CR3.DMAR := False;
. H4 D! }2 O: H  end Disable_DMA_Receive_Requests;
$ q+ y* g% {& m. M  -----------------------------------
9 Q# d( a! M5 M* ~6 f. @. S  -- DMA_Transmit_Requests_Enabled --4 Z2 G7 \- @0 q) o( i6 j: k4 P; b
  -----------------------------------
1 D7 r. I0 ]8 u" {: M  ^, s  function DMA_Transmit_Requests_Enabled  (This : USART) return Boolean is" a) l: T6 A& u0 U0 Z
     (This.Periph.CR3.DMAT);
8 v! N: H' g. w7 P3 F& N0 `) I  ----------------------------------6 G; j9 k4 u0 z; a
  -- DMA_Receive_Requests_Enabled --0 O7 R9 ~  N3 q% b4 b4 D
  ----------------------------------* Z- v: A; C: m9 L' O
  function DMA_Receive_Requests_Enabled  (This : USART) return Boolean is3 N8 O' F3 k! ]+ W2 J. n  t
     (This.Periph.CR3.DMAR);; U1 j* x2 C8 h
  -----------------------------0 r7 Y, |5 w" W0 O/ @! g: z! V
  -- Resume_DMA_Transmission --
/ p4 \) L, d% m" `4 X$ E1 |  t7 @  -----------------------------
9 T9 c& z2 b9 z5 n- E( v( ~; \* E0 y  procedure Resume_DMA_Transmission (This : in out USART) is4 I% D( @& J2 w7 ]  S3 m
  begin
3 u) Y/ k2 G2 x: E5 r! n     Enable_DMA_Transmit_Requests (This);
, h5 j: G& V$ ~) s& J     if not Enabled (This) then: i/ ^9 x0 r5 X
        Enable (This);/ X9 V& W# @4 h; S& l  S6 l
     end if;  Z8 U5 ~9 e2 |; W9 `9 [+ O  [
  end Resume_DMA_Transmission;$ G: B2 V7 G( q% E. q' r; v  l
  --------------------------
& k- R& k" [: z/ a  -- Resume_DMA_Reception --# C0 |' O" M4 o& B( K
  --------------------------
& h# b1 S: D% \, T. S1 K  procedure Resume_DMA_Reception (This : in out USART) is
% F6 E! v+ z/ s$ _0 Y  begin
1 B. m. `% J0 t8 o  N     Enable_DMA_Receive_Requests (This);$ V" [4 C* h- K. D7 a6 p) L, ?, b
     if not Enabled (This) then6 ]. G7 c) ]  `: x: s: Q: n
        Enable (This);
0 K* h0 u  _" \% t     end if;
$ u9 y- h9 x9 V) D  n  end Resume_DMA_Reception;, d% e. R' L( _( k5 d& V5 E7 l! ]7 N
  ---------------------------, H) W2 m- Z# Y) I6 g- G5 |
  -- Data_Register_Address --
& F# N5 s& z! k. [: l2 k. N  ---------------------------5 d# q/ Q' y/ X. `# c  E" x
  function Data_Receive_Register_Address (This : USART) return System.Address is
, D4 t2 q1 N8 t) N+ r    (This.Periph.RDR'Address);
9 y/ h0 _4 U" V  ---------------------------
' o8 _+ }5 o! B) D8 z& R" C; o  -- Data_Register_Address --
: N+ {& |, ~8 G! I  ---------------------------8 y+ z0 d$ w3 F( t
  function Data_Transmit_Register_Address (This : USART) return System.Address is, q* f+ U8 Q5 {+ i
        (This.Periph.TDR'Address);+ c% T/ B9 [; p! o$ ^0 L" |
  ---------------
% l: d$ x( ]! J2 V. V  -- Data_Size --+ B3 z- v- H9 J7 M' H( Y
  ---------------( W* @  U* N, U. w
  overriding
: A4 y" I  ~3 S& c3 M! O( W  function Data_Size (This : USART) return HAL.UART.UART_Data_Size
" ], G/ p9 l: S4 z" f" _  [  is
# T" M- U+ U2 J1 C% Z) T# }  begin3 @* @2 k; A  y' x+ [( u- f2 m; b
     if This.Periph.CR1.M0 then$ B" U% ~$ _) X- l" h! B: u
        return Data_Size_9b;
: m" o  i4 C+ S9 g     else( u# }! c% s( S3 `+ w* {! ^
        return Data_Size_8b;1 `0 L' F: T+ r( X, u" V
     end if;/ v/ `6 N. h0 R7 `# N
  end Data_Size;" J7 ^+ [, ^  m* W: u
  --------------
) Z' `9 f- d( W' R8 Z  -- Transmit --: Z" c/ @  u2 Q" e9 u5 z4 r! |
  --------------( X- [4 a9 s" s( D/ e. _: v
  overriding" c3 S$ o0 w7 E! P5 R7 \5 {
  procedure Transmit+ G: h' C' U  P' t+ [9 Z" q' l
    (This    : in out USART;
, ~+ G' M4 Z9 ]) @     Data    : UART_Data_8b;
4 B$ }( e& m& T3 U( n& C* B     Status  : out UART_Status;% F  G$ v* g' M: I0 R3 Q
     Timeout : Natural := 1000)/ S( ^( Y8 e: j' I
  is6 c+ t7 t* m6 K! C% G# z
     pragma Unreferenced (Status, Timeout);
8 ^1 _6 A( `! K- B: X+ ~6 T  begin$ x! P" F) x2 n, F! i* F8 Y, j6 T: x
     for Elt of Data loop
1 ?/ N4 w/ A- ?' E" E        loop* M# v& o8 ]. M; S; \/ ]; Y4 @& z
           exit when This.Tx_Ready;9 D; L6 P: F  T- o; _
        end loop;2 |8 X4 c, j4 C# I- A5 `' R2 t9 E
        This.Transmit (UInt9 (Elt));
- G: ]. K) p. }" y$ K6 Y     end loop;; d* r+ ~; i! |
     Status := Ok;
6 A$ a) p  \, w5 i2 n  end Transmit;
9 U) l5 G" L" F, L" p9 b1 e  --------------
2 z( d1 Y/ Q$ y( f9 Q. a  -- Transmit --% p, B2 i8 ]4 p- b
  --------------* A$ N4 N' R: o8 }% d, Z1 T
  overriding$ q# ^& X& N5 i) I1 Z/ Z
  procedure Transmit1 R1 C  g0 ^2 W7 f+ e' t* B1 E
    (This    : in out USART;( `8 r# k% R* b
     Data    : UART_Data_9b;
$ i( |* k7 ^9 r7 k     Status  : out UART_Status;
3 S+ }0 r5 X  F; ?) p$ t     Timeout : Natural := 1000)
' {( x: `8 ^$ \8 K+ G9 z/ ]( s  is" T6 K8 l: n* v2 V) k0 R
     pragma Unreferenced (Status, Timeout);2 @/ g7 y7 ^8 I& n, G
  begin
) q: q7 T, T- s- j4 x$ I- v' U# A, J     for Elt of Data loop$ u- B! x- Z+ e7 ~* A: n  G
        loop
. U; U% M6 T( ?. `           exit when This.Tx_Ready;
" \* z7 b! u) M  j6 B4 V        end loop;, D7 f- F7 z0 G; c; B) W+ s  a9 D
        This.Transmit (Elt);
$ @% V& u* `  @9 `     end loop;
& t4 a' ?5 g  H* Q. G     Status := Ok;
; z/ R: q9 U! m* b2 f  end Transmit;& Q" p& Y: p: Q1 M- R' e
  -------------/ R( w- Z, }$ r/ `# v" g8 N
  -- Receive --
3 C( p( d7 J3 x* w  -------------
9 p! d1 R9 H6 L" u. N$ Q# a  overriding
9 J' y; J) t) m  procedure Receive* q" e3 v1 k! r* p5 J1 l+ W
    (This    : in out USART;
5 H! ]. k8 u: n& u& z) _% P7 x     Data    : out UART_Data_8b;$ F. u" T, ~- R3 j6 j* p
     Status  : out UART_Status;2 o& l% ?; M  Q: B( n
     Timeout : Natural := 1000)' k) O0 w4 d' R0 @+ g
  is$ E: c. Y( |& q. T+ w! A. ^: r, N
     pragma Unreferenced (Status, Timeout);! y; _* J: @0 i# t" o
  begin4 F5 f; h4 y/ C2 k' G' y4 S
     for Elt of Data loop' e" V0 C7 W# f1 f0 _) A+ v
        loop2 a4 o3 {% H1 B$ n2 i# J6 b7 F
           exit when This.Rx_Ready;' @  V& v3 l! w! F; i
        end loop;
4 F" @+ Z2 V2 T1 d        This.Receive (UInt9 (Elt));
" M! O3 w$ E1 `     end loop;
0 S# s* {) R" L6 G     Status := Ok;& [( C6 u+ _8 r! O4 ^
  end Receive;/ g' H* N4 B' s$ [! F2 D7 C
  -------------
, T# [, c! U+ X; i) C" k0 Y2 }  ^  -- Receive --
4 v8 u% `5 l7 ~; G" ^  -------------
4 Y2 }! U4 S& {+ E1 K3 T  overriding
3 x2 G4 K+ _$ h$ m& x  procedure Receive
1 }! H7 Y5 Y+ T/ B    (This    : in out USART;. y! U# y3 C$ O+ |
     Data    : out UART_Data_9b;4 \* v& ^# D$ o8 `$ j) m- I
     Status  : out UART_Status;
3 }: {, A0 M$ v; Y2 v- D/ F     Timeout : Natural := 1000)3 [' e- y+ \: p- }
  is- D$ c- {9 p9 r1 A5 F* l! [* \
     pragma Unreferenced (Status, Timeout);, Q$ u$ N1 {% o6 J, t& g
  begin
8 @8 Z- b4 J" ?0 d6 \/ c     for Elt of Data loop5 H; S/ C- c3 v7 U
        loop) J1 m$ x9 s3 e6 _8 Y6 [
           exit when This.Rx_Ready;
) N' S1 v* S9 A; r+ v" @- K$ Z/ n        end loop;% |: w6 K& q2 l/ \. l* Q
        This.Receive (Elt);  C( C9 J$ N$ D: g
     end loop;
& a# j! Q9 u1 e' M7 ^9 G     Status := Ok;! Q0 o1 y0 y) i8 C3 n7 ]3 k
  end Receive;8 B2 Z! x0 K5 u6 q
end STM32.USARTs;
( t2 s7 Q5 R6 |5 r8 t9 R( Y
, [. `' t1 J# E  q2 F4 W: D8 Y5 q4 U) v* s( m" v- V% G
10步:结果
过滤后的SuperIMU在振动时更稳定。来自振动的噪声由多量程配置值和冗余度补偿。
结果非常酷,在图片中,我在垂直握手时抓住了滚动,桌子上有一些小的震动(更多的测试会有严重的振动):
48.jpg
红色:单个IMU,黄色:过滤SuperIMU(滚动)

2 Y$ y6 `( c' F3 h, O
测量的加速度和陀螺仪速率的加权平均值有助于减少振动环境中的噪声(例如,握手)。然而,成本与获得性能的使用可能不值得结果
49.jpg
红色:单个IMU,黄色:过滤的SuperIMU
' a7 ^; x5 m3 i

. ]6 I" `; P# G8 n4 ?2 O* g: {

: n* V( a0 k/ ]
最后,使用以下命令使用生产编译模式:
sudo gprbuild --target=arm-eabi -d superimu.gpr -XLCH=led -XRTS_Profile=ravenscar-full -XLOADER=ROM -XADL_BUILD_CHECKS=Disabled -XADL_BUILD=Production superimu.adb
. i0 G/ u$ S' y8 F9 Z5 v9 ?
我能够在1ms内达成执行:
50.jpg

: F4 [! ?8 @5 l4 T( A: P8 I/ @
结论
经滤波的SuperIMU允许相对于振动和高加速度计算显着的俯仰和行的稳定值。
使用STM32F746 @200MHz通过过滤13x IMU并在1毫秒内估计一段时间内的音调,取得了良好的效果。
似乎对于火箭的需求,配置12G范围的单个BMI088足以满足火箭需求,而不是为超精确IMU支付300美元,使用两个BMI088突破可能会很有趣,每个25美元。
另一方面,在这个项目中,我学会了如何为STM32制作驱动程序(更新SPI驱动程序,制作UART驱动程序)以及制作BMI088芯片驱动程序。在嵌入式领域中,进行预检查,检查后具有强类型定义的可能性是一个真正的好处。与以前使用的C / C ++相比,在Ada中我不能错过UInt4和UInt8

0 r( e* @* o6 b: o: |/ U. ?" `
这是一次有趣的体验,在成功完成项目的这一重大步骤后,我感兴趣的是为我的个人项目挖掘更多并为其他板和传感器制作其他Ada驱动程序。并且还使用Adacore框架继续开发火箭的自动驾驶仪。

# m% E1 X" [$ X* N5 N

4 O: y8 u- R2 G7 d. K8 D, Y# Y) z! s9 s! B# w
" x6 l. c3 c! g$ B  P! h8 e
0 ~9 n9 [1 M( t% w9 S

评分

参与人数 1 ST金币 +8 收起 理由
g921002 + 8 很给力!

查看全部评分

收藏 评论0 发布时间:2019-3-12 23:33

举报

0个回答

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版