diff --git a/README.md b/README.md index 234b8c8..120c41e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # stm32-ada Ada bindings for STM32 internals + +## Hardware quirks and workarounds + +### APB + +APB does not support writes of parts of 32-bit registers. +The library provides acess to register fields as records. +This could lead compiler to emit byte and half-word writes +to APB registers causing erroneous effects. +As a workaround those registers should be read to local variable, +this variable altered, and then written back to hardware. +GNAT users may not need the workaround, because of its pragma +`Volatile_Full_Access` used in this library. + +## Compiler specific notes + +There are compiler-specific pragmas so your compiler may complain about them. + + +### GNAT + +`Volatile_Full_Access` pragma is used on (at least writable) APB registers +as byte- and half-wide writes are not supported by APB. Read STM docs on +what those accesses actually do. \ No newline at end of file diff --git a/source/stm32-f4-exti.ads b/source/stm32-f4-exti.ads index 24aa2fe..3a6c6a9 100644 --- a/source/stm32-f4-exti.ads +++ b/source/stm32-f4-exti.ads @@ -27,12 +27,18 @@ package STM32.F4.EXTI is end record; type EXTI_Registers is record - IMR: Event_Set_Register with Volatile_Full_Access; - EMR: Event_Set_Register with Volatile_Full_Access; - RTSR: Event_Set_Register with Volatile_Full_Access; - FTSR: Event_Set_Register with Volatile_Full_Access; - SWIER: Event_Set_Register with Volatile_Full_Access; - PR: Event_Set_Register with Volatile_Full_Access; + IMR: Event_Set_Register; + Pragma Volatile_Full_Access(IMR); + EMR: Event_Set_Register; + Pragma Volatile_Full_Access(EMR); + RTSR: Event_Set_Register; + Pragma Volatile_Full_Access(RTSR); + FTSR: Event_Set_Register; + Pragma Volatile_Full_Access(FTSR); + SWIER: Event_Set_Register; + Pragma Volatile_Full_Access(SWIER); + PR: Event_Set_Register; + Pragma Volatile_Full_Access(PR); end record; for EXTI_Registers use record diff --git a/source/stm32-f4-pwr.ads b/source/stm32-f4-pwr.ads index 2d312d6..2399ac9 100644 --- a/source/stm32-f4-pwr.ads +++ b/source/stm32-f4-pwr.ads @@ -117,8 +117,10 @@ package STM32.F4.PWR is end record; type PWR_Registers is record - CR : Power_Control_Register with Volatile_Full_Access; - CSR : Power_Control_Status_Register with Volatile_Full_Access; + CR : Power_Control_Register; + Pragma Volatile_Full_Access(CR); + CSR : Power_Control_Status_Register; + Pragma Volatile_Full_Access(CSR); end record with Volatile; for PWR_Registers use record diff --git a/source/stm32-f4-syscfg.ads b/source/stm32-f4-syscfg.ads index a835062..424e5c0 100644 --- a/source/stm32-f4-syscfg.ads +++ b/source/stm32-f4-syscfg.ads @@ -114,13 +114,20 @@ package STM32.F4.SysCfg is end record; type SYSCFG_Registers is record - MEMRMP: Memory_Remap_Register with Volatile_Full_Access; - PMC: Peripherial_Mode_Register with Volatile_Full_Access; - EXTICR1: External_Interrupt_Configuration_1.Register with Volatile_Full_Access; - EXTICR2: External_Interrupt_Configuration_2.Register with Volatile_Full_Access; - EXTICR3: External_Interrupt_Configuration_3.Register with Volatile_Full_Access; - EXTICR4: External_Interrupt_Configuration_4.Register with Volatile_Full_Access; - CMPCR: Compensation_Cell_Control_Register with Volatile_Full_Access; + MEMRMP: Memory_Remap_Register; + Pragma Volatile_Full_Access(MEMRMP); + PMC: Peripherial_Mode_Register; + Pragma Volatile_Full_Access(PMC); + EXTICR1: External_Interrupt_Configuration_1.Register; + Pragma Volatile_Full_Access(EXTICR1); + EXTICR2: External_Interrupt_Configuration_2.Register; + Pragma Volatile_Full_Access(EXTICR2); + EXTICR3: External_Interrupt_Configuration_3.Register; + Pragma Volatile_Full_Access(EXTICR3); + EXTICR4: External_Interrupt_Configuration_4.Register; + Pragma Volatile_Full_Access(EXTICR4); + CMPCR: Compensation_Cell_Control_Register; + Pragma Volatile_Full_Access(CMPCR); end record; for SYSCFG_Registers use record diff --git a/source/stm32-f4-usart.ads b/source/stm32-f4-usart.ads index 9c6018c..651edc9 100644 --- a/source/stm32-f4-usart.ads +++ b/source/stm32-f4-usart.ads @@ -226,13 +226,20 @@ package STM32.F4.USART is end record; type USART_Registers is record - SR: Status_Register with Volatile_Full_Access; -- Status register - DR: Unsigned_32 with Volatile_Full_Access; -- Data register - BRR: Baud_Rate_Register with Volatile_Full_Access; -- Baud rate register - CR1: Control_Register_1 with Volatile_Full_Access; -- Control register 1 - CR2: Control_Register_2 with Volatile_Full_Access; -- Control register 2 - CR3: Control_Register_3 with Volatile_Full_Access; -- Control register 3 - GTPR: Guard_Time_and_Prescaler_Register with Volatile_Full_Access; -- Guard time and prescaler register + SR: Status_Register; -- Status register + Pragma Volatile_Full_Access(SR); + DR: Unsigned_32; -- Data register + Pragma Volatile_Full_Access(DR); + BRR: Baud_Rate_Register; -- Baud rate register + Pragma Volatile_Full_Access(BRR); + CR1: Control_Register_1; -- Control register 1 + Pragma Volatile_Full_Access(CR1); + CR2: Control_Register_2; -- Control register 2 + Pragma Volatile_Full_Access(CR2); + CR3: Control_Register_3; -- Control register 3 + Pragma Volatile_Full_Access(CR3); + GTPR: Guard_Time_and_Prescaler_Register; -- Guard time and prescaler register + Pragma Volatile_Full_Access(GTPR); end record with Volatile; for USART_Registers use record SR at 16#00# range 0 .. 31;