Embedded Programming

Embedded Programming

By Saheen Palayi | 18 March 2021 | FAB Academy 2021

week 8 assignment is to read a microcontroller data sheet and to program the board (which created on week6) to do something, with as many different programming languages and programming environments as possible

Embedded System

Multiple components interfaces jointed together and also embed in to a chip or chip based board for performing a dedicated task is called embedded system. Mostly in a Embedded system contains a programable chip like Microcontroller ,Microproccessor or FPGA chip etc..


Embedded_system

The Picture shows the applications of embedded system in Everyday life.many of them based on microcontrollers

Microcontrollers

we all know about computer and its CPU Unit.Microcontroller is like a CPU unit of a Computer it has RAM,ROM,BUS,I/O Ports,Processor everything embed into a single silicon chip.


Embedded_system

The below picture shows internal blocks of a Motorola microcontroller which is introduced in 1978.they called "computer on chip" ,source link


Embedded_system

Atmel AVR Microcontroller

The board that I made during electronics design is based on an Atmel AVR Chip called Attiny84.Atmel was a company who make AVR series 8 bit single chip using modified Harvard architecture called RISC.Recently another chip making company called Microchip Acquired atmel.So all the supports of AVR is now coming from Microchip


During my elctronics engineering diploma course I explored 8051 and AVR architectures well and made many projects and programs using 8051,Atmega328,Atmega8,Attiny85,Attiny45 ..etc.. So this is the first time I'm using Attiny 84


Embedded_system

I found the Atmel Attiny24/44/84 datasheet online from microchip website. This chip created Based on Advanced RISC Architecture.24,44 and 84 are same design only the memory capacity is different 84 has more program memory than 44.

week 8 Group assignment is to compare the performance and development workflows for other architectures


STM32 Nucleo

I selected STM32 for the experimental explorations.This works on ARM Architecture.FAB LAB Kochi has a hardware development board called STM32 Nucleo this board is based on a STM32 Series Chip from ST Microcontrollers for learning I just plugged the Nucleo Development board to the PC


Embedded_system

After plugged it opens a directory like a Flash drive .the directory contain an html file I thought may be its a tutorial


Embedded_system

But it was like a login page into some kind of webapp,may be a online compailer .


Embedded_system

I sign up any way and by clicking sign up and filled all the information required then logged in to the web app after confirming the email the app is called Mbed OS


Embedded_system

it opens a webpage which has information about the board and pin diagrams etc.....On the top corner I clicked on te compiler button that's open a new web app in new tab


Embedded_system

Then opened new Program under the 'New' tab and selected a by default blink test program


Embedded_system

Then hit ok The program opened .cpp file its in C++ and I double clicked the .cpp file


Embedded_system

The cpp file is opened which contains the basic LED blinking The LD2 is on board led


Embedded_system

Then I just compiled the program by clicking te compile button on the menu tab


Embedded_system

The it started to compile the program and then downloaded a bin file as the result


Embedded_system

Then I saved the .bin file and copied the .bin file to the flash directory of the Nucleo development board


Embedded_system

then I checked the board ,but it's not blinking anything!! . it's like no response.so I search for tutorials on YouTube and find out one embed os web app tutorial.It seems I did everything same but didn't work anyway I decided to go with other tutorial to try other ways to programing the board .I found another good tutorial by digikey It was awesome and I followed the video and downloaded the programing software they suggested


Embedded_system

After installing the IDE I opened the STM32 cube IDE and created a new stm32 project by following file>>new>>STM32Project


Embedded_system

Then I selected the target as NUCLEO-F303RE board on the board selector tab


Embedded_system

That shows a picture of the board that I'm using and clicked on it and clicked on the next button


Embedded_system

Then i given a project name as 'First_step' and selected the targeted language as 'C' language then clicked finish


Embedded_system

Then the IDE starts to download some resource files from the internet for the NUCLEO-F303RE development board


Embedded_system

After the downloading the Project window opened and also shows the graphical pin diagram of the STM32 Microcontroller of the NUCLEO-F303RE board


Embedded_system

We can Also see the set-up diagram of the stm32 nucleo-f303re development board under the clock configuration tab


Embedded_system

I dont need to change that.but if I making a custom board then I have change this accordingly


Embedded_system

On the tool tab we can calculate current consumption of the Microcontroller,many other features are available too


Embedded_system

I opened the main.c file That I want work with by following First_step>>Core>>src>>main.c on the left


Embedded_system

Scrolled down to find while loop to add my code in loop we can write what I want do with the Microcontroller


Embedded_system

we can declare each IO pins as whatever we want with it on the graphical pin diagram by right clicking on the pins


Embedded_system

while scrolling down we can also see how pins are declared in the program.the n I started to write the code for blinking the on board led by following the digikey tutorial.


Embedded_system

for finding the syntax I found the doc for stm32L4 by typing 'stm32l4 hal' on google will get this PDF doc I clicked on the GPIO gernric drivers and searches for the led toggle command,there is lot of commands are there for other applications



Embedded_system

I found the Toggle pin command and entered the syntax in the code also a delay command.For toggle command it required two parameters 1)which POART we are using then 2) which PIN we are using


Embedded_system

On the graphical PIN diagram we can see the LD2 LED connected to the GPIO_PIN_5 at POARTA (PA5)


Embedded_system

Then I build the program following Project>>Build but got an error and rebuilds again after fixing the error


Embedded_system

The while loop of the code that I created is given below

while (1)   //loop
      {
     HAL_GPIO_TogglePin (GPIOA,GPIO_PIN_5); //togling the LED LD2 Connected to the PIN 5
     HAL_Delay(1000);   // 1 second delay (1000ms = 1 sec)

     /*USER CODE END WHILE*/

     /*USER CODE BEGIN 3*/
      }
    

Embedded_system

After the successful building ,to upload the program I clicked run>>Debug As>>STM32 Cortex-M C/C++ Application


Embedded_system

I leaves everything default on the De-Bug menu and clicked OK


Embedded_system

It STM32 Cube IDE automatically dedicated the NUCLEO-F303RE development board and says it's firmware need to be update


Embedded_system

I clicked 'OK' then it started to update and after updating I decided to do the drag and drop programing that I tried before



It started to blink,So the firmware was the problem that's it didn't works earlier with embed Os programing method after the firmware updating program working fine.then I continue in the Cube IDE I run the program again


Embedded_system

After downloading the program to the Board it asked to switch the debugging mode or not .I clicked OK to see the debugging process



In debug-mode we can see the RGB LED on the Debugging section blinking to indicate communication in between the Microcontroller and the cube-IDE


Embedded_system

After Clicking the resume button the program will starts to run.We can pause the program and Can be execute step by step it was awesome

I did some adding and changes in the program for fast blinking in the cube ide.as per my experience the coding in STM32 Cube IDE is more simpler than the AVR Embedded C. I like it so Much

while (1)   //loop
                {
               HAL_GPIO_TogglePin (GPIOA,GPIO_PIN_5); //togling the LED LD2 Connected to the PIN 5
               HAL_Delay(1000);   // 100 milli second delay
               HAL_GPIO_TogglePin (GPIOA,GPIO_PIN_5);
               HAL_Delay(100);
               HAL_GPIO_TogglePin (GPIOA,GPIO_PIN_5);
               HAL_Delay(100);
               /*USER CODE END WHILE*/
          
               /*USER CODE BEGIN 3*/
                }
              


Back to Top Back to top