You are on page 1of 3

GPIO (Polling Mode)

Blinking LED and Creating a Pulse Train

Lea Dominique Fariola


Department of Electrical and Electronics Engineering
University of San Carlos
Talamban, Cebu City Philippines
leadominiquefariola@gmail.com

Abstract The paper details the activities done in using most interesting part of this is that it is a standalone software
STML053R8T6. The author aims to create a successful running on every type of operating systems.
simulations using software and uploading it to the
microprocessor. However, the actual simulations were not The STM32 is well served with general purpose Input/
presented due to the lack of data upon performing the Output (IO) pins, having typically 80 bidirectional IO pins. The
experiment. STM32CubeMX is the software used in making the IO pins are arranged as five ports each having 16 IO lines.
LED blink and DigilentWaveforms is used in showing the graph
of a 4-pin pulse train with different states at different time. These ports are named A-E and are all 5V tolerant. Many of the
external pins may be switched from general purpose IO to
Index Terms STML053R8T6, STM32CubeMX,
serve as the Input/ Output of a user peripheral, for example a
DigilentWaveforms, blinking LED, pulse train
USART or 12C peripheral. Additionally, there is an external
interrupt unit which allows 16 external interrupt lines to be
I. INTRODUCTION mapped onto any combination of GPIO lines. Each GPIO port
can configure individual pins as input or output with different
The software STM32Cube is part of STMicroelectronics driver configurations. It has registers to write word-wide or for
STMCube original initiative to be able for the developers to atomic bit manipulation. Once a configuration is defined it can
reduce development efforts, time and cost. It is a graphical be locked. Each GPIO port has two 32-bit wide configuration
software configuration tool that allows in generating C registers; these two registers combine to give a 64-bit wide
initialization code using graphical wizards. It truly makes every configuration register. Within these 64 bits each pin has a four-
developers life easier and give them the chance to be not bit field that allows its characteristics to be defined. The four-
afraid in trying something without breaking any costly bit configuration field is made up of a two-bit wide mode field
components. It is a graphical tool software that can be and a two-bit wide configuration field. The mode field allows
download without any licensing wherein it already allows the user to define the pin as an input or an output, while the
anyone to configure STM microcontrollers very easily and configuration field defines the drive characteristics. The input
generating the codes in a step-by-step process wherein a and output data registers allow port wide access to the IO pins.
newbie wont have hard time in understanding the features of Atomic bit manipulation is supported by either using the
this software. Cortex bit banding technique on the input and output data
It embeds comprehensive software platform, delivered per registers, or through two dedicated bit manipulation registers.
series. This software includes STM32Cube HAL which is an One of the most emphasized feature of an STM that is used
STM32 abstraction layer embedded software. It ensures the on this experiment is the IAR Embedded. This toolbox gives
maximized portability of the STM32 portfolio. One of its the user a single toolbox wherein all the components were
before-generating steps is selecting the STM32 Microcontroller already integrated effortlessly. It performs any C/C++ codes
which matches the required set of peripherals needed. As the faster. IAR system work tightly with STMicroelectronics. It
user launches the generation of the initialization of ones C helps STMicroelectronics on its lighting applications.
code. It will be based on the selected configurations of the user. Another software used is the DigilentWaveforms. It is a
The code is then ready to use within several development powerful suite of virtual instruments which brings both the
environments while keeping the next code generation. The analog and digital circuit designs simulating it virtually. It
includes Oscilloscope, Logic Analyzer, Arbitrary Waveform wherein the blinking of the LED is at 5ms. It can also be tested
Generator, Digital Patter Generator, Power Supplies, Voltmeter, by changing the delay time from the previous code.
Virtual I/O devices, and a spectrum analyzer. The Logic
Analyzer tool is a great tool to observe digital signals that
III. CREATING A PULSE TRAIN
works both internal and external clocks and triggers. It has
multiple options in displaying the signal.
The output pins in creating a pulse train are PA1, PB2, PC3,
II. CREATING A NEW PROJECT and PC4. Its individual GPIO mode were configured. Its Clock
STMCubeMX contains menu bar which are the File Menu, Configuration is the same as the first.
Project Menu, Pinout Menu, Window Menu and Help Menu.
The microcontroller was connected first to the computer so that Figure 1. Code Segment in main.c
it will recognize that certain port.
A New Project was selected to make a new project. There
Fig. 1 shows the codes used. It consists of four pins used.
were windows appearing wherein the Releases of
The first group of codes sets Pin1 which makes the Pin1 HIGH
STM32CubeMX must be installed. Anyway, in the New
while the rest of the pins are Reset which means they are at the
Project window, it consists of two tabs MCU Selector and
OFF State. After setting each pin to its corresponding state, a
Board Selector. Under the MCU Selector, the certain type of
delay of 0.5 seconds was coded. The second group sets the
Series, Lines and Package to find the selected MCU. This
second pin to HIGH while the other pins were OFF. This goes
experiment uses the STM32L053R8T6. Its pinout tab then
on until the fourth pin will be the one on HIGH state. It is in
appears along with the clock configuration, configuration and
between 0.5 seconds delay. All of this command were encoded
power consumption calculator tabs.
under USER CODE BEGIN WHILE while(1).
PA5 pin was set as output. This pin can be either Input or
Output. There were settings changed in the Clock
Configuration tab. Then, the next tab which is the
Configuration Tab was selected. The GPIO Configuration
Settings were manipulated. On this settings, the PA5
Configuration was changed for it Maximum output speed into
fast. The output state must be push-pull signal so that its state is
0 if it its OFF and 1 in turning it ON.
Generating the code was designated by a gear icon. This
Figure 2. GPIO PinState
enables the code to be generated with a Toolchain/ IDE of
EWARM. Generating the code means that the IAR Embedded
Workbench IDE will already be viewed and the codes may Fig. 2 shows the code used in defining the state on whether
now be edited. Main.c is where the codes are edited which is the GPIO_PIN_RESET is low and GPIO_PIN_SET is high
then uploaded to the microcontroller. Stm32l0xx_hal_gpio.c under the typedef enum function.
has different function with main.c. It serves as the one that The codes were then Rebuild and uploaded to the
gives firmware functions so that the user manages the microcontroller.
functionalities of the GPIO peripheral. The
stm32l0xx_hal_gpio.h serves as the header file of the GPIO IV. DIGILENT WAVEFORM PROGRAM
HAL module. Each of the output pins which was indicated previously
HAL_GPIO_TogglePin (GPIOA, GPIO_PIN_5) was were connected to specified pins of the test box. The pin
encoded on USER CODE BEGIN 3 of main.c file with a delay assignments were known based from the Appendix of the
of 500 ms. This code lets the output pin 5 to toggle or change Microprocessor System Laboratory Manual. The Analyzer
states between ON and OFF with a delay of 0.5 seconds. After toolbar of Digital menu enables to show the waveform of each
that, the Rebuild All was clicked which is found on Project of the output pins. Before that, each of the test box pin names
Tab. After rebuilding, the total number of errors and total were added.
number of warnings will be displayed. Download and Debug
proceeds the codes encoded before to the microcontroller
wherein one can directly use Digital Logic Analyzers or
Oscilloscope without bulky laboratory instruments instead only
uses pins to connect to the STM32 Nucleo Board to read the
output waveforms done on the microprocessor.

VI. RECOMMENDATIONS
Figure 1. Digital Analyzer output waveform
Upon performing the experiment, the student must take into
Figure 7 shows the output waveform using the account the documentation for not all of the readers have
DigilentWaveforms Logic Analyzer Tool. It performs what the STM32Cube Softwares. Hence, screenshots of the processes
codes generated previously. On the first clock pulse, only the or outputs is very much important.
first DIO or the first pin while the rest of the pins are on their
VII. ACKNOWLEDGMENTS
OFF state. Each of the pins goes to their ON state for 500
.
milliseconds before the ON state of the next pin. This set of
codes just forms a loop. VII. REFERENCES

V.CONCLUSION
STM32CubeMX is a great help in simulating different [1] http://www.st.com/en/development-
codes especially to students wherein there is not enough tools/stm32cubemx.html
resources and not enough understanding wherein one does not [2] https://www.iar.com/iar-embedded-
need simulations anymore. It uses C/C++ which makes it more workbench/partners/stmicroelectronics/
understandable to students which are not that good in [3]http://www.st.com/content/ccc/resource/technical/docum
programming. A 32MHz is set as the resulting frequency so ent/datasheet/8a/f4/9d/d7/61/1b/46/b4/DM00105960.pdf/files/
that it will perform a precise output. GPIO functions as either DM00105960.pdf/jcr:content/translations/en.DM00105960.pdf
Input or Output. It just needs to be specified which will you use [4] (STM32F4 Discovery, n.d.)
on a certain pin.
Also, Digilent Waveform software is also a great help
because it is somewhat a portable laboratory instruments

You might also like