Lab 6 Report
Lab 6 Report
Lab 6 Report
1 / 33
PG-N-MM
(MICROCONTROLLER LABORATORY)
1.1 Be familiar with the basic operation and specification of STM32 Board and be familiar with the
functionalities of Integrated Development Environment (IDE).
1.2 Know how to program the STM32 board to execute desired tasks.
2. INTRODUCTION / THEORY
Arduino is a tiny computer that you can program to process inputs and outputs going to and
from the chip. The Arduino is what is known as a Physical or Embedded Computing platform,
which means that it is an interactive system that through the use of hardware and software
can interact with its environment.
The STM32F334 discovery kit helps you to discover the digital power features of the
STM32F334 and to develop your applications easily.
Microcontroller features
• STM32F334C8T6 in LQFP48 package
• ARM®32-bit Cortex®-M4 with FPU
• 72 MHz max CPU frequency
• VDD from 2.0V to 3.6 V
• 64 KB Flash
• 16 KB SRAM
• GPIOs (37) with external interrupt capability
• 12-bit ADCs with 15 channels (2)
• 12-bit DAC channels (3)
• USARTs (3)
• I2C (1)
• SPI (1)
• High-resolution Timer (1)
• Other Timers (8)
• Watchdog Timers (2)
• Ultra-fast Analog Comparators (3)
• Operational Amplifiers (1)
• CAN interface 2.0 B Active (1)
Board features
• On-board ST-LINK/V2-1 debugger/programmer with SWD connector
o Selection-mode switch to use the kit as a standalone ST-LINK/V2-1
• Flexible board power supply
o USB VBUS or external source (5 V)
o Power management access point
• High brightness LED dimming with buck converter
• Four user LEDs: LD3 (red), LD4 (orange), LD5 (green) and LD6 (blue).
• Two push buttons: USER and RESET
o Virtual Com port
o Mass storage (USB Disk drive) for drag'n'drop programming
o Debug port
Faculty of Engineering Technology Page No. 4 / 33
The Arduino IDE 2 features a new sidebar, making the most commonly used tools more
accessible.
• Verify / Upload - compile and upload your code to your Arduino Board.
• Select Board & Port - detected Arduino boards automatically show up here, along with the port
number.
• Sketchbook - here you will find all of your sketches locally stored on your computer. Additionally,
you can sync with the Arduino Cloud, and also obtain your sketches from the online environment.
• Boards Manager - browse through Arduino & third party packages that can be installed. For
example, using a MKR WiFi 1010 board requires the
Arduino SAMD Boards
package installed.
• Library Manager - browse through thousands of Arduino libraries, made by Arduino & its
community.
• Debugger - test and debug programs in real time.
• Search - search for keywords in your code.
• Open Serial Monitor - opens the Serial Monitor tool, as a new tab in the console.
The Arduino IDE 2 is a versatile editor with many features. You can install libraries directly, sync
your sketches with Arduino Cloud, debug your sketches and much more.
Faculty of Engineering Technology Page No. 6 / 33
3. EQUIPMENT
4. PRELIMINARIES
Requirements
• Windows - Win 10 and newer, 64 bits
• Linux - 64 bits
• macOS - Version 10.15: "Catalina" or newer, 64 bits
Faculty of Engineering Technology Page No. 7 / 33
(i) Downloading the Arduino IDE 2 is done through the Arduino Software page. Here you will
also find information on the other editors available to use.
Installation – Windows
(ii) To install the Arduino IDE 2 on a Windows computer, simply run the file downloaded from
the software page.
(v) You can now use the Arduino IDE 2 on your Windows computer!
Installation – macOS
(vi) To install the Arduino IDE 2 on a macOS computer, simply copy the downloaded file into
your application folder.
(vii) You can now use the Arduino IDE 2 on your macOS computer!
Faculty of Engineering Technology Page No. 9 / 33
(iv) Click OK
5. PROCEDURES
(i) To make your STM32 device compatible with Arduino’s IDE, we need to install the STM32
support. This can be achieved by clicking: Arduino IDE > File > Preferences:
(ii) In the Preferences dialog window, add the following URL to the "Additional Boards
Managers URLs" field, then click OK:
https://github.com/stm32duino/BoardManagerFiles/raw/main/pack
age_stmicroelectronics_index.json
Faculty of Engineering Technology Page No. 21 / 33
(iv) Select “Contributed” type, search for "STM32 MCU based boards" and install:
Faculty of Engineering Technology Page No. 22 / 33
(ix) Great! Your board is now correctly selected and recognized by the Arduino IDE!
(x) Let us start programming our STM32 device with a simple Blink LED through the Arduino’s
IDE.
(xi) To perform this task, we have a few options. These options include programming
the STM32 MCU through the Serial Wire Debug, using an STLINK device (external
or embedded), and also through bootloader serial port, DFU etc.
(xii) Let us see below how to program our STM32 MCU using Arduino’s IDE to get it
working properly as expected:
(xiii) Having the STM32CubeProgrammer installed helps program the STM32 Nucleo,
Discovery or Eval board through SWD, Serial or DFU methods with ease. The
STM32CubeProgrammer enables drag-and-drop flash programming, so there is no
need for a separate debug probe. However, this step is optional and you can
program directly via Arduino's IDE as well.
(xiv) Go to Arduino IDE, and go to File > New Sketch.
Faculty of Engineering Technology Page No. 23 / 33
/*
Blink
Turns an LEDs on for one second, then off for one second, repeatedly.
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(PB6, OUTPUT);
pinMode(PB7, OUTPUT);
pinMode(PB8, OUTPUT);
pinMode(PB9, OUTPUT);
}
(xvi) Go to Tools > Board Part Number > Generic F334C8Tx. Leave other settings as default.
(xvii) With the microcontroller correctly selected and the board properly connected, let us define
the COM Port where the device is connected. Go to Tools > Ports > Select the Port Number:
(xviii) Click the Upload Button, wait for the code to be compiled and the board to be programmed:
Faculty of Engineering Technology Page No. 25 / 33
Please discuss and draw the programming flow chart for Task 1:
Faculty of Engineering Technology Page No. 26 / 33
(i) Copy the coding below. Save the “Sketch” as Lab6_Task2 in the subfolder “Lab MicroC”
created.
/*
Button_LEDs_STM32
This code is designed to read USER button and turn ON LEDs for 5 seconds when the button
is pressed.
*/
int buttonState = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(PA0, INPUT);
pinMode(PB6, OUTPUT);
pinMode(PB7, OUTPUT);
pinMode(PB8, OUTPUT);
pinMode(PB9, OUTPUT);
}
buttonState = digitalRead(PA0);
if(buttonState == HIGH){
digitalWrite(PB6, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB7, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB8, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000); // wait for 5 seconds
}
else{
digitalWrite(PB6, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB8, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB9, LOW); // turn the LED off by making the voltage LOW
delay(5000); // wait for 5 seconds
}
}
Faculty of Engineering Technology Page No. 28 / 33
(ii) Click the Upload Button, wait for the code to be compiled and the board to be programmed.
(iii) Observe the output. Try and press the user button (blue button). What happened? Does the
LEDs light up as expected? Discuss the reason why the button is not responsive.
Please discuss and draw the programming flow chart for Task 2:
Faculty of Engineering Technology Page No. 29 / 33
Please discuss and draw the programming flow chart for Task 2b:
Faculty of Engineering Technology Page No. 31 / 33
/*
Button_LEDs_STM32
This code is designed to read USER button and turn ON LEDs for 5 seconds when the button is
pressed.
*/
int buttonState = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(PA0, INPUT);
pinMode(PB6, OUTPUT);
pinMode(PB7, OUTPUT);
pinMode(PB8, OUTPUT);
pinMode(PB9, OUTPUT);
}
buttonState = digitalRead(PA0);
if(buttonState == HIGH){
digitalWrite(PB6, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB7, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB8, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000); // wait for 5 seconds
}
else{
digitalWrite(PB6, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB8, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB9, LOW); // turn the LED off by making the voltage LOW
}
}
Faculty of Engineering Technology Page No. 33 / 33
5. CONCLUSION
This study of the STM32F334C8 microcontroller and Arduino IDE seamlessly merges the power of the
STM32 platform with the user-friendly Arduino environment, offering users a robust foundation for
advanced embedded systems projects. For example we can make the LEDs turn on and off in various type
of combination for instance make the traffic light LED and more. This integration lowers the entry barrier,
empowering enthusiasts and professionals to focus on creativity and innovation, making it an ideal for
students to explore embedded system development