Good day! It's a shame few articles devoted to the
hellish programming of the wonderful
programming language of Hell, and even more so there are no them programming on it for microcontrollers. But the language itself is even positioned as a language of embedded systems ... Maybe it is very difficult?
I will try in this small note to give a classic example of the LED blinking program, but in Hell, so that everyone could repeat.
As a motherboard, I use some kind of Chinese motherboard with a stm32f407vet6 processor, its LED is connected on port A to pin PA6. As a programming environment, I will use gnat for
arm under ubuntu, st-link v2 is connected for uploading and the st-link package is installed (you need to build and install it from
stlink.git ), but you can use any other programmer (for example, SEGGER) .
Fortunately, stm32f4xx is also included in the supported processors, so all you need to do is create a project file with the version of target and runtime. Well, write our own program. To make life easier, I used the svd2ada program to automatically generate peripheral description files from the svd file for my processor. Svd description can be taken from the standard package, and the program svd2ada is on
GitHub .
')
All source code is available on
GitHub .
So - the actual program below:
with STM32F40x; use STM32F40x; with STM32F40x.RCC; use STM32F40x.RCC; with STM32F40x.GPIO; use STM32F40x.GPIO; with Ada.Real_Time; use Ada.Real_Time; procedure main is Led_Pin : constant := 6; Port : ODR_Field renames GPIOA_Periph.ODR.ODR; begin -- clock for GPIO-A RCC_Periph.AHB1ENR.GPIOAEN := 1; -- PA6 GPIOA_Periph.MODER.ARR(Led_Pin) := 2#01#; GPIOA_Periph.OTYPER.OT.ARR(Led_Pin) := 0; GPIOA_Periph.OSPEEDR.ARR(Led_Pin) := 0; -- loop Port.Arr (Led_Pin) := Port.Arr (Led_Pin) xor 1; delay until Clock + To_Time_Span(1.0); end loop; end main;
First, how to collect all this and run ...
Below are all the commands for bash in the project directory, all utilities are installed in / opt / gnat / bin
Step 1. Set the paths so that the toolchain we need is called
export PATH=/opt/gnat/bin:$PATH
Step 2. Putting the executable file.
gprbuild -P step1.gpr
Step 3. Create a bootable binary for st-flash:
arm-eabi-objcopy -O binary main main.bin
Step 4. Download our firmware via st-link2 connected via USB
st-flash write main.bin 0x8000000
If everything went well, then you can admire the flashing LED ...
Now for some explanation. For this target board, all the necessary initialization code has already been written, and the processor frequency is set to 168 MHz, so we had very little code to write. Port string: ODR_Field renames GPIOA_Periph.ODR.ODR is introduced for code readability. The Funcion Clock returns the current time (precision - microseconds).
In addition, for Ada-programs there is practically no need for an operating system (this is how the OS itself is) for the implementation of tasks, synchronization tools, etc.
All the richness of the Hell language for this processor is not available, since a special profile is defined for the compiler - namely, Pragma Profile (Ravenscar). This profile introduces a number of restrictions to ensure that your program is guaranteed to work in such an environment.
However, these limitations can be artificially circumvented, but the main advantage of this language feature is that if you write a program within this profile, then most likely it will work ...
That's all, write in the comments that is not clear, I will try to answer. In the next article I will try to give the full development cycle of an interesting application on Ada for the same microprocessor starting with the description and analysis of the system on aadl and ending with automatic proof using SPARK.