Chap04 Poo
Chap04 Poo
Emir DAMERGI
INSAT - GL3 - 2023
Advantages of OOP:
Wrapper
layer Wrapper Functions
HAL
(ST
FWL)
HARDWARE
Emir DAMERGI – INSAT - 2023 4
OOP For EMBEDDED SYSTEMS
Case Study:
Configuring
GPIO Pins as
Inputs
Case Study:
Configuring
GPIO Pins as
Inputs
PinModeNames.h
File containig OO Pins/Modes
definitions (Platform Independent)
Pin Represention:
0xYZ
with
F : Pin 15
Emir DAMERGI – INSAT - 2023 7
OOP For EMBEDDED SYSTEMS Case Study: Configuring GPIO Pins as Inputs
parameters
Case Study:
Configuring
GPIO Pins as
Inputs
STM32_GPIO_Wrapper.c -1-
STM32_GPIO_Wrapper.c -2-
Function to translate
PinName (OO) to GPIOX (Firmware)
Emir DAMERGI – INSAT - 2023 11
OOP For EMBEDDED SYSTEMS Case Study: Configuring GPIO Pins as Inputs
PinName pin
PinNames.h
STM32_GPIO_Wrapper.c -5- Adapt OO definitions to ST Library
Modes – PinName to GPIOx
STM32_GPIO_Wrapper.c -6-
STM32_GPIO_Wrapper.c -7-
APB2ENR
. 4 3 2 1 0
. C B A
ShortHand notation
If (ObjectName = = ..)
PinAsInput.h
Constructors
Methods
Operator (=)
ShortHand
Emir DAMERGI – INSAT - 2023 18
OOP For EMBEDDED SYSTEMS Case Study: Configuring GPIO Pins as Inputs
Main.cpp
OO (PinAsInput Class)
Main.cpp
2
Emir DAMERGI – INSAT - 2023
0
THE MBED ECOSYSTEM
HW ST HW TI HW …
Emir DAMERGI – INSAT - 2023 24
The MBED ECOSYSTEM for ARM processors based SOCs
Example1: Toggle the Led connected to Pin PC9 when Button PA0 pressed.
#include "mbed.h"
Classes defining
Pins configured DigitalIn mybutton (USER_BUTTON); //USER_BUTTON = PA0
in digital input
resp outupt DigitalOut myled (LED1); //LED1 = PC9
int main() {
Objects with pin
number as while(1) {
parameter if (mybutton == 0) // Button is pressed
{
myled = !myled; // Toggle the LED state
wait(0.2); // 200 ms
}
}
}
Emir DAMERGI – INSAT - 2023 25
The MBED ECOSYSTEM for ARM processors based SOCs
se trouve un microcontrôleur
l'Atmega328p
cartes Arduino :
• Simple à programmer
• Langage C++
http://arduino.esp8266.com/stable/package_esp8266com_index.json
https://dl.espressif.com/dl/package_esp32_index.json
https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json
33
Digital I/O : GPIO Pins & Ardunio Numbering
Arduino Connector
When programming SoCs Input/output operations, the
used pin(s) must be identified.
For Arduino IDE, the connector pinout identifiers can be
GPIO4
used D0..D15 (Digital) and A0..A5 (Analog)
For Pins that are not tied to the Arduino Connector, the
ardunio pin numbers must be known. For each installed
Example for Arduino Pin
board, a pins_arduino.h file contains the pin mapping.
numbering (ESP8266)
#define PushButton 4
Arduino Connector
Example:
An application that continously :
Tests if the PushButton is pressed (Low level).
If yes : The Led is Turned ON
GPIO4
No: the Led is Turend OFF
GPIO4
Example:
An application that continously :
Tests if the PushButton is pressed
(Low level).
If yes : The Led is Turned ON
No: the Led is Turend OFF
3
7
USART:
Synchronous
Asynchronous
while ( !Serial) {//wait for Serial port Initialization The default Serial object names in arduino are:
} Serial (the UART connected to the USB/Serial
} Converter)
Serial1 for the second UART, Serial2, etc…
4
Emir DAMERGI – INSAT - 2023
0
UART Communications : Receiving Data
char rc;
rc = Serial.read();
receivedChars[nbr] = rc;
nbr++;
}