adacore paris tech day 2016: fabien chouteau - making the ada drivers library
TRANSCRIPT
Senior Software Engineer
Making the Ada Drivers Library
Fabien Chouteau
Ada & Device Drivers:A Well-Engineered Collaboration
Ada’s strong typing systemencourages communication and demands precision
Representation clausesare the killer feature for coding drivers
Contract-based programminghelps eliminate problems earlier in the development cycle
Object-oriented featurescan improve code reuse
Multitasking support is available for bare metal platforms
We wanted to experiment.
So, we started this project as a proof of concept to explore whether this was demonstrable with modern ARM
microcontrollers.
We wanted to use the best features of Ada to provide:
• clean hardware mapping,
• good interfaces,
• code reuse, and
• easy debugging.
What did we learn?
• Modern microcontrollers are gigantic beasts.
• Accessing memory mapped register can be tricky (pragma Volatile_Full_Access).
• Customization of run-times is still not flexible enough.
• Confirmed that Ada had good properties for programming device drivers.
Representation clauses
GPIO->MODER &= ~(GPIO_MODER_MODER0 << (pin_nbr* 2));
VS
GPIO.MODER.Arr (Pin_Nbr) := 0;
package STM32_SVD.RNG ispragma Preelaborate;
----------------- Registers -----------------
-- control registertype CR_Register is record
-- unspecifiedReserved_0_1 : HAL.UInt2 := 16#0#;-- Random number generator enableRNGEN : Boolean := False;-- Interrupt enableIE : Boolean := False;-- unspecifiedReserved_4_31 : HAL.UInt28 := 16#0#;
end recordwith Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use recordReserved_0_1 at 0 range 0 .. 1;RNGEN at 0 range 2 .. 2;IE at 0 range 3 .. 3;Reserved_4_31 at 0 range 4 .. 31;
end record;
SVD2ada: generating hardware register mapping
<?xml version="1.0" encoding="utf-8" standalone="no"?><device schemaVersion="1.1"xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"xs:noNamespaceSchemaLocation="CMSIS-SVD_Schema_1_1.xsd"><name>STM32F46_79x</name><version>1.0</version><description>STM32F46_79x</description><!--Bus Interface Properties--><!--Cortex-M4 is byte addressable--><addressUnitBits>8</addressUnitBits><!--the maximum data bit width accessible within a single transfer--><width>32</width><!--Register Default Properties--><size>0x20</size><resetValue>0x0</resetValue><resetMask>0xFFFFFFFF</resetMask><peripherals><peripheral><name>RNG</name><description>Random number generator</description><groupName>RNG</groupName><baseAddress>0x50060800</baseAddress><addressBlock><offset>0x0</offset><size>0x400</size><usage>registers</usage>
</addressBlock><interrupt><name>HASH_RNG</name>
SVD2ada: generating hardware register mapping
Now what?
Introducing the Ada_Drivers_Library
An Open Community Project hosted on GitHub
Vendor-independent
Makes it easy to use Ada to do interesting things with a
variety of ARM microcontrollers!
Ada_Drivers_Library Framework
MCU
HAL
Components
Services
Low-level drivers to interface with peripherals on particular microcontrollers
Ada layer providing clean abstraction of hardware
External components connected to the MCU in a standard way (I2C, UART, SPI, SDIO, MMC, etc.)
OS services (we have a filesystem; on our wishlist is a network stack, USB stack, Bluetooth, etc.)
What’s in it?
• GPIOs
• I2C, SPI, UART
• ADC, DAC
• Audio (SAI)
• LCD and touch screen drivers
• Timers, PWM
• DMA
• Flexible Memory Controller (external RAM)
• Camera (DCMI)
• Random Number Generator
• SDcard
On what board?
Crazyflie 2.0
OpenMV
BBC Micro:Bit
Roadmap
• More boards from more vendors
• More device drivers
• More services (Filesystem, Bluetooth, USB)
•Robotics utilities and drivers
• General purpose control system code
Making with Ada
Make with Ada: Candy dispenser, with
a twist
Make with Ada: DIY Instant
Camera
Make with Ada: ARM
Cortex-M CNC controller
More Information Online
• The Ada_Drivers_Libraryhttps://github.com/AdaCore/Ada_Drivers_Library
• Ada Driver Library for ARM Cortex-M/R - Part 1https://community.arm.com/groups/embedded/blog/2016/07/08/ada-driver-library
• MCQ Candy Dispenserhttp://blog.adacore.com/make-with-ada-candy-dispenser-with-twist
• DIY Instant Camerahttps://www.youtube.com/watch?v=MHo5bcHWx3o
• ARM Cortex-M CNC Controllerhttp://blog.adacore.com/make-with-ada-arm-cortex-m-cnc-controller