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

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

[复制链接]
木木&点点 发布时间:2019-3-12 23:33
本帖最后由 点点&木木 于 2019-4-12 23:57 编辑 7 W% T+ {! ?0 u: A( ?

, c& b& {" w9 r2 P$ [8 ~& l

. i) B" U9 ^# o  j- i# D0 X
硬件组件
STM32 Nucleo-F746ZG  ×    1      
博世BMI088   ×          13     
跳线(通用)     ×  1      
# _8 u! C* F1 W8 W" t$ E6 U$ [
手动工具和制造机器
烙铁(通用)         
焊料空气流动站
信号分析仪

9 E( N: R# a7 ?5 {: R
# e( h% g$ l5 }' C/ k, j
介绍
在这个项目中,我描述了我在Ada中的小型奥德赛,用于嵌入式ARM从头开始创建冗余IMU(使用多个6DoF陀螺仪/加速传感器)和软件环境来控制它。
我还将向您展示我用来达到目标​​的工具和方法(调试,分析器......)来估算一组6DoF IMU的音高和滚动:
' c, I2 F2 j' c6 ?- _2 C
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png 1.jpg

% }8 w! f& x2 j7 `( F7 t# R+ T
* E, b* F2 A* n" B8 {2 g

6 b" P# W6 [% U* Z4 P, S/ c" ]  Y
局限性:
在本教程中,我没有描述控制火箭副翼或如何减少偏航旋转的PID过程,而只描述如何获取数据并估算滚转和俯仰。工作正在进行中,将在单独的教程中进行描述。
$ ^, @$ N+ o/ Z! ]/ _$ z
动机:
对于正在进行的业余火箭项目,我们需要一个能够容忍各种加速度(和陀螺仪)的IMU,而无需在飞行范围内重新配置。此外,我们希望有一个多IMU板用于可靠性和过滤目的。
出于这个原因,我设计了一个冗余的BMI088(13x IMU),试图在高振动环境中获得最佳结果,一个业余火箭和高精度无人机。
在我们的使用案例中,它将被放置在如下的火箭中,连接到托管微控制器的板,该微控制器能够控制和处理来自传感器的数据。
' ], d, ?2 t& N) p8 i, y
2.jpg
, M0 x( L0 K) Y% n8 v* m

9 v0 w, k" G( |  ?) _8 V% f8 {" @& T/ _
使用AdaCore框架和工具链将使我们能够从他们提供的强大编码环境中受​​益(在安全/可靠性导向的行业中得到高度认可,如航空航天和运输)。
我注意到在代码实现过程中,Ada代码,特别是在AdaCore GitHubrepo中编辑的代码很容易阅读。对于像我这样习惯于C /C ++和java环境的人来说,使用Ada并不是特别难。
" F/ |" w' a! U, x1 j, u& V
语境:
SuperIMU已被开发用于CNRS PlaneteScience的业余火箭队。它将有助于在高速和变化的振动环境中计算精确俯仰/滚转,以在飞行期间使用副翼稳定火箭。
7 A: {- y5 p, H  E$ B/ {
3.jpg
火箭的第一个目标
5 S+ h; E' ~$ |6 M7 H
SuperIMU必须嵌入芯径小于90mm中。
- ]7 ^  f. u( R/ X/ G; k, J, d1 U
4.jpg
2 p8 s) b) }* v
  Z% a6 i1 x# l4 M& I8 e% ?$ t! _
第1步:系统描述
SuperIMU具有13倍冗余6DoF IMU,可以直径50mm。它将使用SPI接口与微控制器通信,以获取原始数据(加速度和陀螺仪数据)。

! V/ X  b$ Z3 I) n, _. Z) N
5.jpg
板载配置

. N3 ]6 V& U( Z. ]' L( j
我们使用简单的架构来可视化和测试SuperIMU。
微控制器使用SPI端口从SuperIMU过滤原始数据(加速度,角度速率),并估算角度。出于测试目的,它使用UART端口发送角度值。

% w$ [4 R/ Q: O2 \( l) Q$ ^/ I
6.jpg
测试configuartion

9 @  k* z! C" k% i; l2 u+ x. m
UART端口连接到计算机,以串行到USB模块可视化数据。
该项目的下一步是为SuperIMU创建一个特定的主机板。主机板将是圆形的,并嵌入STM32F746微控制器。
IMU按以下方式分布,呈星形:
. `( p1 x" w  X  n
7.jpg
角度分布遵循45°模式:

$ v  E% ]3 y2 E1 N  N* r9 j( [) Z
8.jpg

+ h1 @3 b! s6 f$ O% @
选择了先前的模式以最大化表面上IMU的存在。根据在德克萨斯大学(RedundantIMU Configurations:paper)进行的几何研究,其中测试了不同的几何配置:

5 z/ v: A8 u6 M  b1 O& V9 r
传感器的3D空间中的几何分布比计划中的分布更好的结果(我们的情况)
分布对加速度没有影响(aDOP Accelaration Dilution of Precision)
分布对旋转精度有影响(wDOP角精度稀释)
我们添加的IMU越多,我们的精确度就越高
IMU的方向对结果没有显着影响

2 O1 V7 @( K- l
9.jpg
5 S$ _9 }9 c7 I3 n
我们记住这个研究,为了达到像配置这样的立方体,我们可以将两个SuperIMU并行叠加。目前我们继续使用UnitCircle配置,尝试从中获取最大值。

- c2 [( \1 K- D6 Z
10.jpg

; p- c$ h; P, E+ x0 |
灵敏度范围配置:火箭模式
在业余火箭中,在飞行的最初几秒内,加速度可以达到8到9克。我们在滑槽开口和落地时观察到了一阵骚动。
这是一个典型的飞行日志(加速度/速度)的业余火箭与三个阶段(推进,上升无推进,滑槽开放,潜水与滑槽,地面接触):
11.jpg

- j) s5 O6 }2 M  A
在短途飞行期间,典型的加速曲线如下:
发射<7秒:加速度> 6g
在降落伞开启前<11s,无推进上升:<3g
用降落伞潜水<50s:<3
12.jpg

& i- T9 `; x( K% o7 Q
在飞行期间,感应范围需要容忍低和高,以无缝地进行精确控制。IMU的范围将在发布前配置。目前我将尝试四种不同的配置,当然这些配置不是确定的,它们需要通过实验进行调整:
13.jpg
1 E8 u  r2 z9 |+ C6 p
IMU分布,范围和名称
在飞行期间,将根据配置的范围忽略传感器原始值:
14.jpg

( Z+ M+ M8 q# t6 h  o
过滤过程
在开始使用它们的俯仰/滚转估计之前,根据它们的范围过滤来自IMU的采集数据(加速度,角速度)。
范围过滤器:
过滤器获取原始数据,并根据每个IMU的配置范围,仅输出低于阈值的值:配置范围的95%。
范围滤波器还根据配置的范围提供每个测量数据的权重。权重用于取消高范围值的影响,它由平均过滤器使用。
权重具有以下值:0,1 / 2,1 / 4,1 / 8。
例如,如果IMU的范围是3G并且测量的加速度是2.9G,则范围滤波器输出来自该IMU的值为0的权重。
15.jpg

& [# _# a$ b( n( W% N
例如,如果测量的加速度<1G,则最准确的IMU是配置有3G范围的IMU。3G IMU的重量为1,6G IMU的重量为1/2,12G IMU的重量为1/4,24G IMU的重量为1/8。
权重根据下表计算:
16.jpg
5 C0 O: c, g' z0 s
例外,当测量数据> 24%> 95%时,它不会为零加权。它会避免产生价值。
范围滤波器的输出值是每个IMU的四倍(加速度,加速度,陀螺仪,陀螺仪等)。
& t; L5 k; M3 ?) K5 u  d6 ~7 a
平均过滤器:
该过滤器根据每个重量计算平均值。当权重为空时,不考虑测量值。
平均滤波器输出滤波数据,该数据是3轴的耦合(accel_filtered-xyz,gyro_filtered-xyz)。

$ E+ }" D% \% ?- y( a, l
滚动/间距估算器:
然后使用经过滤的数据来估计滚转角和俯仰角。使用众所周知的互补滤波器来估计飞行角度。
17.jpg

% k" Y* f/ s0 Y$ j
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,自动检测到电路板,无需安装任何驱动程序。

/ L1 x. A4 D, Y/ i! H( W! i
18.jpg
$ _7 B* S5 s2 {" _6 c
Nucleo主板的另一个有趣之处在于它们与ArduinoUno标头保持兼容。在下面以绿色(D0 ... D13)呈现。
19.jpg
2 i8 Y  }2 L4 u
资料来源:https://os.mbed.com/platforms/ST-Nucleo-F746ZG/
8 k: [" D' V- _6 ]/ c
由于我们需要在读取BMI088传感器(13x IMU)时将延迟降至最大,因此我们使用SPI端口获取Accel和Gyro数据(在这种情况下,I2C不适用)。

: ]3 d+ Q& a* r" k
对于代码,我们将使用STM32F746的SPI1:
SCK:PA_5
MISO:PA_6
MOSI:PA_7
Super IMU的描述:
SuperIMU基于BMI088,它使用SPI接口配置和获取IMU的数据。从数据表中,用户电路如下:
20.jpg

% B) g$ d* P$ X2 a+ a0 q
在SuperIMU的情况下,没有使用中断,它按顺序获取数据。ACCEL和GYRO的SDO在电路板中输出相同的输出。
我必须单独选择每个Gyro和Accel。
21.jpg
' n& {! O7 [3 I6 ], P9 }6 p# c
AdaIMU BMI088 Circle(SuperIMU)的原理图
SuperIMU的设计可以使用单个SPI获取数据(下一个版本将使用多个SPI),它具有13x BMI088:
22.jpg
. s. J5 l! M9 h8 o* j3 r% X
这是它的样子。我需要焊接接头以连接杜邦线:
23.jpg
在后面有引脚的描述,SPI(SDO / SCK / SDI)以及用于选择陀螺仪和引脚的引脚:
24.jpg

7 {. L6 ^/ {& c8 h( h

7 G" P4 O, x) k( W5 w
25.jpg
$ Z$ e5 w2 M5 |7 p  c
1 \  c- [/ N4 [) i8 f7 ]4 I
26.jpg
完成焊接后的样子如下:
27.jpg
La pieuvre:
28.jpg
8 K/ Q' H/ i- J) Z8 E9 |

. m# H# o' K8 n& }! p
29.jpg
SuperIMU使用3v3电源和SPI端口1连接到Nucleo板。
30.jpg

% @9 L  Y: }' O% n0 q" ^
. y% _( V' t7 z! O. P* a
GPIO引脚用于选择Gyro,13x IMU的Accel将按如下方式完成:
31.jpg

1 y. W$ N7 w3 s# f- f+ p

7 q8 D. \4 A* M7 t* j
用于选择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
                                                            );

! a7 r0 E  o5 b! q6 A, @
4 n. N" D6 t+ I3 \7 k# _0 B

% }) c6 l5 A8 z9 v; q, J( k; ~4 v% B6 W$ H
第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)提供编译器和构建器工具链。
0 _/ c2 @2 A1 ^) p4 L
使用项目的代码
要使用该软件,您需要克隆此分支http://github.com/LaetitiaEl/Ada_Drivers_Library,此存储库基于Ada驱动程序库:AdaCore /Ada_Drivers_Library

- M) |4 m, ?* C
使用./GNAT/2018/bin/gps 打开项目文件:Ada_Drivers_Library / examples /STM32F746_Nucleo / SuperIMU.gpr
你编译/上传,这就是全部!

5 q: q7 G/ `- n- b( m; [* B; i
该项目针对STM32F746,如果需要可以轻松移植到STM32F4(通过github或黑客联系我寻求帮助)。

9 I  G* p' g+ Q" m$ Q' |
第4步:首先进行眨眼测试!
在继续之前,我需要确保可以正确编程电路板。
( j/ S4 N. H: G! N: @( Q9 S: P' K  A
我保留了现有文件:blinky_f7disco.gpr,并修改了以下路径。继续使用stm32f746_discovery_full.gpr没问题

4 X+ p+ H3 h% m! ]' h7 G; }: ]
with "../../boards/stm32f746_nucleo/stm32f746_discovery_full.gpr";
blinky_f7disco使用以下主条目:
Ada_Drivers_Library/examples/shared/hello_world_blinky/src/blinky.adb
7 c; _1 }8 x* y, Y  ~/ d
blinky的内容如下:
with STM32.Board;   use STM32.Board;
2 Y8 Z5 b- q3 Y5 ^( Fwith STM32.GPIO;    use STM32.GPIO;- F8 ]! a$ H6 s: A$ Z0 k
with Ada.Real_Time; use Ada.Real_Time;# x4 V$ d! x' ]& W
procedure Blinky is
3 ~3 t$ p$ U1 t% R  Period : constant Time_Span := Milliseconds (200);  -- arbitrary
: `4 C& J( _3 R4 D: b5 w  Next_Release : Time := Clock;
" ?4 n$ X6 ^& w& V' y: H6 Q2 xbegin
4 L4 ~- e- X8 S7 }0 s; ]( o  O9 T  STM32.Board.Initialize_LEDs;
$ A+ }6 F$ J0 ^, P  n* y' Z  loop
5 f, N( V( [8 L* T) D+ ~     Toggle (All_LEDs);2 M! ^) H* ^: K& _
     Next_Release := Next_Release + Period;' w6 Q0 n  {& N6 T
     delay until Next_Release;! A/ _9 ~7 H; Y. _
  end loop;: ]/ L; R+ x, P6 P" L( P) q
end Blinky;
- F3 S; H" \4 T; ~4 i& ]! W
  Z" N: Q4 F. Z! G% Q2 H0 {4 D9 j
# }% M8 ?9 l' Y1 v! {! {

2 n! z9 r: w# x! Z/ E' F/ {
似乎这个代码对所有主板都是通用的。使用GPS IDE我遵循All_LED的定义,它定义于:
Ada_Drivers_Library/boards/stm32_common/stm32f746disco/stm32-board.ads
1 d2 S$ ~. J% }& i
值All_LEDs是索引为1的集合,指向PI1:
  Green_LED : User_LED renames PI1;6 n/ H# r4 e- `5 Z8 g" `  i# r" r
  LED1      : User_LED renames Green_LED;% t+ s5 O. y& |  H* r" [. A8 A) j
  LCH_LED   : User_LED renames Green_LED;; @- Y* J+ g4 [
  All_LEDs : GPIO_Points := (1 => Green_LED);
+ u: n% p; R, }( Q- K6 v  Q/ ^9 y. o; f5 r. c

6 e+ c* r- L0 _5 |6 D: ?
在Nucleo板上没有LED连接到PI1,找出我可以使用的输出,简单的方法是检查核板的原理图http://www.st.com/resource/en/sc ... leo_144pins_sch.zip
8 G* Q/ k. v  P2 y$ B
32.jpg

  B% ~! _2 R6 s, d/ o
我把蓝色LED连接到PB7。然后代码更新为蓝色:Blue_LED : User_LED renames PB7;
7 l4 v# n8 D7 U! v+ N* C. i  LED1      : User_LED renames Blue_LED;
# ^' L( Q2 P5 V$ `, x4 F0 q8 d, r  LCH_LED   : User_LED renames Blue_LED;+ u9 a: m% C2 R& A7 s
  All_LEDs : GPIO_Points := (1 => Blue_LED);9 s$ V6 W3 Q% M1 }. A2 M

3 ?9 O2 w: u+ Q9 ?  _
8 F8 A, F' v* Y

* k1 `8 b5 w/ R9 _2 i
7 @; T# s- k1 m: o4 @+ [/ P' ~
然后使用上传按钮上传代码(重要的是您需要配置上传/调试,在我的情况下,我使用OpenOCD,如下所述)
33.jpg
代码编译得很好,正确上传并且蓝色LED闪烁:
34.jpg
+ q: }& M( ~% C! r1 @6 x' ]4 p
让我们开始认真的工作。为BMI088制作SPI驱动程序。
0 P& b- J7 T, `9 Y$ \# w- P% M
第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中,我们添加:
  ---------------------------------
4 f8 v+ V, r3 O  k) T  --  SPI1 / IMU BMI088 example  --
) ~$ K) y# o& z' Q" z  ---------------------------------% |. s" A9 F8 Q# S" m
  -- SPI Port4 n/ x/ T% E2 V/ c$ i7 C- h: C
  IMU_SPI : SPI_Port renames SPI_1;2 F4 q! ^- p6 x% o0 F2 P
  -- SPI IOs! c" E# O/ F1 y3 n* m' x9 o
  SPI1_SCK     : GPIO_Point renames PA5; -- D13 in connector CN10
1 [; u7 S( |1 _5 U0 Q. z  SPI1_MISO    : GPIO_Point renames PA6; -- D14 in connector CN10- O2 G2 v3 G% f" E# e" I, Q$ U
  SPI1_MOSI    : GPIO_Point renames PA7; -- D15 in connector CN10: v. c2 D* G+ G
  -- IMU select
) A2 |3 U/ i: f7 s7 K' r  IMU_SEL1    : GPIO_Point renames PG9; -- D0 in connector CN103 v3 n( E& G% @; a+ A# t
  -- To initialize the SPI1 port for the BMI088+ B2 s( [( M. }( a; `) k, m
  procedure Initialize_SPI1_For_BMI088;- i5 `' c5 O; i* g

8 k" M4 R# [7 }( D. X

& g) {5 g0 Y4 s) J; O$ \
STM32F7中使用8SPI的技巧
BIM088与8位通信非常重要。但是数据tx / rx DR寄存器是16位,默认情况下它发送16位。首先写入/读取:NOK
36.jpg
) w, t" F, s6 u! R, Z- K/ D! [
根据参考手册,诀窍是将寄存器DS(数据大小)配置为4位,并正确格式化DR寄存器中写入的数据。
37.jpg

8 g( B% H' q6 G7 L7 c: c
这就是为什么我更新了SPI(stm32-spi.adb)的默认驱动程序,如下面的写/读8位模式。
. ^% [) P" B, M6 T/ [( Y6 m3 b
procedure Configure (This : in out SPI_Port; Conf : SPI_Configuration) is
5 C+ N* G0 K* ^, V- K7 s  begin
4 N$ v9 q( |1 G/ S% }5 s...- O% t1 M) D2 _4 V( |8 `
    This.Periph.CR1.DFF     := Conf.Data_Size = HAL.SPI.Data_Size_16b;
+ J  F8 H9 U' {! t7 X' a     This.Periph.CR2.DS      := STM32_SVD.SPI.Size_4Bit; -- add this line4 O3 \2 M5 z  Z) n9 B
     This.Periph.CR1.CPOL     := Conf.Clock_Polarity = High;
0 h: L! x6 b0 Y% L+ j+ r8 x" B...
7 Z; x/ ^( |. s4 Wprocedure Send_8bit_Mode
. ]. w1 m) Q+ w' C! z7 R1 O    (This     : in out SPI_Port;
' h) F: m! m' w3 D' O     Outgoing : HAL.SPI.SPI_Data_8b)6 b" B$ Q$ w, J/ }; z( g0 {# o( f
  is# n( ~/ H3 H; @; j) h
     Tx_Count : Natural := Outgoing'Length;' z& c9 T% ~4 K4 @3 n8 D  y! e
     Index    : Natural := Outgoing'First;" o% Q7 ^1 L" `. A; G+ }
     Tmp : UInt16;
# ]2 O/ H3 V; X9 _4 T4 S  begin
% j5 B9 e/ u7 k; W; ]. f     if Current_Mode (This) = Slave or else Tx_Count = 1 then
" r9 q3 C/ |: a% K7 \! _2 V) Y6 O        Tmp := UInt16 ((Outgoing (Index) and 16#0F#))*256 + UInt16((Outgoing (Index) and 16#F0#))/16;0 L0 r" ?+ P, \- F; V- ?" y
        This.Periph.DR.DR := Tmp;
. i1 k0 v0 _7 v0 b8 @- \7 B$ B( L3 B        Index := Index + 1;$ s7 o2 ^& F$ k: a8 [
        Tx_Count := Tx_Count - 1;+ X  g2 p4 s+ y1 w
     end if;
% {% I0 X* B6 i% a  P...$ f5 y) x/ ^4 H$ Z
procedure Receive_8bit_Mode3 E, D1 o. E- D: r0 R* [
    (This     : in out SPI_Port;
' g! I6 s. I  b: }. p1 N     Incoming : out HAL.SPI.SPI_Data_8b)
# ]/ I6 E" X  ?; U  is* @. _# _: s. d8 ~: f0 V
     Generate_Clock : constant Boolean := Current_Mode (This) = Master;
' H) l$ Z# H# e, I% r& I. A     Tmp : Uint16;
) b8 k/ u+ ~8 c! C5 @& r  begin2 e# ?' q: j& r7 U; Q6 m
     for K of Incoming loop
7 w, @- _4 u, v. Z6 v' q, T$ U        if Generate_Clock then4 ]  n' U0 N" d0 d- j! }0 A
           This.Periph.DR.DR := 0;$ L0 E3 N: _7 Y9 t" g8 ]. p7 N/ {
        end if;7 A" a7 q0 D+ W' ?
        while Rx_Is_Empty (This) loop" F- L; l$ l1 G2 p! l& \
           null;) \/ D- r3 _# B6 v; J+ ]( ]. h; E1 ]5 P
        end loop;
  H: B, w* {* L7 X5 W$ a3 {        Tmp := This.Periph.DR.DR;
/ I; g  ~3 i! x) l3 o# a6 v4 m        K := UInt8 (Tmp and 16#000F#)*16+ UInt8 ((Tmp and 16#0F00#)/256);" Z9 }5 Z! T, O  U  G. h
...7 Z. O# A4 M7 j7 K

; J- L6 h" ]  w- e2 r' ]3 y& E6 r; O1 C% x5 [/ |! X' f+ a$ M
) @/ ?( v5 N5 `# U5 I
8 F, s% d" E1 d, K
/ a" _; c- \1 ]" G
这样我获得了更好的时钟,BMI088寄存器中的读/写在8位模式下工作正常:
38.jpg
% W' i3 a/ U* R( [$ I5 y' J: M
但还是不行:
因为我们需要在读取加速度计时(不是陀螺仪的情况)总是丢弃BMI088中的第一个接收字节。这就是为什么每次我进行读取时,我都必须先读取虚拟字节。通过此更新,我获得了更好的结果。
, z) e, N$ \+ h2 p) g
在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;
# t* F/ E$ K& }( w& K0 |; T% m4 r

; J) g' s6 W5 ?4 `. t
+ x4 k* d; {" B  ?) P
最好从寄存器中读取加速数据。在下图中,我们仅表示SDO和时钟(SDI未表示,我只有2个探测......:'():
39.jpg
对于陀螺仪数据,虚拟字节没有问题。
这就是为什么必须要有Accel_Read和Gyro_Read不同的程序。
初始化BMI088的步骤
首先,您需要通过调用以下过程正确初始化SPI以与BMI088通信:
2 h; m3 B4 F6 M9 Q
procedure Initialize_SPI1_For_BMI088 is# Q, ]3 ?# a; l- e
     Config : GPIO_Port_Configuration;
; w! {! z; H, [9 z     Config_SPI : SPI_Configuration;, ]# I3 o0 x% U! a
  begin% h: j' A+ t- J- S
     -- Enable the clocks
( c5 s4 h1 m% [# H0 O     Enable_Clock (IMU_SPI);& O! b* ~( V* Q1 ?* U
     Enable_Clock (SPI1_Points);
7 o. b# o/ F. K5 l9 ^8 f4 X     Enable_Clock (IMU_SEL1);
& V. y& S% O% ^     -- Configure the SPI IOs+ W& J, H# v. I' u8 N
     Config := (Mode           => Mode_AF,
5 [% ?' Y; W: n0 @# o                   AF             => GPIO_AF_SPI1_5,
2 U9 J7 f3 [: ?$ Q( A' S7 }6 Q                   AF_Speed       => Speed_100MHz,
* f, \0 l; v* p: o4 ]                   AF_Output_Type => Push_Pull,
2 j) u7 r! j  l6 C                Resistors      => Floating);8 H6 r" R0 m" W( i
     Configure_IO(SPI1_Points, Config);
  Z1 H; R9 P' f: P2 r" G' R     -- Configure the SPI select chip IOs
( R  E. q% U6 @( Y, f6 P3 C6 P& u     Config := (Mode        => Mode_Out,& ?- U9 d: t1 {8 a1 y3 B! h# V
                   Speed       => Speed_25MHz,# r# K) _, t0 L+ m( g+ s
                   Output_Type => Push_Pull,
% f8 m1 @8 m0 Y- L                   Resistors   => Pull_Up);
, c5 m. m2 }' v2 k& a2 |% |! X8 c: S     Configure_IO(IMU_SEL_Points, Config);
% I1 C1 @- W- L     -- Configure the SPI1 port4 Q! k4 r$ ?9 z! V  a
     Config_SPI :=
! s. b( }) g; f& s5 ^          (Direction           => D2Lines_FullDuplex,6 K+ w% z) a5 B
           Mode                => Master,
0 x8 G# V4 k1 f0 b+ t4 A8 u           Data_Size           => HAL.SPI.Data_Size_8b,& N+ b9 x4 k4 E" s% D$ b
           Clock_Polarity      => Low,, s/ @' l) S4 v0 }, u; Z% J" b
           Clock_Phase         => P1Edge,6 @8 K* E3 J  ]0 D
           Slave_Management    => Software_Managed,
( I2 {3 F$ q6 _4 A, a5 c           Baud_Rate_Prescaler => BRP_328 U! g7 t; t8 z7 ]& \' X
           First_Bit           => MSB,8 R* D0 o$ `: s1 n
           CRC_Poly            => 7);
& {$ u7 ?1 h# m1 C  h0 v* `4 I     Configure (IMU_SPI, Config_SPI);6 Q( E8 k6 M2 u$ J& B
     STM32.SPI.Enable (IMU_SPI);
0 F8 u6 H: N: G7 [) ]  end Initialize_SPI1_For_BMI088;( w3 ~2 v1 N3 h0 j" Z8 }

9 p# j* i$ Q+ _+ |
然后按照以下步骤获取加速度计(寄存器和命令的值在数据表中定义,您可以在最后的驱动程序中找到它们):

* J* y( q1 ]: ]  q$ ~9 z7 S. A
---- check the device ID
* K' [& K& O& |1 L  Bmi.Read(ACC_CHIP_ID_ADDR, Result);$ ~( ]1 g1 T3 g- w
  while Result /= ACC_CHIP_ID loop
% S  [, }" W  F     Bmi.Read(ACC_CHIP_ID_ADDR, Result);: B$ e: z: W# C- S9 E
     delay until Clock + Milliseconds (1);
2 L) f9 d* f/ T% ~$ I  end loop;) q  A" K* o+ b# G% ?
---- reset the accel
! v; p% ^5 t0 P4 j: y  Bmi.Write(ACC_SOFT_RESET_ADDR,ACC_RESET_CMD);9 \1 l$ v! y8 I2 U
  delay until Clock + Milliseconds (50);. D7 A" c- z+ e# r: j+ a
  Turn_ON(IMU_SEL1);
: b' q3 E* S/ Y& |8 Q  delay until Clock + Milliseconds (5);2 S3 i* m; S5 h8 w: P7 p
  Turn_Off(IMU_SEL1);1 z" M! g9 C. J4 m0 |6 ?; ?! X4 J( p
  delay until Clock + Milliseconds (5);
+ R% x( m0 W, Y3 y! L+ I---- enable the accel (rundandant to make sure it works)
3 z$ C* \+ Y/ j* s$ m  Bmi.Write(ACC_PWR_CNTRL_ADDR,ACC_ENABLE_CMD);/ j9 n/ Q  m8 w) y, w! k
  delay until Clock + Milliseconds (50);  * D2 \6 U9 [  s5 `# T5 g: G% X
  Bmi.Read(ACC_PWR_CNTRL_ADDR, Result);0 K% s% H7 v0 |" Y% Y+ ?# R
  while Result /= ACC_ENABLE_CMD loop: V+ U4 p; j1 J) f- U, Y" {) S
     Bmi.Write(ACC_SOFT_RESET_ADDR,ACC_RESET_CMD);# Z" v9 B& }& Q8 a5 z
     --delay until Clock + Milliseconds (1);" A, H+ A0 w0 S1 q4 X& S/ V" q
     Bmi.Write(ACC_PWR_CNTRL_ADDR,ACC_ENABLE_CMD);
! E# B; i( D  j& I* C- l7 J     --delay until Clock + Milliseconds (50);+ C! E! ]. C0 D/ L* L
     Bmi.Read(ACC_PWR_CNTRL_ADDR, Result);* g8 ~- T, V! ~0 e4 u4 n4 c
     delay until Clock + Microseconds (4);  O/ W( x( {: \: t5 z+ J, W
  end loop;0 E; V: \+ u3 B7 b$ [  ]
---- enter active mode
  k& X4 H2 i5 C% W% J  Bmi.Write(ACC_PWR_CONF_ADDR,ACC_ACTIVE_MODE_CMD);
) G  _& H- {1 F  D' Q9 ?- H  delay until Clock + Milliseconds (5);+ p! B; I1 m" I* X, l
  Bmi.Read(ACC_PWR_CONF_ADDR, Result);
- J. \1 ~: W, y  while Result /= ACC_ACTIVE_MODE_CMD loop
( F* i2 D& t2 {- o- z5 A+ j     Bmi.Write(ACC_PWR_CONF_ADDR,ACC_ACTIVE_MODE_CMD);
; \$ u; P. B4 X8 p+ u3 z3 x     delay until Clock + Milliseconds (5);) w% t5 ]3 |/ m2 E7 @7 r
     Bmi.Read(ACC_PWR_CONF_ADDR, Result);  {+ E  n3 y3 X% F% C& P  \
  end loop;, u+ x, z6 s' L/ Z
---- set range 24G) m/ M5 k9 q- I- Q- z% G6 x
  Bmi.Write(ACC_RANGE_ADDR,RANGE_24G);- k' b8 W) [1 H& w6 |0 }
  delay until Clock + Milliseconds (1);6 t+ G6 U4 f5 ~0 s9 b6 F
  Bmi.Read(ACC_RANGE_ADDR, Result);
$ h5 R5 ^6 r7 A9 P0 T# t  while Result /= RANGE_24G loop
# |  ^# ]5 _9 b! Z     Bmi.Read(ACC_RANGE_ADDR, Result);
2 `; e) @' ^1 J! s  end loop;
, J) A% Q6 B6 H+ g  Q2 g---- set default ODR
( l! b, ?8 U) P' _8 J  Bmi.Write(ACC_ODR_ADDR,ODR_1600HZ_BW_280HZ);, d& K% V) o' n+ q* h# r- J( g
  delay until Clock + Milliseconds (1);
; m' `) u1 g8 V4 y  Bmi.Read(ACC_ODR_ADDR, Result);0 z; P2 L! T  G* h. _% ^1 Q/ B
  while Result /= ODR_1600HZ_BW_280HZ loop
. }* Y7 r6 B- d$ d     Bmi.Read(ACC_ODR_ADDR, Result);
, q0 H+ T3 x0 C  end loop;6 w& c# }6 q3 F) p
---- check if there is an error
" ^+ [7 r, Z$ ^; ^  v* E! z  Bmi.Read(ACC_ERR_CODE_ADDR, Result);6 I0 H6 i9 c8 `: L' O  Q
  while Result /= 16#0# loop
( t  r' |7 r. X* G* A1 _7 `( s% y$ i+ P     Bmi.Read(ACC_ERR_CODE_ADDR, Result);
3 i- S* `# P* \) \1 j  end loop;* c+ F9 D& z& C. z0 I
  ---- read the value1 [( A* w$ g  V
  loop/ q5 `( |. Q8 x/ o+ }
     Bmi.Read_UInt8s(ACC_ACCEL_DATA_ADDR,Received,6);2 V% F8 y% J1 p
     delay until Clock + Microseconds (100);. _+ d1 U8 m( J) G' e
  end loop;
# _" Q$ m% O& c3 q
, I  \4 l" L& \* [1 G
按照上面的步骤,我使用来自BMI088的SPI获取值。
/ C- s1 n4 A; l1 _0 a( D
步骤6:过滤和估计描述
应用几何变换:
SuperIMU中IMU的配置不一样,它们被旋转(45°和90°):
40.jpg
只有加速度X和Y受到旋转的影响。陀螺仪没有受到影响(转速是相对的)。

+ }( C% U2 Q+ {1 N9 y
根据每个IMU位置完成旋转变换。旋转按以下过程编码:
6 N1 p" {3 o2 P5 b$ p
--------------------
  -- 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;  
' _) j7 G3 S% ~& J% y
( F; e: u9 E. I  [) m

/ l/ j  K4 {; s7 |+ Z8 E4 R& J
使用范围:
IMU的范围不同。每组IMU都有一个特定的范围:
41.jpg
IMU分布,范围和名称

, m; v6 r! C; I# C; |
配置中使用的范围使用以下代码计算:

4 ?6 T8 S& X9 J8 n* c$ E
--------------------------. U5 N; P- {. Y. U
  -- Get the range to use --) ^9 D0 h4 r0 o0 m
  --------------------------  k# J5 H, m. }( w' [9 a9 S5 `
  Range_3G_Index : constant array (1 .. 5) of Integer := (1,3,4,5,2);2 n) A; w% W5 U
  Range_6G_Index : constant array (1 .. 4) of Integer := (8,6,12,10);
! B& l- @) |9 o% l* U- t0 _! [  Range_12G_Index : constant array (1 .. 2) of Integer := (9,13);1 @, G8 I& e0 [  y8 n
  Range_24G_Index : constant array (1 .. 2) of Integer := (7,11);
- p. v/ R  j! G% l% B2 ]  function GetAccelRangeConf(i : Integer) return Accel_Range is
5 c- J) B2 U3 r9 x' [0 |: Z# n  begin$ ?8 Q% D# U3 x7 E* {
     if i in Range_3G_Index'Range then
  e, p4 _9 Z* B- R: k4 S        return ACCEL_RANGE_3G;# B% H0 i+ m. S3 u' Q3 X- j
     elsif i in Range_6G_Index'Range then
& L# `, N" q9 W9 c, l& o& J! i' c        return ACCEL_RANGE_6G;2 `" r7 A# D$ k4 T
     elsif i in Range_12G_Index'Range then
; U. h+ L3 w" C0 }! K9 @% x8 u        return ACCEL_RANGE_12G;0 h& ?7 w1 Y$ v* E# m9 b8 P
     elsif i in Range_24G_Index'Range then
/ G. {8 T) B- q        return ACCEL_RANGE_24G;& N1 q& U: o5 G
     else
3 z& Z( w# d! |" z. ~$ Y        return ACCEL_RANGE_24G;
4 }% k0 t) W, o9 {5 L5 N     end if;
& o. K8 w- S$ a  end;
; Q+ w8 C( V' Z0 `  Range_125DPS_Index : constant array (1 .. 5) of Integer := (1,3,4,5,2);
( s$ }- G( \: }  Range_500DPS_Index : constant array (1 .. 4) of Integer := (8,6,12,10);
7 ]. ^& W9 a6 y2 }5 e  Range_1000DPS_Index : constant array (1 .. 2) of Integer := (9,13);- h7 Z8 A6 P! K. U
  Range_2000DPS_Index : constant array (1 .. 2) of Integer := (7,11);
5 k$ H, X$ z$ C  function GetGyroRangeConf(i : Integer) return Gyro_Range is
3 c8 m/ x2 V9 ~' q  begin
3 L3 Y) n. ]8 Z/ |9 s; K     if i in Range_125DPS_Index'Range then
2 `0 z# e. E7 s. }+ H+ e        return GYRO_RANGE_125DPS;
/ a( S% _# u8 M     elsif i in Range_500DPS_Index'Range then( N) O: \! y/ O0 v% n$ k* d
        return GYRO_RANGE_500DPS;9 e0 y  S( ?- q2 c( C* ?# t2 d+ d6 ?
     elsif i in Range_1000DPS_Index'Range then
* B1 P* B2 S( z+ B* ]0 H& g, Z        return GYRO_RANGE_1000DPS;" s$ j1 N( z5 A5 c
     elsif i in Range_2000DPS_Index'Range then7 f/ I% @2 i' ^; f/ S, L
        return GYRO_RANGE_2000DPS;# I! K" T' W# w$ v
     else
+ u8 J; ?) K& A. `" c# z4 g        return GYRO_RANGE_500DPS;6 {( n# @2 }  }9 ?0 a+ v% ~+ _# e
     end if;        
2 `' c% f, q. n% l* S- W4 v2 D  end;+ l6 W3 ~2 B' }+ i2 S$ Y) V: E$ F

+ e) |( a2 Y5 m3 P. }' O6 z9 R5 Q
过滤代码:
根据每个IMU的配置范围对加速度和陀螺仪速率进行滤波。
权重使用以下代码计算:

* ^, J4 i9 _) I2 f9 H
-- IMUs filter, filters the Gyro/Accel according to the range& V/ R' C9 s, A
  function GetAccelWeight(rng : Accel_Range; val : Sensor_Accel_Data) return Float is
4 T  C0 D+ y4 t* r. y& \     weight : Float := 0.0;6 A2 }" t! K. a( W4 g+ {
     refaccel : Float := 3.0;
  {6 I3 |/ ^+ Y7 W0 j     refrange : Float := 3.0;& ]# H1 b: V' b& W; J1 ?( o# }8 v- ^
  begin% l  q& _* y; x
     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)) then
# W- ~0 Z2 I0 `% G% t- H7 u2 ]4 P        refaccel := 3.0;
. J0 K% I/ z: b9 C6 _4 l8 o     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)) then8 X; Z1 d2 X8 w! F+ M
        refaccel := 6.0;
# P( f& T! Y* r" B7 E9 R7 T     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)) then5 H: K" ?) E( r: J2 U
        refaccel := 12.0;
: z2 g# `2 u' Y) r- h9 w     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)) then1 c5 t; b4 N, ?; }5 v
        refaccel := 24.0;
# q1 j* T6 h% X# Z9 Y/ R3 X     end if;% e, ?4 k4 N) O# `9 h0 u) M
     if rng = ACCEL_RANGE_3G then, @3 H. l5 T* C) A0 n; h' N  X
        refrange := 3.0;# k) R+ X- l- W7 m' M  Y6 U0 ~/ y+ O
     elsif rng = ACCEL_RANGE_6G then
3 w  k+ ^- i& u. k" _        refrange := 6.0;
/ M& v3 a# _; u* H2 T6 L6 ^     elsif rng = ACCEL_RANGE_12G then# i8 K4 R4 a* D! e: v/ [
        refrange := 12.0;
# z# W! Q( Q5 G6 L$ K     elsif rng = ACCEL_RANGE_24G then; ?" ]2 A4 C% J2 Z3 f, e
        refrange := 24.0;
: i( |' [' b. u, Q3 o9 W2 j     end if;
, C4 H6 k% x- W4 w, u6 a1 e     weight := refaccel / refrange;9 X" a' G6 B0 m* [; T6 W3 ~5 }
     if weight > 1.0 then
2 A  s" h: P% R9 U# {( N4 O3 {        return 0.0;
! V3 ?7 A$ a8 X+ k3 z4 q     end if;
; Z; [" P  ^: l, s3 n" P. W     return refaccel/refrange;" m* K5 ?  A. l4 U- u8 v
  end GetAccelWeight;
% _5 E4 B& O  p. Q function GetGyroWeight(rng : Gyro_Range; val : Sensor_Gyro_Data) return Float is
; R) m; e  I4 e1 F5 z     weight : Float := 0.0;4 \6 c1 v2 `# r8 U
     refgyr : Float := 125.0;& v3 s; ~( i5 {, v0 B  o
     refrange : Float := 125.0;
8 K9 Z+ e- N$ a: h0 w, F  begin, F+ {6 p# [# ^( Q
     if ((abs(val(X))<125.0*0.95 and abs(val(Y))<125.0*0.95 and abs(val(Z))<125.0*0.95)) then+ o3 M$ D. A- ]( l
        refgyr := 125.0;
3 z9 Y7 a$ y# O% n     elsif ((abs(val(X))<250.0*0.95 and abs(val(Y))<250.0*0.95 and abs(val(Z))<250.0*0.95)) then
- U$ }* k8 y4 S, h        refgyr := 250.0;+ T, b7 J& U8 T' m8 L  U" ~! F0 O
     elsif ((abs(val(X))<500.0*0.95 and abs(val(Y))<500.0*0.95 and abs(val(Z))<500.0*0.95)) then4 [+ _; ?1 [' L7 F- D7 m9 \
        refgyr := 500.0;
* S0 |" _  B/ O6 I$ `- G     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! X7 T; \( v) t9 n
        refgyr := 1000.0;
' v7 u1 K+ n) z$ X, W0 l8 |     elsif ((abs(val(X))<2000.0*0.95 and abs(val(Y))<2000.0*0.95 and abs(val(Z))<2000.0*0.95)) then9 }( h# `7 F3 P) \2 ~! n. d6 D& N
        refgyr := 2000.0;* Y2 w! ^; T  O" i/ R: `
     end if;
9 J+ V. |- z( A: A+ O9 G     if rng = GYRO_RANGE_125DPS then) e( [- N; e& w" F# m: M
        refrange := 125.0;1 `& Y' H3 u3 y) G; T/ q0 F
     elsif rng = GYRO_RANGE_250DPS then
4 a8 R9 I7 W# Y        refrange := 250.0;
8 R0 Z: X9 e# B) ?$ C     elsif rng = GYRO_RANGE_500DPS then
# K9 R9 y" {5 P5 |) a/ u& ^# E# C        refrange := 500.0;$ ]# o; t' D3 U. u- T
     elsif rng = GYRO_RANGE_250DPS then' k" b- p1 I2 d$ \2 N- U: T# ~
        refrange := 1000.0;
5 q/ _  p5 B% w, j* D9 b; n; c     elsif rng = GYRO_RANGE_125DPS then
- J  m* k+ P' P6 j2 p& ]        refrange := 2000.0;
: K% w0 I  k* I- m     end if;
/ q: _& R5 h. ?4 e8 }     weight := refgyr / refrange;
$ b. J# d! E/ W7 o+ y3 X; C     if weight > 1.0 then
5 B) k8 W$ l* M: U        return 0.0;, L: K! e. d7 v  R7 W) z' A
     end if;' @0 Z. @3 u# k' t) x- P6 y3 Y
     return refgyr/refrange;
" n: U; u" z; C& L& R1 ?  end GetGyroWeight;2 ~" ]7 ], v- s* N- [3 s+ Y  p
9 d! h& a. s) s' x  f7 q1 M
* a# v: }3 H! S' A& Q3 o& Z
使用权重,加速度值是所有值的加权平均值:
procedure FilterSuperIMU(facc   : out Sensor_Accel_Data;4 h* i3 M9 b2 \0 @3 v* i, U. x
                           fgyr   : out Sensor_Gyro_Data) is
" c7 r: N( O5 a$ N/ y  x     sumacc  : Sensor_Accel_Data;  -- cumulated accel value" D$ m! ], c+ g1 G  U
     sumgyr  : Sensor_Gyro_Data;  -- cumulated gyro value9 {8 q% |5 q$ S
     sumwacc : Float := 0.0;  -- cumulated accel weight, K# @* u; i- @9 [
     sumwgyr : Float := 0.0;  -- cumulated accel weight7 \2 `( ^& A) W0 N! ]; c
     macc    : Sensor_Accel_Data;  -- measured accel value8 q  S# T, G) ]* Z0 R
     mgyr    : Sensor_Gyro_Data;  -- measured accel value" W3 c/ t$ V. }
     mwacc   : Float := 0.0;  -- measured accel weight
* k: U9 T4 C5 V+ O. i     mwgyr   : Float := 0.0;  -- measured accel weight
; r4 f. I4 X1 e9 |2 ?  begin$ B9 K! l/ L# ?9 T7 X. n$ H. `1 l
     sumacc := NullAccelRate;
, u' W, v6 [3 {     sumgyr := NullGyroRate;* p, B! F* I- h1 ^& ]: J, v% z% j
     for i in Integer range 1 .. BMIs'Length loop         " ^7 t% M% B: y4 q9 ?% P
        -- get accelerartion
$ }7 c" H4 M. {% f7 I        BMIs(i).ReadAccelRates(macc);  X: @) y  b) _0 h& J
        -- get weight according to the range
, b$ B4 b5 [' ]% y% O! S        mwacc := GetAccelWeight(BMIs(i).GetCurrentAccelRange, macc);
1 l; f$ Z* H5 e6 w        -- apply 45° and inversion tranformation (geometry of the IMU)
4 n: a# s6 F% E6 H1 [5 g" c' K4 {        ApplyIMURotation(i,macc(X),macc(Y));. ^; ~" Z6 f8 f* K# H
        -- update the cumulated sum
% W* c' o# z" D7 e        sumacc(X) := sumacc(X) + macc(X)*mwacc;0 Q4 H$ f& ^; V6 O
        sumacc(Y) := sumacc(Y) + macc(Y)*mwacc;
3 E  _* C  r+ H  O  d        sumacc(Z) := sumacc(Z) + macc(Z)*mwacc;
  Z! O+ k4 p8 u# ]# ]) o        sumwacc := sumwacc + mwacc;
5 @0 v: ^; A4 q7 d" d! S6 h        -- get the gyro rate0 ~2 J  I4 L& H, `3 R2 \
        -- we don't rotate the gyro rate, no need* w( _4 }: m& l. L
        BMIs(i).ReadGyroRates(mgyr);. [( X5 R1 G: }3 I! G. s
        -- compute the weight according to the range  A5 E% f  H5 s
        mwgyr := GetGyroWeight(BMIs(i).GetCurrentGyroRange, mgyr);' _0 m/ |% P, I8 e/ F
        -- update the cummulated weighted sum
# z0 j0 D/ o/ k8 Q% G! H/ i3 ~        sumgyr(X) := sumgyr(X) + mgyr(X)*mwgyr;
1 L. E% ?) ?3 {- O4 C' k8 V        sumgyr(Y) := sumgyr(Y) + mgyr(Y)*mwgyr;$ r, O7 v- S/ h* t
        sumgyr(Z) := sumgyr(Z) + mgyr(Z)*mwgyr;
$ a, ~" [9 m" x( q, R        --
4 o  u: ]- r% V( |        sumwgyr := sumwgyr + mwgyr;
0 I% t5 h/ ~! A, a     end loop;
- |  h3 Y( s5 u/ o" r9 l& u; [     facc(X) := sumacc(X) / sumwacc;: }9 ?2 d  y5 h  k, h+ l
     facc(Y) := sumacc(Y) / sumwacc;
+ f! b. D4 P' ~5 \; F2 [- }     facc(Z) := sumacc(Z) / sumwacc;
. R' C* X, p. C0 ^0 n     fgyr(X) := sumgyr(X) / sumwgyr;) I+ C1 u* O- u* E/ A0 C# M
     fgyr(Y) := sumgyr(Y) / sumwgyr;8 N+ g' o0 f0 L0 K4 }
     fgyr(Z) := sumgyr(Z) / sumwgyr;
7 a; T0 T  G. T  x5 c& t  end FilterSuperIMU;4 `2 R2 O) S! @5 E# j9 a% f5 r
" h# V+ c1 `# n) T5 m1 ~6 j

9 W$ m* j8 i9 B; y3 k
估算代码:
我用一个简单的互补滤波器来估算音高和滚动。我们从IMU获得加速度和陀螺仪速率数据。
代码在这里:
3 r5 ?/ B2 O# \* [- l5 _
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;
4 c2 x! M  z* C+ ^1 \! x
第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  
3 U0 G, q, x, s* ~, w
用于OpenOCD的配置:
- 本地主机的端口为3333
- 我使用了来自openocd github 的stm32f 74discovery的配置文件。
42.jpg
用于OpenOCD的配置

- o4 v: H5 N4 v$ X7 }5 c2 ?& I, n. K( a( ^
使用带有Analyzer2goCYUSB3KIT-003SPI进行分配
Analyzer2Go只是一个用于小预算的神奇工具。结合电路板CYUSB3KIT-003(45 $),您可以在200MHz采样率下使用功能强大的16x通道分析仪!
对于我的情况,与SPI / UART的交换低于10Mhz,并且读取Nucleo板的MCO(在100MHz下的PLL),这就足够了。
SPI测试
SPI的速度配置为STM32F746的6MHz(波特率DIV 32)。
我可以使用来自BMI088实例的SPI使用以下过程正确获取IMU运动数据:

4 w6 l% S5 F. U$ m
  procedure ReadAccelRates (This : in out Six_Axis_Imu;                            Result   : out Sensor_Accel_Data);
' i$ w( q$ z3 `) v8 P  procedure ReadGyroRates (This : in out Six_Axis_Imu;
; t5 M* G1 w! w& c1 Z  R! O                            Result   : out Sensor_Gyro_Data);# J" I) L  y) M

" x1 H0 N, m* g3 H) ^% V
8 i5 ]! c$ T% G' R
第8步:PLL时钟测试:8 B) O. W+ l  _; Q% B
: l( m/ E1 o3 g4 T% Y
) K9 J& P/ o% Z' a" `  \
在核板中,外部高速时钟(HSE)不是来自25MHz晶体(如Adacore内置STM32F746Disco),而是来自ST-Link芯片@ 8MHz。
, ?, ]7 _( ?$ h" S经过数小时的调试后,我最终修改了adl_config.ads和s-bbbopa.ads(作为workarround)文件以设置HSE时钟的正确值。我终于为Nucleo-F746创建了一个新的BSP,而不是因为这种差异而使用stm32f746disco。
+ l8 `1 {3 X5 t$ `% \现在时钟正常运行,测量显示时间:4 ?+ |2 [( h, n7 w0 T4 s/ o6 ?
在调试模式下读取加速值需要35us 。
$ b( s/ l5 T) Q$ @6 V" G' l$ ]- u2 X) C( f! V. e( H

1 U; F2 x. K7 t8 k/ R7 N
43.jpg
' T; v. e) q9 u/ @7 I+ B
在从IMU读取值结束时,我使用流动代码切换引脚PG1:

& g; ]/ T6 B$ [
  --------------------5 P6 |3 D/ s% `, B9 j+ H/ L# {
  -- ReadAccelRates --
  r9 H: v- v3 K- Q  i9 h# ~- S8 O  q  --------------------
: T& c& ]% P1 F5 `- y  procedure ReadAccelRates (This : in out Six_Axis_Imu;
' l" V; M# p; ?! A                            Result   : out Sensor_Data)1 ~7 [! S- _+ N% d. K0 x
  is! s. s% C; [1 @5 x
     Received        : SPI_Data_8b (1 .. 6); -- 2 bytes per axis
( B  @" N3 o% p, }0 }. d6 H0 }     AccelRates : BMI088.IMU_Rates;-- todo create AccelRate type  C7 e/ T# j" ~4 O- a
  begin
" R" E; p" E  {7 `$ x3 |' u  G     PG1.Set;7 @* E2 m2 l( ?3 Y  N( f
     This.AccelRead_UInt8s(ACC_ACCEL_DATA_ADDR,Received,6);6 `) \  o1 d6 Z1 O1 z9 u
     AccelRates.X := As_IMU_Rates_Pointer (Received (1)'Address).all;( L0 D" C( J" [( {" X* [
     AccelRates.Y := As_IMU_Rates_Pointer (Received (3)'Address).all;
5 _' m6 z5 r& [- ?. c8 M$ t     AccelRates.Z := As_IMU_Rates_Pointer (Received (5)'Address).all;& j/ C' f: e4 w
     Result(X) := Float (AccelRates.X) / 32768.0 * Accel_Range_MSS;* ^8 y: r) _0 Z% e9 m
     Result(Y) := Float (AccelRates.Y) / 32768.0 * Accel_Range_MSS;7 }4 q. |/ d. @- ~# I$ V/ A
     Result(Z) := Float (AccelRates.Z) / 32768.0 * Accel_Range_MSS;
$ g0 F3 R0 V! I# k# a' r     PG1.Clear;; M) S7 q4 V4 r+ }; A. z
  end ReadAccelRates;. u8 ^: u. v( D' n! ?; J' M( q

7 i& L9 w, f% n: V% u
Reading在调试模式下,完整的陀螺仪值需要34us
44.jpg

% x: b$ T6 J7 R+ q; z1 Q; R/ b, T* ^
   -------------------8 r; X/ h9 @6 M
  -- ReadGyroRates --
8 x7 r7 _) i- M+ w2 n" \  -------------------
6 C, l4 t5 m/ o" `5 v7 e  procedure ReadGyroRates (This : in out Six_Axis_Imu;4 ^4 L. E5 @/ s, K
                            Result   : out Sensor_Data)( s9 z' ^' H) E& E
  is
1 h' V; Y( N6 L& u- P     Received        : SPI_Data_8b (1 .. 6); -- 2 bytes per axis% ^' p/ C& f# {4 W1 K
     GyroRates : BMI088.IMU_Rates;-- todo create AccelRate type
* ]. `$ g5 B0 E8 }" b: u, I  begin. Q* f. v& ~3 s/ A9 g
PG1.Set;
/ |# e9 v6 C! b2 U' A  ^9 A     This.AccelRead_UInt8s(ACC_ACCEL_DATA_ADDR,Received,6);: d7 q7 r2 J" j; K1 k# s0 Z
     GyroRates.X := As_IMU_Rates_Pointer (Received (1)'Address).all;
$ K( j7 l- Q8 q5 L5 z     GyroRates.Y := As_IMU_Rates_Pointer (Received (3)'Address).all;3 q0 l- |3 Z- M' M& Z: X' O
     GyroRates.Z := As_IMU_Rates_Pointer (Received (5)'Address).all;
2 D, E, `, o3 {. A! ^3 p     Result(X) := Float (GyroRates.X) / 32768.0 * Gyro_Range_Rads;
$ p$ @0 V' [% D" Q+ j     Result(Y) := Float (GyroRates.Y) / 32768.0 * Gyro_Range_Rads;! j2 N: {7 j8 P) n" E
     Result(Z) := Float (GyroRates.Z) / 32768.0 * Gyro_Range_Rads;
. E) d! J% z1 h% [! U# ]PG1.Clear;# _3 t- K( u# Q3 y* Q2 W- U! `$ U
  end ReadGyroRates;' @) m+ B  G% d" N+ @9 ?- Y

* |6 z) A8 y  [
Of 对于真实用例,我需要将编译模式设置为生产以进行正确的优化。

, q( s" ^# N$ o& \& X5 u# C4 M* O  M! w
步骤9:使用UART绘制数据
为了可视化输出数据,我想使用UART在超级惊人的酷系列绘图仪中可视化它:https://github.com/CieNTi/serial_port_plotter
45.png

& F* \# i1 c  f: ~/ U4 Z
现在的问题是将Float转换为String ..以使用UART将其发送到Serial_Port_Plotter工具。
为此,我在这里使用神奇的单词'Img in Ada 将Float转换为String。然后我逐字节地将字符串发送到UART。
如果要发送一个值:
% t. [6 ~+ v2 J6 S- 发送“$”
4 H% c* }8 F( m8 l- \7 K) R( k1 Y- 发送浮点值" {9 R' x8 e& l' ^3 C3 v$ H! m, O
- 发送“;”
如果你想发送多个值:
/ h' G( P5 h# S) B- 发送“$”开始
4 O+ k" J; z, X! p3 `/ j2 ?- 发送浮点数值1 * F/ M6 v3 _  m! s
- 发送空格“” 1 K$ O0 y& Z4 Y* V/ @* n3 V
...
6 m  p. d1 g  G6 v, M& y9 Z4 _- 发送浮点值i
# X% [. V/ u8 G7 P4 L! @- 发送空格“”
2 @) Q! Q- |8 b- 发送“;” 终止

2 _+ {" m( N% j6 W6 \
为了能够向绘图仪发送加速度,我使用了以下代码:

0 u4 H* T$ P6 B2 Q3 u: H% c0 j
  type FixedFloat is delta 0.00001 digits 18;---
( X1 `! h4 B2 ]0 T8 a     data_1B(0) := UInt8(36); -- '$'* X( B" v8 q& s' W( }( R
     UART_OUT.Transmit(data_1B,status);
& J0 q5 m1 [" T4 l/ ~" Q     for ch of FixedFloat(AccelRates(X))'Img loop
! X/ u; ]" ?2 P' g) z+ K        c := Character(ch);& m" r* v. U1 B1 j* U& |* z
        data_1B(0) := Character'Pos(c);
. D5 q: L5 K; N1 j$ }        UART_OUT.Transmit(data_1B,status);( M8 a: k9 Q& b( @; `5 r
     end loop;# g. H* W- u9 q, Y% Y4 K. [1 \
     data_1B(0) := UInt8(59); -- ';'! c% h/ _' D/ G5 n" w& g) {
     UART_OUT.Transmit(data_1B,status);
0 R; Z2 S; T0 d% c' @& L
" d$ U# s9 g/ _. U) o& m
- W: w9 C. o+ t5 l7 y" `& u
结果非常令人满意,在下面的快照中我实时可视化Accelerometer(X)值:
46.jpg

) z* F: t2 d6 d
创建驱动程序后,该数据通过UART端口正确发送:
47.jpg

# ]5 Y, d7 ]5 k: t8 o8 k
UART制作驱动程序
不幸的是,在STM32F7器件中还没有UART驱动器(仅适用于STM32F4)。
要为UART创建驱动程序,我从STM32 F4 的stm32-usarts.ads/adb开始。我修改了文件以符合STM32 F7 的SVD 。我还要修改STM32-Device.ads/adb以包含STM32F7的UART / USART定义。
它适用于传输9或8位大小的字节。我没有测试它的DMA风格(因为从未做过
! `0 ]& K' V3 {& F; a
代码广告:
------------------------------------------------------------------------------
- i. S+ \5 e5 t! E$ f4 @1 \9 C--                                                                          --
- d# {" ?9 c  l. {7 ~8 z' {7 Q# [--                  Copyright (C) 2015-2016, AdaCore                        --
3 H- v4 M, \, N  I--                                                                          --
+ q0 D; T, y) ?--  Redistribution and use in source and binary forms, with or without      --9 u$ O, Z  ~% ?8 Q7 [2 l
--  modification, are permitted provided that the following conditions are  --# @; ?4 V" ]5 j
--  met:                                                                    --
4 @- m: y! n% o% o- L--     1. Redistributions of source code must retain the above copyright    --; a/ F) x8 ]( m9 _, n; e* h
--        notice, this list of conditions and the following disclaimer.     --4 D1 a& [( B+ U7 L; ]
--     2. Redistributions in binary form must reproduce the above copyright --
, [- F4 {. q2 V; k& e# v--        notice, this list of conditions and the following disclaimer in   --
& g( z, B' y  `1 }. M--        the documentation and/or other materials provided with the        --
5 ~6 r$ {' t/ O; U7 r9 R* V--        distribution.                                                     --
& \+ l8 Q4 \& C) d  u, `1 Q--     3. Neither the name of STMicroelectronics nor the names of its       --: E( D/ @8 Z- O6 T& B
--        contributors may be used to endorse or promote products derived   --
: x" C+ M# J$ w- U/ `3 F--        from this software without specific prior written permission.     --8 f5 w; q( [* z2 b
--                                                                          --* m5 q6 T" s* m0 r5 }- u% X- B$ D
--   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    --) K# {3 A2 F2 G3 y  Z
--   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      --$ P+ p* l( p4 T: G( f" M8 b% B
--   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  --
+ u, s5 r( [! j--   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   --
0 S( P9 N6 A5 v0 v--   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
$ Y$ w9 A' |; m$ ?1 c--   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       --# m2 q% P& F3 B9 l7 M
--   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  --$ {4 {0 C, M- i* \+ s* ~6 D
--   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  --
* y9 q# @0 f, n2 d--   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    --
, O. M4 p! B! F" R--   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  --3 g) \$ x. z( K& `% n1 W* z5 P
--   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   --
$ j. A1 e5 Y) `% \3 A5 Z--                                                                          --7 f5 _& Y1 P) G: L' E
--                                                                          --+ v( p- D0 ^; S  S: n4 v' f9 A2 D
--  This file is based on:                                                  --
- J! \, s9 u( O2 m--                                                                          --
0 G: k# k! q  W5 d) Q$ W! o; x--   @file    stm32f4xx_hal_usart.h                                         --4 }7 R! s9 O( t# m+ q* A
--   @author  MCD Application Team                                          --
6 P3 U  e+ g! ~1 ^" P--   @version V1.1.0                                                        --
: D: m5 C/ ?( o* \( b! C9 D--   @date    19-June-2014                                                  --: |$ c3 w) K) [8 Z( D. |9 x
--   @brief   Header file of USARTS HAL module.                             --' e. Y; \6 C" N" @& Q5 G2 [
--                                                                          --5 z) [) ~. r/ Y, \6 l" P
--   COPYRIGHT(c) 2014 STMicroelectronics                                   --
1 n4 _- a! G( }, d6 p------------------------------------------------------------------------------
+ ?& s7 ]2 g' b% J--  This file provides register definitions for the STM32F4 (ARM Cortex M4F)# U0 ^( J. A# s# ^* s0 ~. e
--  USART from ST Microelectronics.
  S& b  [7 C' L  H, j3 U--  Note that there are board implementation assumptions represented by the6 a, @5 X6 ~) }1 x& A
--  private function APB_Clock.
% ^, E8 n) Z8 K+ Bwith System;" s" ~1 s; L) }4 a. E, _3 B: P7 m
with HAL.UART; use HAL.UART;
* t7 A8 H# G3 x8 R* ^+ X6 Z, @private with STM32_SVD.USART;
/ h' C! D4 V/ Vpackage STM32.USARTs is
- D. ?. F4 w# D% d& f4 e# e- T7 b' R  type Internal_USART is limited private;, y  f. I. k4 p- n/ W( e
  type USART (Periph : not null access Internal_USART) is
6 [! {* K' v4 \    limited new HAL.UART.UART_Port with private;
: ^, Z- [  E/ p5 N; w$ h- {  f  procedure Enable (This : in out USART) with# E7 k- C2 d; a
    Post => Enabled (This),
7 Y5 o# Q/ w9 r7 V; o1 [: [) P    Inline;
# F: y+ M0 E( ?# X% T! j4 F4 m  procedure Disable (This : in out USART) with
7 X# j: J; e4 z: _8 o& p* ?    Post => not Enabled (This),9 v$ {; j' X0 a8 S
    Inline;
- \6 C3 i/ w5 U/ A  function Enabled (This : USART) return Boolean with Inline;; D8 P1 i( r, ~3 U! t0 s0 h# l. q
  procedure Receive (This : USART;  Data : out UInt9) with Inline;: j, g& j/ S: l; e6 W
  --  reads Device.DR into Data4 t# ?2 g- I% J0 X  P5 L0 h0 ^, j
  function Current_Input (This : USART) return UInt9 with Inline;
) P! z+ t7 _3 V  ?  --  returns Device.DR
* g; H9 Y( @) F" Z9 k  procedure Transmit (This : in out USART;  Data : UInt9) with Inline;
/ I' }% J! M- o. d7 ^& O  function Tx_Ready (This : USART) return Boolean with Inline;
  F# a( J: O" e( q  function Rx_Ready (This : USART) return Boolean with Inline;
* J' I( S1 Y; P) u  type Stop_Bits is (Stopbits_1, Stopbits_2) with Size => 2;; Z$ \) p1 I' {0 F- ~
  for Stop_Bits use (Stopbits_1 => 0, Stopbits_2 => 2#10#);
8 M' O/ i  s* Z: K3 n  procedure Set_Stop_Bits (This : in out USART;  To : Stop_Bits);
# W. k4 c' ^9 ]; n. a5 {  type Word_Lengths is (Word_Length_8, Word_Length_9);
# H5 P) s- _5 |0 r& O' n  procedure Set_Word_Length (This : in out USART;  To : Word_Lengths);5 j% v* R$ J( F" Q1 X
  type Parities is (No_Parity, Even_Parity, Odd_Parity);; w) Q; M8 E4 H
  procedure Set_Parity (This : in out USART;  To : Parities);
, b8 s+ _1 k! b9 {7 g% J  subtype Baud_Rates is UInt32;; ^- W" ?8 X# V0 O" X
  procedure Set_Baud_Rate (This : in out USART;  To : Baud_Rates);* M- G; N4 Y  y  A* Q9 Y/ f
  type Oversampling_Modes is (Oversampling_By_8, Oversampling_By_16);
9 ]: U, ~2 [3 F& m* x( p  --  oversampling by 16 is the default
7 \' A& N: R% i: i: l  procedure Set_Oversampling_Mode: G* x8 {5 Z; {9 c2 s, Y' U
    (This : in out USART;/ b/ J/ n3 Q; l( M
     To   : Oversampling_Modes);
* Q. c" T. t8 V7 d  type UART_Modes is (Rx_Mode, Tx_Mode, Tx_Rx_Mode);
- Z& A4 O, D# y1 m) P  procedure Set_Mode (This : in out USART;  To : UART_Modes);
( P! O5 g  g% j6 O' k1 h  type Flow_Control is
# c) A1 X# \6 I9 \. o    (No_Flow_Control,
: g* f) X: f! Z     RTS_Flow_Control,+ B; Z3 `9 ^0 U; O6 N
     CTS_Flow_Control,
" \* p, M' W$ m5 I6 B3 l% l     RTS_CTS_Flow_Control);& m% I# _; Z( t. H, P
  procedure Set_Flow_Control (This : in out USART;  To : Flow_Control);
/ B' R/ `' h$ R# G. Y  type USART_Interrupt is
* J; i# q$ s  R    (Parity_Error,
( b3 `. f: t3 z6 P) u     Transmit_Data_Register_Empty,) C8 ^  b, ]+ M% w  U0 d9 l
     Transmission_Complete,! l0 K" k- o% D1 D3 [7 \! [- d
     Received_Data_Not_Empty,4 ~% ^7 Q1 J4 j
     Idle_Line_Detection,
4 W$ e/ T6 }( b; `! ?( @     Line_Break_Detection," q) [! A$ F5 T8 ?, b" B, w
     Clear_To_Send,; }5 A: |/ I. b$ g% Q9 K
     Error);
: \7 _# K) x( k4 N2 n+ V  procedure Enable_Interrupts
$ x. ?% b( J) |* q5 y    (This   : in out USART;
8 @/ W4 S1 R  D4 N) p     Source : USART_Interrupt)
- u+ c6 Q4 G5 k1 g/ D% G0 j    with
. _; s5 S# k, K* S      Post => Interrupt_Enabled (This, Source),* h* M1 x: w8 k8 i/ j
      Inline;% d# ]# y* Z$ E0 K& D
  procedure Disable_Interrupts
% y  F1 `/ N" c' M0 |2 X    (This   : in out USART;6 l8 A1 y- \3 F& L) g' f
     Source : USART_Interrupt)" Z1 x. P. t  R4 {, B- u, W
    with7 F& a7 @' d2 e4 [1 l6 f- K4 i
      Post => not Interrupt_Enabled (This, Source),
' l8 p1 b2 L; r- y  ^       Inline;8 v" b6 S! ]9 d, ]
  function Interrupt_Enabled
7 O8 A6 t/ f: [9 n" E3 @! a3 H    (This   : USART;
9 O5 p2 D; Y6 n* V4 N1 w1 c     Source : USART_Interrupt)
. w. N5 D0 l6 C/ N. N4 ?  m     return Boolean
) n5 Q- W4 f- h- e    with Inline;
, I1 V7 X/ b% l  j7 G7 ^! }  type USART_Status_Flag is
, `; r7 q! Z0 T; `! I3 i    (Parity_Error_Indicated,
% }% x- v# T4 s( r     Framing_Error_Indicated,5 s7 k( |( @( q/ I# V
     USART_Noise_Error_Indicated,
' ~# k; z& [6 A  N  }     Overrun_Error_Indicated,
1 |% b" N" N# R; }$ {# }+ p     Idle_Line_Detection_Indicated,0 r2 ~' ], v! u& U0 J4 R" c
     Read_Data_Register_Not_Empty,
' C% `- A, @$ ~  m. b     Transmission_Complete_Indicated,: i9 j1 m' M9 K) R" B. D" v! y
     Transmit_Data_Register_Empty,
, f6 P2 S& Z1 d& E     Line_Break_Detection_Indicated,
" _( K' M: O# z" [2 a     Clear_To_Send_Indicated);
4 }4 Z/ B3 p& w$ \  function Status (This : USART; Flag : USART_Status_Flag) return Boolean3 [- d7 }1 ]( O4 E4 f! @) }
    with Inline;/ d. x# A: V1 x! U2 M3 \, K
  procedure Clear_Status (This : in out USART; Flag : USART_Status_Flag)2 ^+ }7 f; F6 A$ d2 ~6 J$ p
    with Inline;! a- i2 P: K+ r
  procedure Enable_DMA_Transmit_Requests (This : in out USART) with
; b) b7 g/ A5 b) h( s% X1 t    Inline,
' o7 X/ _8 b2 P. H: P$ Y! p7 C9 t    Post => DMA_Transmit_Requests_Enabled (This);
* G7 v0 t! P( O  procedure Disable_DMA_Transmit_Requests (This : in out USART) with
9 d9 @; T: `* z- i/ o) E% i  ?    Inline,
; A2 ]: c; A9 i* N, \% b1 c    Post => not DMA_Transmit_Requests_Enabled (This);5 ^8 L3 r) w( E0 y  ~
  function DMA_Transmit_Requests_Enabled  (This : USART) return Boolean with
8 N6 N' \' K/ I" Z8 @' H    Inline;
2 L5 c. f  k# J8 \- `' Z8 b& v  procedure Enable_DMA_Receive_Requests (This : in out USART) with, D. d8 Z/ j9 y9 F, a( s; ]
    Inline,- C- X6 C5 Q$ C' l
    Post => DMA_Receive_Requests_Enabled (This);! e3 r) C7 d2 T# ~0 w
  procedure Disable_DMA_Receive_Requests (This : in out USART) with  F3 ?9 M. ^' }( G
    Inline,
8 _: V: b  |, q1 ?1 h* `7 m( o    Post => not DMA_Receive_Requests_Enabled (This);
. ]: d2 n, s% A! Z" [" P5 u  function DMA_Receive_Requests_Enabled  (This : USART) return Boolean with
- z; v4 g2 C" G4 t( }7 `( ^+ e    Inline;
1 A& q( f- V0 s! n& c" H# i  procedure Pause_DMA_Transmission (This : in out USART)
" y2 ~4 S) u& j1 E( g! {3 e, ]. ]    renames Disable_DMA_Transmit_Requests;
% i) \  A# P" f) j  procedure Resume_DMA_Transmission (This : in out USART) with4 p+ D9 B" a% I6 x: i; k
    Inline,. Z1 c9 D' T4 B8 g# _! Q
    Post => DMA_Transmit_Requests_Enabled (This) and
$ \! X! T8 }2 o' P9 i            Enabled (This);0 g" I% I( P1 C6 c0 P
  procedure Pause_DMA_Reception (This : in out USART)
0 b$ c) n/ i" }' V0 R1 M    renames Disable_DMA_Receive_Requests;1 D, N& n9 M4 W* i
  procedure Resume_DMA_Reception (This : in out USART) with% f: J3 }9 V+ Q( }# e; d, Z$ J+ R
    Inline,
* _/ A% ~! C7 z    Post => DMA_Receive_Requests_Enabled (This) and0 r% l% f6 s8 u2 o; o2 H
            Enabled (This);! r' h5 Z8 H- Y! Z8 B8 D+ M: n1 t
  function Data_Receive_Register_Address (This : USART) return System.Address with9 m$ A$ |& l- P; q- ]
    Inline;5 I0 q  x: v/ r! W% ~: }
  function Data_Transmit_Register_Address (This : USART) return System.Address with/ I1 l6 o1 y" @' Q6 P2 F7 _
    Inline;
, h* A8 E* I* r) z  --  Returns the address of the USART Data Register. This is exported
% q, E2 z) A* I  h; Y) L  --  STRICTLY for the sake of clients driving a USART via DMA. All other
+ f8 p. k( r. M4 V) U. C  --  clients of this package should use the procedural interfaces Transmit
- z! ^9 v7 Y' I! c: V) v$ L7 U% `4 J  --  and Receive instead of directly accessing the Data Register!
% w# w1 t( d6 k/ d: p  --  Seriously, don't use this function otherwise.
6 |2 U/ i3 j' |- T7 T, R3 \  -----------------------------
* q" {3 d9 I& G: D: R+ b  -- HAL.UART implementation --/ V6 F) [% N; }
  -----------------------------
( c% Z4 z! c7 \% Q, x* K# j1 R3 m  overriding0 b5 b: ?+ h- T) I) Z
  function Data_Size (This : USART) return HAL.UART.UART_Data_Size;
( w; S, Y/ O/ a. D& I1 M1 `  overriding+ z/ @" d; \5 R( a" n7 k
  procedure Transmit
$ F+ F* u. I* t2 m( `    (This    : in out USART;3 f9 r; S# d2 g: m# g
     Data    : UART_Data_8b;# Y" Q0 T% g: t$ a( `' z3 K) P- p3 ~
     Status  : out UART_Status;
  C5 `+ `/ ?4 E, x4 U2 X4 V, `     Timeout : Natural := 1000)
0 G, d7 b* V' |3 q& H) ^    with! x& \+ S0 \" e! n
      Pre'Class => Data_Size (This) = Data_Size_8b;' W( o3 q) I% u% r" M  I# T& x+ G
  overriding
) _0 Y/ M- n: a  procedure Transmit% h% n. q+ c" c  G4 g
    (This    : in out USART;
. ^1 `/ k9 v0 f& v& C! |3 H     Data    : UART_Data_9b;
, c) Y, S/ X2 }     Status  : out UART_Status;$ r: T) e! a8 g4 _" C
     Timeout : Natural := 1000)
* J& E* z1 I6 s4 u2 K: q    with4 y5 l. [: G6 E% a$ @5 g
      Pre'Class => Data_Size (This) = Data_Size_9b;0 o% W2 Y7 P% S
  overriding3 M# @% u1 u' i+ Z+ K
    (This    : in out USART;
1 z1 T' j1 X9 v5 _9 s     Data    : out UART_Data_8b;
& z* `- m" o7 ]( ?     Status  : out UART_Status;
  Q5 v. l0 L2 m6 I. x     Timeout : Natural := 1000)
( J* C+ i2 M9 K' K# ^: c% U2 D. T    with
, R, Z4 k4 Y5 W      Pre'Class => Data_Size (This) = Data_Size_8b;
/ ]4 G$ y7 c( K  overriding
$ |* W' a6 J' k- N# }  procedure Receive
  G* J, c0 n# k; x+ O' s( V    (This    : in out USART;
6 G7 _! r2 M. U% V3 \' x     Data    : out UART_Data_9b;
2 f5 [) |0 J$ Q     Status  : out UART_Status;
7 F( Y6 b7 |: k3 h     Timeout : Natural := 1000)$ Y- |" T$ [0 E  p
    with
* u' L! z7 Z1 W8 W3 a      Pre'Class => Data_Size (This) = Data_Size_9b;
  Z# a& ?) n; [! T) i: W: Zprivate
) _- v- ]! U* H5 A8 ~" q  ?2 l  function APB_Clock (This : USART) return UInt32 with Inline;
0 x6 Y0 ^6 h" J: m+ u  --  Returns either APB1 or APB2 clock rate, in Hertz, depending on the' f9 i0 M$ D& ?! J, v7 ]; i
  --  USART. For the sake of not making this package board-specific, we assume
6 t  u( O; B* U& x% p: w4 d  --  that we are given a valid USART object at a valid address, AND that the
  h# k& z# Y* P% z, t  --  USART devices really are configured such that only 1 and 6 are on APB2.
# B/ I) C7 F8 F+ p. K2 z! o9 b0 Q  --  Therefore, if a board has additional USARTs beyond USART6, eg USART8 on4 V- e: k" n0 A: r6 m5 P7 V% K) C
  --  the F429I Discovery board, they better conform to that assumption.
. Q7 q3 Y! |7 C$ E  --  See Note # 2 in each of Tables 139-141 of the RM on pages 970 - 972.  O# S3 l. u) K* b7 F* c
  type Internal_USART is new STM32_SVD.USART.USART_Peripheral;- E3 J  e8 Z5 b1 R! e
  type USART (Periph : not null access Internal_USART) is
$ [8 s* v: M5 t" n" a    limited new HAL.UART.UART_Port with null record;
* k& B/ g! P5 Pend STM32.USARTs; , n/ \$ B. S% R
& y1 k/ q  k. V! [+ D  O* s
代码adb:
------------------------------------------------------------------------------/ P) W0 m" j! a
--                                                                          --
2 }' q' E' K/ U" T, D--                  Copyright (C) 2015-2017, AdaCore                        --
( M& u1 c# p4 @7 i--                                                                          --* d8 _1 h. o! t
--  Redistribution and use in source and binary forms, with or without      --
  e! Z/ T5 s9 K7 t3 g* c: o. U: N" q--  modification, are permitted provided that the following conditions are  --3 Q9 K) v7 j8 g1 d2 N
--  met:                                                                    --& K8 C  ~* S1 b6 M' m
--     1. Redistributions of source code must retain the above copyright    --
) D! S! ~( C! c/ P( q% `, j. M--        notice, this list of conditions and the following disclaimer.     --
2 i- }9 A' I% u9 x" g# q$ k--     2. Redistributions in binary form must reproduce the above copyright --
( a$ x- w! @8 F9 n5 j* h--        notice, this list of conditions and the following disclaimer in   --0 e# R& J0 ~6 `, W2 r
--        the documentation and/or other materials provided with the        --
! {* g6 z: Y! u4 Z--        distribution.                                                     --1 _! `# ^0 X1 O. K
--     3. Neither the name of STMicroelectronics nor the names of its       --$ m* b& i- S* v# t9 R* V
--        contributors may be used to endorse or promote products derived   --9 q+ W) Y8 }6 y! w7 }7 w
--        from this software without specific prior written permission.     --* {* M& x4 k4 _, r7 i" x/ H  o, F. o
--                                                                          --
$ ?% ^$ Q- ]0 P" L--   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    --+ @  d: \8 K, k4 [. r7 `4 ~
--   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      --) s: z1 f( A/ V
--   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  --
. i! w7 @# ~" J4 N--   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   --
& S' o; C+ I0 T- A! g--   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
8 h3 a1 P! `2 _7 n4 j6 X8 I--   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       --
, F5 q( T! S1 K! o5 x& ?# [5 _--   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  --2 ]( @1 V' J" f; a9 L
--   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  --  S: q: m8 B, K1 u
--   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    --
8 P. F/ v& C, _6 p- _1 @. M--   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  --& ^: F; h6 d$ l9 F
--   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   --# w6 Q8 {+ E+ U& p- r0 z# s
--                                                                          --
6 h& q; Z0 o9 \! m7 ^( |6 m--                                                                          --! J8 B% r$ `# A1 W+ E6 |  o
--  This file is based on:                                                  --4 L# p8 Z6 }3 S8 ]* G
--                                                                          --% i& P% W1 v5 W1 Y. Q, ^1 \" _
--   @file    stm32f4xx_hal_usart.c                                         --6 p2 D4 Z7 }; j% Y; z: |
--   @author  MCD Application Team                                          --
" z0 Y  Q/ o& M: T( G, f" D--   @version V1.1.0                                                        --
/ X  ]8 E+ W& x" c8 n; L--   @date    19-June-2014                                                  --
5 F5 Y7 G/ s  W7 r; u* C--   @brief   USARTS HAL module driver.                                     --
( z2 g  c' ]9 W--                                                                          --3 Z9 _* T2 [" K9 p: Z9 R, w% Y; T
--   COPYRIGHT(c) 2014 STMicroelectronics                                   --- C0 z* b$ l, \4 ?! Q( p0 t
------------------------------------------------------------------------------
/ c9 a8 N! u" H$ I: J* T/ {with System;          use System;  H% Z& x1 p5 G4 `8 [
with STM32_SVD.USART; use STM32_SVD, STM32_SVD.USART;. A( N' e/ s. e9 c$ J
with STM32.Device;    use STM32.Device;$ G- p1 Q7 e: B& j
package body STM32.USARTs is' j/ r6 Q, m. q( H0 n9 p* R0 s  N
  ---------------
/ `  b4 _+ g+ |5 c. S  -- APB_Clock --
2 D' m5 w/ z/ a7 h' s. H  ---------------
& K& w! I) o5 Y+ o8 z% A; d# t  function APB_Clock (This : USART) return UInt32 is
: E( H8 n  B8 m) P9 l     Clocks : constant RCC_System_Clocks := System_Clock_Frequencies;6 n, h- {4 F0 S0 p$ d! V
  begin* s1 W& v3 U/ z: R" H
     if This.Periph.all'Address = USART1_Base& `  k% J: |# v. c
       or; H' X" j/ p* c" F
        This.Periph.all'Address = USART6_Base
: m; I, q  J2 Z: @" ?     then+ N# W  j; A9 `  Y3 k0 M& @
        return Clocks.PCLK2;
7 x: l( l0 W5 n6 t  E' F     else
/ j" W. V9 K0 `" j" i        return Clocks.PCLK1;! m1 R4 U# N7 S* Q- x
     end if;9 Y3 L) C. T7 S: Q% C
  end APB_Clock;0 V- r  P3 h- E( Z, k
  ------------
+ g5 W/ ^) l; y  -- Enable --
% h( T' F4 i5 `  ------------
3 Y9 c* }0 j! J2 W  procedure Enable (This : in out USART) is
( @* J* }( Z* P8 t1 t3 _  begin
1 m9 A2 @+ e1 t0 a     This.Periph.CR1.UE := True;  L3 X7 W# t$ y# X3 |5 C, ?; P
  end Enable;
; l" y4 }+ Z* ~9 i, Q' \* D  -------------% j6 N; h6 Q* m6 X' O
  -- Disable --1 ?. }6 ?) ^2 D3 ^7 l1 c: V$ H
  -------------# j% _$ D  ]: [* j( d: i; V  N
  procedure Disable (This : in out USART) is% s3 I$ M- V+ Z& o$ Y
  begin
$ H9 U  h" `) _8 W     This.Periph.CR1.UE := False;& @# A2 j- F. `' T* p+ S0 R
  end Disable;" U9 W4 b7 D4 |
  -------------
: n$ q( |+ i9 D9 n  -- Enabled --
" i: K, q% O! f  -------------/ q! O5 t4 N- u  n
  function Enabled (This : USART) return Boolean is
& T* P1 Q- a# U" |    (This.Periph.CR1.UE);) [6 M5 i" k4 M6 o6 |+ t
  -------------------- }( O2 x8 F) {( O4 q
  -- Set_Stop_Bits --
+ q$ C& E1 E5 @9 F! ^' C) H/ {  -------------------
0 Q  F  p" J% G  procedure Set_Stop_Bits (This : in out USART; To : Stop_Bits)
) d. W7 R: D' h3 i% E  Y7 }# D  is
2 M: z5 a8 x% V' J+ e  begin. ~7 Y; [! i1 R" C
     This.Periph.CR2.STOP := Stop_Bits'Enum_Rep (To);! f0 m! s- T: B, Z) |" }3 p
  end Set_Stop_Bits;
* Z4 @- T: k/ s4 f' S% t  ---------------------
* x4 H0 j- p+ [/ t! h  -- Set_Word_Length --" K$ U9 _" N2 r0 d5 F# G* _2 O5 g- D
  ---------------------: r9 O# P; C+ h; N
  procedure Set_Word_Length. d4 |  R, l# T" E
    (This : in out USART;( c5 L( J7 T' T& M- e
     To : Word_Lengths)
1 _* M" n3 s1 T/ P& f7 g  is: t( O3 V! n$ X" T, V2 Q
  begin! W6 Q( @1 t1 W7 X) f1 q' z, R
     This.Periph.CR1.M0 := To = Word_Length_9;6 _; c; ~4 w: E1 R
  end Set_Word_Length;: F$ V1 f& G( H1 P/ ?
  ----------------9 k5 Y2 V1 g$ ~- i  b: T* k
  -- Set_Parity --
/ C  _7 }( k# u  p0 D  ----------------- S  @/ @: N& n
  procedure Set_Parity (This : in out USART; To : Parities) is7 |2 d' y; S2 {2 D6 Z
  begin9 Z3 S7 e* l" E) f5 n" T
     case To is
5 w) L% n! _  T3 _- p        when No_Parity =>" M# R7 d" r, w7 [
           This.Periph.CR1.PCE := False;0 d" Z9 K+ A. Z) h5 L* q( {+ {. L& H
           This.Periph.CR1.PS  := False;
5 r7 r6 ]+ A2 V, Q- T: G5 H        when Even_Parity =>
6 {; e6 z! |" W( F           This.Periph.CR1.PCE := True;
- V& I. l  z# v9 j* L8 a: R           This.Periph.CR1.PS  := False;
6 J* O7 |: v7 Q/ C        when Odd_Parity =>$ Y: o* X9 Z( z) V- {' ~8 \
           This.Periph.CR1.PCE := True;
, c$ O; |0 O9 x1 M# b0 n           This.Periph.CR1.PS  := True;& I+ g8 k: j7 N
     end case;: \) Q, E( ^0 b3 z
  end Set_Parity;
' z  m% j, Q  {( A# |5 X  -------------------
' Z  @/ t( w# [, k! v7 K, s  -- Set_Baud_Rate --8 @9 ^9 R$ g7 D! ~5 X
  -------------------
' H' L4 W! ^0 T* Z  procedure Set_Baud_Rate (This : in out USART; To : Baud_Rates)
5 [1 M8 M4 X* O5 E7 U5 |* e5 Z4 O6 l  is
5 C4 i3 s5 |" A" s( l     Clock        : constant UInt32 := APB_Clock (This);& Q$ Z' W/ S1 x) `# s2 b# p( b
     Over_By_8    : constant Boolean := This.Periph.CR1.OVER8;$ D; u- j5 |7 \8 ~- \- }
     Int_Scale    : constant UInt32 := (if Over_By_8 then 2 else 4);% o: t5 H, a! H" X! C
     Int_Divider  : constant UInt32 := (25 * Clock) / (Int_Scale * To);& C6 T/ q& ]7 }
     Frac_Divider : constant UInt32 := Int_Divider rem 100;
: A+ H9 l! K. e) }% s5 E* \  begin
) }' G1 y/ G% \2 [) p1 f! @     --  the integer part of the divi2 l: P6 `4 R8 V
     if Over_By_8 then
. t6 W1 e8 e5 o! j/ L6 b        This.Periph.BRR.DIV_Fraction :=, m( @( G: |1 O% ?) }  i) S, K: [
          BRR_DIV_Fraction_Field (((Frac_Divider * 8) + 50) / 100 mod 8);8 i4 M, G# j  q$ W& a
     else1 c2 m/ ]) J% Q. i% O4 C0 Z. a  k
        This.Periph.BRR.DIV_Fraction :=
- E! Y7 @. R4 \, G) K          BRR_DIV_Fraction_Field (((Frac_Divider * 16) + 50) / 100 mod 16);
% J1 N6 f1 u/ x# M0 P     end if;
; W0 x9 O* B6 b5 a! O* T7 ?( e& o     This.Periph.BRR.DIV_Mantissa :=
" w: P; `6 M+ c9 X8 |- C+ ?0 ^! T       BRR_DIV_Mantissa_Field (Int_Divider / 100);
1 |9 N" [% T& L& @  end Set_Baud_Rate;# Z! |& ]+ F4 ?3 ?) A
  ---------------------------
. F; L+ @+ d! V! o  h/ p! {  -- Set_Oversampling_Mode --
7 E) A( M$ @; r1 o8 E2 B3 ~5 {  ---------------------------
; V1 c, |& y# S5 R- O' D: C3 R% D: X6 |  procedure Set_Oversampling_Mode: ]* B, C+ V8 E; z6 f" Q
    (This : in out USART;
; T" T& S2 D& }3 r5 s3 H% I     To   : Oversampling_Modes)
, Z2 R. s: l6 c2 g, i/ |8 Y' p  is% o" U# D; ~8 p
  begin, l7 ?( B4 g) @( W
     This.Periph.CR1.OVER8 := To = Oversampling_By_8;
/ s0 N+ E! x, _* ^6 |0 a& f  end Set_Oversampling_Mode;$ h: o4 g/ Q& b- }" {2 `
  --------------
1 q4 z0 A; B/ \& O' W# s0 {  -- Set_Mode --+ M8 X. _& W0 V8 N
  --------------
4 v3 O# a% O2 r, h, Q- i  procedure Set_Mode (This : in out USART;  To : UART_Modes) is
6 G/ o% [  z8 |; V+ j  begin
  [8 v1 c' k+ Z* j, Z. \4 J# `     This.Periph.CR1.RE := To /= Tx_Mode;
, ^0 s' s4 W: r+ r     This.Periph.CR1.TE := To /= Rx_Mode;
) H, m/ U& R/ q) C  end Set_Mode;
6 U- K& d  x1 C$ C- g, l  ----------------------& j, \& s5 G4 H; `) g' z
  -- Set_Flow_Control --
2 }" k6 I. K% |  ----------------------* P; }. i5 ?) |8 d7 n9 L
  procedure Set_Flow_Control (This : in out USART;  To : Flow_Control) is4 \' `0 s/ y' e( h# g% d( F
  begin3 q* |# m, `7 v5 B0 |1 E
     case To is
) _% C6 N2 w5 ?) M7 X        when No_Flow_Control =># b! x+ G* ^1 l, N6 K/ y
           This.Periph.CR3.RTSE := False;$ i0 Z, ~5 \0 R
           This.Periph.CR3.CTSE := False;
! Q/ @; \3 Z; f9 _7 M! i        when RTS_Flow_Control =>
: F1 r' g5 [. C0 a7 v, \; n           This.Periph.CR3.RTSE := True;
; M% P- D( z# U3 G$ t           This.Periph.CR3.CTSE := False;' w" U: a) V9 m/ W% q. t( M
        when CTS_Flow_Control =>
5 c6 I+ t6 U, w- f& i/ T6 }- ~2 N           This.Periph.CR3.RTSE := False;7 K$ S2 b( e; F  ?6 Y, L
           This.Periph.CR3.CTSE := True;
/ |6 ?) z' N& l0 K# m0 P5 c1 k, V& k        when RTS_CTS_Flow_Control =>
6 @" D/ [- ]- y& {. \           This.Periph.CR3.RTSE := True;
/ {' w( E+ X) y) T* }           This.Periph.CR3.CTSE := True;
% }# p' }' [, q- E( N: T- b     end case;
3 j* k' A8 R8 {2 q5 {" A  end Set_Flow_Control;0 F( Z8 y  _2 m5 L2 R
  ---------
$ {3 G' k6 Y- L4 i9 M. ]# m; w% c  -- Put --
. r* x2 v1 z, \) q& A2 E" ^4 Q  ---------, Z% d' A/ [; }7 [
  procedure Transmit (This : in out USART;  Data : UInt9) is+ I8 v' o! c  f- B) `
  begin2 D1 b: `% b6 p: z2 D2 y
     This.Periph.TDR.TDR := TDR_TDR_Field (Data);
5 o- X) W5 f$ w% a+ X% {4 t  end Transmit;
9 G7 W$ P3 Y& p: P$ G7 z. g/ p* ?+ \  ---------0 B: I" J+ q1 `' ?$ L9 l
  -- Get --
. F, N% a4 P2 B& G  ---------
8 R; w8 B3 V7 _4 ^% A( w3 G1 D  procedure Receive (This : USART;  Data : out UInt9) is
/ ]% w$ s5 n7 \  begin9 q1 W. y. U; U! x! o& S: ]9 ~7 I
     Data := Current_Input (This);; ]' U; j7 W) g2 ?' i
  end Receive;
' j& y' h6 h  [1 w2 r- ]" H6 K- I  -------------------
: o& h: O+ I  U  -- Current_Input --0 l; {7 w, [1 Z# G1 e3 X
  -------------------
2 s: C- f1 U; |: w$ m( Z: ?  function Current_Input (This : USART) return UInt9 is (Uint9 (This.Periph.RDR.RDR));$ f5 J  `* c: g7 {
  --------------
8 g2 V% `% v) |( j  -- Tx_Ready --; P3 h& Z; C& v4 Y
  --------------
/ N6 N9 \% k; |' `+ `  function Tx_Ready (This : USART) return Boolean is( a, v$ H0 k3 x! a
  begin2 P( L; e+ M0 N& B) p# D
     return This.Periph.ISR.TXE;
* ^! U6 W2 ~" m1 G0 h  end Tx_Ready;
" _, O: a" J. O  h$ w  --------------* o3 B( g# }1 @* K1 |7 N
  -- Rx_Ready --
3 L) Z+ j+ B  _3 y2 U+ Q& Q  --------------
! q, i) `  c! i  _  function Rx_Ready (This : USART) return Boolean is; G3 ?4 p% V/ D2 ?0 R6 }* H  D
  begin- F* |2 E! _4 ?) t
     return This.Periph.ISR.RXNE;
+ K/ U/ j' \) F7 ?* L% M0 C( J  end Rx_Ready;
9 c+ q% g; W' h6 i6 K  ------------
8 G* O- s6 @# S2 }* P# b0 b  -- Status --- L" _# `0 X, ]7 ~8 J
  ------------/ p. k8 j& J4 J2 v$ _$ P
  function Status (This : USART; Flag : USART_Status_Flag) return Boolean is
# C: x9 B0 E* D( d0 E  begin
6 a. W8 G  Z+ W% C8 {; o     case Flag is2 }7 {$ x" F! b" a; v
        when Parity_Error_Indicated =>
9 h6 a, O' G" i; Y* z) _5 x           return This.Periph.ISR.PE;3 j9 f3 {/ x0 h- n+ h1 W$ y
        when Framing_Error_Indicated =>
) l4 G0 T7 F3 f( K5 k$ p           return This.Periph.ISR.FE;/ q5 n) j. @6 `. T& n% i" ~
        when USART_Noise_Error_Indicated =>9 u4 d6 J2 U, _2 L) [9 A+ ^7 f$ t
           return This.Periph.ISR.NF;
" |; q  n6 y# Q* p  E+ R. j! {        when Overrun_Error_Indicated =>
/ L2 T. q6 Z+ w& T           return This.Periph.ISR.ORE;
4 ]8 _+ i: S) ?1 Z: V8 u        when Idle_Line_Detection_Indicated =>
5 l8 B4 w% f# c0 u0 Q           return This.Periph.ISR.IDLE;5 D2 J) ?/ j) }
        when Read_Data_Register_Not_Empty =>0 ^0 ]+ r- ?+ F$ F3 k0 l2 T
           return This.Periph.ISR.RXNE;
' y7 P* `) K* o- u1 q! C; N8 h        when Transmission_Complete_Indicated =>
4 l7 S* r- ^- Q# M$ N) d+ u* }0 ?           return This.Periph.ISR.TC;( Y3 Q* u" b7 U. q8 g
        when Transmit_Data_Register_Empty =>
- [. }& j$ T' S" R6 j           return This.Periph.ISR.TXE;. H. f( {- q  ~" o+ G$ A
        when Line_Break_Detection_Indicated =>
8 M! |4 o2 G9 n3 m  X& f           return This.Periph.ISR.LBDF;
8 X# v3 x( x! V        when Clear_To_Send_Indicated =>
5 W2 [8 U; ?4 V6 O0 k  S) U           return This.Periph.ISR.CTS;
5 \5 `6 M2 @& x) t5 C/ p     end case;
: ?9 U, W) ^7 W6 K" F0 r9 P  end Status;7 d8 ?! X/ K9 o2 C
  ------------------
1 T, v- z" T  Y0 }  -- Clear_Status --! w3 T* A+ T4 t. b
  ------------------
  c4 O* m$ ^5 G9 R2 s9 @$ w6 Z  procedure Clear_Status (This : in out USART;  Flag : USART_Status_Flag) is
: m4 J& m# g  h  begin
/ B. b$ \: e" P     case Flag is4 u/ f+ D% A, d" n" Q' M
        when Parity_Error_Indicated =>
, V% b5 M7 `5 p2 m           This.Periph.ISR.PE := False;" E, K: P* d& p
        when Framing_Error_Indicated =>
& p/ h; m4 M' U- ^1 z+ F- \3 I/ t           This.Periph.ISR.FE := False;
4 k' z- S8 l5 P        when USART_Noise_Error_Indicated =>0 K* G4 ?3 {- l# I& Q$ i8 e
           This.Periph.ISR.NF := False;% D9 T3 b# z; w3 `1 U: l( i' i2 \
        when Overrun_Error_Indicated =>
# m4 f; c& ~& b7 D* R1 a% S+ m. s; i9 F           This.Periph.ISR.ORE := False;
" d6 O- M* D' e/ }" `  M9 x        when Idle_Line_Detection_Indicated =>
* n! j$ l- a7 L2 t) w# W3 j           This.Periph.ISR.IDLE := False;8 ^- Y5 H* L% [$ G6 u
        when Read_Data_Register_Not_Empty =>
6 H) R, E1 h- g7 h# B. `           This.Periph.ISR.RXNE := False;# @/ H  v& c1 h" ^# ]4 Z
        when Transmission_Complete_Indicated =>
; v# O' l& |1 c) w0 W           This.Periph.ISR.TC := False;
* l2 ^% i& x$ B. F, R7 ?& N        when Transmit_Data_Register_Empty =>
. F0 h/ }2 }4 l2 c0 q  x           This.Periph.ISR.TXE := False;8 i/ g/ a" \" w4 s/ U  O5 Y
        when Line_Break_Detection_Indicated =>
8 @3 x& W8 y/ A6 o! o           This.Periph.ISR.LBDF := False;
2 ~* g! u% G. Z7 ?" F8 h        when Clear_To_Send_Indicated =>! d% \, e" L. n" a/ K9 C) x
           This.Periph.ISR.CTS := False;; }: S: m) n8 J3 J: ?
     end case;
4 ?. r# H( H! @2 J! n  end Clear_Status;' V' U' J. S. H" M. T) x
  -----------------------9 s+ f' F% j: m8 Y- w: W4 G, m
  -- Enable_Interrupts --
7 b: p% p/ ], A$ w( P' H  -----------------------
# [5 f( A" T. _  procedure Enable_Interrupts( X# z) D' e( |' |
    (This   : in out USART;
8 i( q4 R' B% ]     Source : USART_Interrupt)" m+ ], O, c6 M6 E) L' u1 B# o
  is
, ?: K" i1 Y5 m; i1 c  begin# Y$ N/ M; u, L& @4 X' V
     case Source is
: u. d% e, g& t/ i% w, I9 j        when Parity_Error =>( P) a" s. g$ Z- }; z
           This.Periph.CR1.PEIE := True;6 M' s& U* t0 J2 e8 Y& `$ L
        when Transmit_Data_Register_Empty =>) d% A; Y1 X" @0 ^) m1 r! l. Q
           This.Periph.CR1.TXEIE := True;5 S: _6 y" V9 Z+ p/ _
        when Transmission_Complete =>
7 \# H* T1 A' j: x7 B9 N2 c7 x0 Z           This.Periph.CR1.TCIE := True;
8 J  n9 \! D4 z5 @  Y        when Received_Data_Not_Empty =>: h$ l$ ?% m- n9 M2 ~4 R* C
           This.Periph.CR1.RXNEIE := True;  x+ l0 t* e+ J( l. C. d: X
        when Idle_Line_Detection =>7 x* j$ y4 ?' G
           This.Periph.CR1.IDLEIE := True;
; r  m  ]" s, L0 B, P2 s/ W        when Line_Break_Detection =>
( M$ V$ p, u4 c4 g0 s           This.Periph.CR2.LBDIE := True;" u# [: E4 ~# y4 h6 \) z# e
        when Clear_To_Send =>3 N5 g8 z- x/ G  h4 n5 R+ b
           This.Periph.CR3.CTSIE := True;
2 w; J2 w1 B' P  t7 O: F" z        when Error =>
! H; K6 q! ?! j1 {           This.Periph.CR3.EIE := True;5 Q* Q2 M6 c& C0 ?( B# B5 H5 Y: b
     end case;& z- x8 v* v: n5 R
  end Enable_Interrupts;8 T- M: {3 d' `) K! }% X
  ------------------------- B# f; {5 o9 A+ w1 }5 {, x+ W, j
  -- Disable_Interrupts --
+ Q6 |* `3 x6 @5 a; v  ------------------------  E3 l* C8 g& {* D* c+ E. T
  procedure Disable_Interrupts" T' {' ]( a4 z; C" v8 x
    (This   : in out USART;
- v; U6 L! @! J+ s" V$ i# k# h* y4 R     Source : USART_Interrupt)7 D: D1 {9 H/ l: I0 ^" D
  is
0 h+ F6 J4 R; u- F  begin
" O) o9 F" \- m% I' B* i     case Source is
3 A6 z, F: U- W' ]6 \        when Parity_Error =>
( L6 U( ?, P7 [% V, [$ P           This.Periph.CR1.PEIE := False;8 Q6 o* o% E0 {2 o% ?* w2 w
        when Transmit_Data_Register_Empty =>
8 f$ {% c) [4 l# @* n1 j8 G           This.Periph.CR1.TXEIE := False;) L( j; }5 s; Z( t3 P& Z
        when Transmission_Complete =>6 ^+ s- ~% X( V, G" h
           This.Periph.CR1.TCIE := False;
+ V4 ~: d- x. J3 Q! u( y' R9 U        when Received_Data_Not_Empty =>" a. A" X- t5 k- {. i
           This.Periph.CR1.RXNEIE := False;
+ k, S! p6 T+ Y7 b' @* x1 c, T& j& c# Q        when Idle_Line_Detection =>
; i+ S2 K# a2 G# W& ~6 O3 c- L           This.Periph.CR1.IDLEIE := False;6 N$ S9 j3 r% x
        when Line_Break_Detection =>
$ b& b# Y% t2 F           This.Periph.CR2.LBDIE := False;7 L$ S. v- j3 j# a
        when Clear_To_Send =>
$ V1 U6 _8 \, v( f: f           This.Periph.CR3.CTSIE := False;6 c( Y  G# b9 ~: b3 L# }( b
        when Error =>: y; g# Q9 Q  h( ?
           This.Periph.CR3.EIE := False;
+ m; H0 E: ~. L# X+ h* w1 m     end case;
' S0 |4 ]; r: S5 m8 R  end Disable_Interrupts;& D9 _$ |) V2 D/ u
  -----------------------
% I0 _, j/ ~* D. Y! f" p/ A* U  -- Interrupt_Enabled --
2 E8 A! P3 l$ m  -----------------------! l. @  N# y" v& P# N
  function Interrupt_Enabled: o; c, n9 }% M' w/ e% A/ w
    (This   : USART;
4 R  q4 F5 y0 R- v2 g     Source : USART_Interrupt)4 M: O1 N! {; L5 h7 k/ z3 _
     return Boolean7 H# L0 |1 x; g
  is
2 g+ p7 h# t" q3 C$ w! B* [  begin0 |, x, i5 `& ?  ^" }" s
     case Source is8 H/ f( g/ w: k  U) O7 j
        when Parity_Error =>
  h' ^4 I# R6 ^1 ]3 y           return This.Periph.CR1.PEIE;
3 B3 ]* M/ \8 _7 T( R' r        when Transmit_Data_Register_Empty =>  A# c8 b, H3 S4 `  O, B$ T: T
           return This.Periph.CR1.TXEIE;
$ X' A5 T" k- K        when Transmission_Complete =>
: @$ n% E8 n" F* c0 J* x* l- X% R           return This.Periph.CR1.TCIE;
$ ]1 X3 O9 g4 E) D! I1 l+ ]  e, E        when Received_Data_Not_Empty =>. W' e; M) I, c, `9 g
           return This.Periph.CR1.RXNEIE;
9 Y9 ^1 b  d3 K! Y+ Y; x8 ?        when Idle_Line_Detection =>! K! ]  C2 M1 r) _6 E, p
           return This.Periph.CR1.IDLEIE;5 ?: T: W, ^+ ?5 [' r4 o
        when Line_Break_Detection =>- h4 x' C' h3 t' d7 Y
           return This.Periph.CR2.LBDIE;
3 B4 F' l5 x+ e        when Clear_To_Send =>( m) T$ G6 Q  D
           return This.Periph.CR3.CTSIE;; w3 l4 V  i9 z' W
        when Error =>
* b) Q" I6 A; S' w- Q- T8 S           return This.Periph.CR3.EIE;
- Y# Z' r0 ]' r+ M+ A, p( L     end case;$ m1 `7 f3 k$ `6 u
  end Interrupt_Enabled;0 {0 A4 ?5 i) U' N% h% E( N, v$ D
  ----------------------------------" `6 Y# F) Y8 }- S/ y' \
  -- Enable_DMA_Transmit_Requests --
7 `) Y) S5 w. J0 K5 D, {0 j  ----------------------------------
# b6 l) @. d. T0 c* ?) `  procedure Enable_DMA_Transmit_Requests (This : in out USART) is7 W2 A% c% ?& ?$ i6 q
  begin
4 M+ B6 i/ g2 A9 Q) `! x- ?     This.Periph.CR3.DMAT := True;
$ l! u, L8 k. a1 A  b$ N  end Enable_DMA_Transmit_Requests;
; T. {* ~) B2 J* T! p  ---------------------------------! G9 ]4 ?1 w# ^
  -- Enable_DMA_Receive_Requests --
6 L1 u7 O' J+ u  w0 p5 p5 X  ---------------------------------
7 p3 x5 `6 H# n: ~5 p  procedure Enable_DMA_Receive_Requests (This : in out USART) is2 q% k( W+ y$ \5 h( z: d3 y8 D
  begin
$ z0 C0 b4 |% L  j2 |: Y     This.Periph.CR3.DMAR := True;
1 W7 s  }+ Y' s0 W% A  end Enable_DMA_Receive_Requests;. N8 ~9 N! W* i# Q/ ]9 k7 y
  -----------------------------------
; k) Y) h" S2 M8 ]9 O  -- Disable_DMA_Transmit_Requests --6 y' [9 n% y3 M5 s
  -----------------------------------
7 ]" g9 \  z2 e  g, `- Q/ p  procedure Disable_DMA_Transmit_Requests (This : in out USART) is
4 b9 G7 t& s( U+ z/ K# c. V  begin
( s/ `/ {" T; J2 T% h& X     This.Periph.CR3.DMAT := False;; M7 p1 V: k+ |' a* e1 o# ~1 g
  end Disable_DMA_Transmit_Requests;
5 e) A! X( u. d' o1 p  ----------------------------------) W6 |6 Q+ C3 G% h4 ~6 Q
  -- Disable_DMA_Receive_Requests --# M7 p, j( C8 z1 m3 l- ?
  ----------------------------------
7 V- Q8 b; H* o5 D8 D  procedure Disable_DMA_Receive_Requests (This : in out USART) is1 B  ^: q: L! x- @& S1 |
  begin
/ X) @$ p/ x' q$ `3 I& Z% ?     This.Periph.CR3.DMAR := False;
* g7 S4 ]6 ]6 a+ i  t+ T9 {$ k+ v- e# U  end Disable_DMA_Receive_Requests;6 X& ?( ^' z$ I4 \4 X( U6 P5 e6 v
  -----------------------------------
7 I& o: J' O4 T7 W1 d* a5 W  -- DMA_Transmit_Requests_Enabled --4 v2 ]5 e/ \! ?) k* T( W
  -----------------------------------" H; B& r, x" T/ M
  function DMA_Transmit_Requests_Enabled  (This : USART) return Boolean is* u$ D: n+ U) Y( G
     (This.Periph.CR3.DMAT);
1 f" R0 @$ f" K; }) l0 e  ----------------------------------
2 o) a: i8 o7 a( _! D& w  -- DMA_Receive_Requests_Enabled --1 `$ @8 F/ c5 y7 i' y, m- z6 |
  ----------------------------------# x, e4 J7 E5 H7 ?% u2 Y: }8 T
  function DMA_Receive_Requests_Enabled  (This : USART) return Boolean is
' w  v9 b. |! g+ @( k$ e  e5 [     (This.Periph.CR3.DMAR);
& o- Y/ w0 a3 z& H  -----------------------------6 |+ J  q/ y; O( ^- ?: j
  -- Resume_DMA_Transmission --' l! a: y& u2 t% X$ e. X9 j* Y/ l5 U9 S& z
  -----------------------------
! h" g, k: z) L5 t( l  procedure Resume_DMA_Transmission (This : in out USART) is% g% F6 d( P: I% w1 A
  begin5 ]! ]; a% w, l' F* X8 \1 t
     Enable_DMA_Transmit_Requests (This);+ i, f% |- B! e2 o2 f
     if not Enabled (This) then
0 r1 R1 f, u  w$ K+ J8 J* E0 L; r        Enable (This);. E; M! r0 C) F9 W, z8 g0 @2 [1 c; ~
     end if;. o" m; _! W6 I4 ?, [% h
  end Resume_DMA_Transmission;
+ ]& H  x/ z6 k' j& [' j5 `# P  --------------------------
2 O) [1 t4 j% R- e' J( p9 g  -- Resume_DMA_Reception --% F3 D$ C: w% d  G1 c$ I
  --------------------------, Z+ M- q9 v+ r: \; u) M
  procedure Resume_DMA_Reception (This : in out USART) is
/ ~& U" Z0 ~. E# W, }- u  begin$ d5 b/ X2 [8 Y% c
     Enable_DMA_Receive_Requests (This);3 Z" H0 }! b) n  E' M
     if not Enabled (This) then
) Q/ Y( S7 O+ |, i        Enable (This);
6 j( o4 O# K# a1 Y, [     end if;
- \8 g8 |1 O$ @: f1 e  end Resume_DMA_Reception;0 h3 Y$ b( _3 c" H; X& |
  ---------------------------4 @' {+ i% `) O) F0 f3 \4 U  @
  -- Data_Register_Address --
' h- g; V; p1 T  ---------------------------) X- ~. \4 b: H  W% @; O+ }
  function Data_Receive_Register_Address (This : USART) return System.Address is1 o$ R. q0 \' k2 k9 c
    (This.Periph.RDR'Address);2 P* T7 n& ?7 P& e# |
  ---------------------------
6 a, e" Q0 v3 k$ r8 n4 F) w  -- Data_Register_Address --
  G( Y2 S1 ~0 J" j# h9 g  ---------------------------: N9 g1 J4 Z, v, @9 e* o7 [1 q8 L
  function Data_Transmit_Register_Address (This : USART) return System.Address is
9 l7 K# O2 e' l0 m8 O7 c8 U' a        (This.Periph.TDR'Address);, T0 A2 w. {" R7 E* e( p" P2 F, V6 l
  ---------------, n: B* c9 k3 I) e
  -- Data_Size --: x3 g$ F# }' X
  ---------------/ x4 c7 ]+ A& S4 N
  overriding6 @2 c( I" z! O+ `( w0 M1 |
  function Data_Size (This : USART) return HAL.UART.UART_Data_Size
, [3 g! B8 F2 B$ w  is# Y2 u  s' X% }9 O3 @
  begin
$ |1 a5 W7 j% o4 l& n     if This.Periph.CR1.M0 then- H% p7 t9 k: J$ F8 c$ ?) v9 B
        return Data_Size_9b;
/ `' E; r1 t+ j; _1 |     else" Q# t3 ^8 q( h
        return Data_Size_8b;
& s$ f( G# [/ Q$ m4 k" a( d0 {- }8 g! z     end if;5 ?5 o, f0 n5 \4 v: w  P
  end Data_Size;
3 N4 O6 S  P. Q$ H. x8 G2 W$ U8 _  --------------) g( M) R" G. E* h/ Q& s
  -- Transmit --0 F# I, ]7 w  z7 n8 M  R6 Y
  --------------+ E- R7 i2 m& L% r" W
  overriding) v/ u0 K4 C+ j! E
  procedure Transmit
. ^$ Z6 _% V3 v  ~' V2 P( L    (This    : in out USART;* c4 _. ^0 v$ w* R' v( B& Z
     Data    : UART_Data_8b;7 a' o# @0 @$ O4 ^0 v
     Status  : out UART_Status;
) Z. I. E! O% w5 r# m     Timeout : Natural := 1000)
* N' I' R0 {3 E8 r1 t/ E  is
" w1 \% q* l4 r0 A/ _6 M     pragma Unreferenced (Status, Timeout);6 J  x4 f9 e1 n* v. z  w
  begin
' S7 A7 c& ]  L4 R     for Elt of Data loop
. [8 ~# B2 Y$ s        loop8 ?0 j/ ]- F3 K' `4 g) d
           exit when This.Tx_Ready;0 k0 f5 z, d) e+ E: _1 ^& ~
        end loop;
. N& g1 V( V- m0 N) S& n+ X        This.Transmit (UInt9 (Elt));
3 ?- q5 M, }9 n: i# N; Y5 h% ?     end loop;
* a# B3 c, }4 _- z3 G     Status := Ok;6 J# q" w% p+ t4 ^9 p9 g5 P/ ?
  end Transmit;
$ d4 R- m0 S$ d3 o  --------------, ?( i3 L) W  v5 r% K: O
  -- Transmit --
* l9 |% _" L7 G* F1 M% }5 e  --------------* k& P0 E. p2 A; A# I
  overriding
. p6 ]5 f- |5 Z: B# U# \* p  procedure Transmit
. t: d& n2 H; X    (This    : in out USART;
: `) o% M2 a; [. J     Data    : UART_Data_9b;4 `- _' i1 Z0 `7 c3 O# o. j; U& U. M
     Status  : out UART_Status;
) L( ^" B5 J3 |  ?- b  A, b8 J     Timeout : Natural := 1000)
$ |& k. s) H6 z; o; w7 c  is
7 M. [7 x, E5 v( H     pragma Unreferenced (Status, Timeout);# `5 ?9 ]  a$ r& j4 g0 f! k  X9 B
  begin. p, {6 O% a8 F
     for Elt of Data loop! i# x" \" ~$ t( ~2 s7 \1 P& w
        loop6 I% @- ], p2 L* A, x2 T$ ]
           exit when This.Tx_Ready;
4 v. g& ]; }+ E: A' l. F6 R        end loop;4 y9 r' Z7 d' Q: d+ B
        This.Transmit (Elt);* a, i! Y" _+ a- T
     end loop;
# x' l/ l2 x. ~% t1 ^  |     Status := Ok;
( w6 q( B7 U& Q5 c+ G  end Transmit;# h2 R6 W$ t# u1 c. ?' d0 z: g- x
  -------------( O$ f; ], u( i
  -- Receive --
' Q- M2 w: Q2 U0 N  H  -------------2 x6 [. r( u% G4 w
  overriding0 ]$ ~/ d0 Y- p0 C$ y' z+ n* v
  procedure Receive0 m+ s& \% _8 O% ^% s) C% ]! @; f! M
    (This    : in out USART;; H" B0 q( p3 z" f
     Data    : out UART_Data_8b;$ d/ Q( {& f! d( g/ l
     Status  : out UART_Status;1 s9 i. F# ~6 G/ H  I
     Timeout : Natural := 1000)
' B5 E" T  Z5 @1 ?  is/ b, t6 @$ R5 f" M. V% L& e
     pragma Unreferenced (Status, Timeout);/ M* P/ g" d" g- Z
  begin; v6 D8 r( n9 W
     for Elt of Data loop
, U3 r- f9 `; \3 V6 a        loop
* |& f4 K; \6 R, H3 C/ Q( [           exit when This.Rx_Ready;
% d! p: `. ]' K        end loop;
9 R: i- u* x, o. t; D( F        This.Receive (UInt9 (Elt));/ S6 l& n* I: t2 o! b2 A  ]; I
     end loop;0 O0 f" O( x+ m3 _1 Q9 @8 p
     Status := Ok;4 m1 i% L; j/ Q) ^4 T0 @2 X
  end Receive;
& d  U6 g8 G' R  -------------0 Y4 k4 {+ J$ r6 V* Z6 ]5 W$ ^
  -- Receive --
9 E9 L( E- W: G* {3 r/ c. H  -------------4 G. C& k# P1 d6 f6 Y
  overriding/ @. q. d0 e, Z# Y/ k2 Y1 E
  procedure Receive
/ @% Y' S5 R8 z1 L' {7 Q    (This    : in out USART;3 F) v" j9 Y' p* Z
     Data    : out UART_Data_9b;) |8 I1 ^' Q( G& N, }( I. ~4 l% h7 C
     Status  : out UART_Status;
9 s0 H  j2 T; m5 C# I1 h     Timeout : Natural := 1000)
1 v! w& Q  e5 J7 q) W% F  is6 J% a. D+ P6 |1 T6 E
     pragma Unreferenced (Status, Timeout);( Y' J/ m5 j# \+ w! h
  begin/ O5 v, J& Q) v3 v" o9 i0 J  g8 h
     for Elt of Data loop
2 R% ^  Y. j# r) V7 ?/ W7 ~        loop! |+ F% Z1 C: B) E) p
           exit when This.Rx_Ready;* h9 B0 f% Z- f4 I# ~% q1 E6 y
        end loop;* [7 E; B, G4 X" X6 V
        This.Receive (Elt);% ?6 X5 G: E+ O: i
     end loop;  Z" x9 `- b" m+ E0 ~6 ~
     Status := Ok;. l5 r' {5 C+ n: r+ j0 l7 p" A2 @
  end Receive;
/ i: K! l6 m# a: xend STM32.USARTs; ' {0 s% n1 {: f: ^( L6 V
# W1 `9 c% @3 E$ L
4 g! {1 T4 _) z6 Y% I" n5 w( S$ m
10步:结果
过滤后的SuperIMU在振动时更稳定。来自振动的噪声由多量程配置值和冗余度补偿。
结果非常酷,在图片中,我在垂直握手时抓住了滚动,桌子上有一些小的震动(更多的测试会有严重的振动):
48.jpg
红色:单个IMU,黄色:过滤SuperIMU(滚动)
+ D8 L% J$ ~: Q! x6 J
测量的加速度和陀螺仪速率的加权平均值有助于减少振动环境中的噪声(例如,握手)。然而,成本与获得性能的使用可能不值得结果
49.jpg
红色:单个IMU,黄色:过滤的SuperIMU
; U. k. |8 V: Y+ n: n
& ^) N4 Y* m6 D" r

) _& g9 d/ J- R# ~3 E  G
最后,使用以下命令使用生产编译模式:
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

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

! ?2 s6 ~. M. F' `5 h/ @4 \( l1 H! d
这是一次有趣的体验,在成功完成项目的这一重大步骤后,我感兴趣的是为我的个人项目挖掘更多并为其他板和传感器制作其他Ada驱动程序。并且还使用Adacore框架继续开发火箭的自动驾驶仪。

/ H) Y0 ]$ r; S8 R
# w0 i+ H) z9 K- S
0 P: P# X2 X- e% Z; _  t
4 W! T1 y0 |& [. Y7 l. l
+ Y: A8 M3 t6 p  f6 ^% D

评分

参与人数 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 手机版