ada - STM32F4 UART 半字寻址

标签 ada uart stm32f4

试图为 STM32F4 UART 推出我自己的代码。
该芯片的一个特点是,如果您像 GNAT 编译器那样使用字节寻址来设置单个位,则半字的另一个字节中的相应位将被设置。数据表说使用半字寻址。有没有办法告诉编译器这样做?我试过
对于 CR1_register'Size 使用 16;
但这没有效果。写入整个 16 位字有效,但您无法设置命名位。

最佳答案

AdaCore 中使用的 GNAT 方法 Ada Drivers Library , 是使用 GNAT-only 方面 Volatile_Full_Access ,关于其中GNAT Reference Manual

This is similar in effect to pragma Volatile, except that any reference to the object is guaranteed to be done only with instructions that read or write all the bits of the object. Furthermore, if the object is of a composite type, then any reference to a subcomponent of the object is guaranteed to read and/or write all the bits of the object.


The intention is that this be suitable for use with memory-mapped I/O devices on some machines. Note that there are two important respects in which this is different from pragma Atomic. First a reference to a Volatile_Full_Access object is not a sequential action in the RM 9.10 sense and, therefore, does not create a synchronization point. Second, in the case of pragma Atomic, there is no guarantee that all the bits will be accessed if the reference is not to the whole object; the compiler is allowed (and generally will) access only part of the object in this case.


他们的代码是
   --  Control register 1
   type CR1_Register is record
      --  Send break
      SBK            : Boolean := False;
      ...
   end record
     with Volatile_Full_Access, Size => 32,
          Bit_Order => System.Low_Order_First;

   for CR1_Register use record
      SBK            at 0 range 0 .. 0;
      ...
   end record;

关于ada - STM32F4 UART 半字寻址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69019439/

相关文章:

ada - 跟踪 Ada 程序的执行

string - 你如何编写一个程序,你可以在一个字符串中输入最多 5 个字符,但又少于 5 个(在 Ada 中)?

record - Ada 重叠标签字段

c++ - C++ 中的 Ada 子类型等价物

c - STM32F1发送UART时丢失字节

c - 从 UART 读取数据时停止程序

linux - UART 回复包括之前的命令?

stm32 - Cortex-M4 上的 Systick 定时器 : What is its prescaler?

c - STM32F407 USART1 : Clearing USART_FLAG_TC requires pgm to be halted before actually clearing the bit

c - 为什么 USART2 发送垃圾值?