Microcontroller Systems (KON 309E) : Lecture Notes (WEEK 1)
Microcontroller Systems (KON 309E) : Lecture Notes (WEEK 1)
Microcontroller Systems (KON 309E) : Lecture Notes (WEEK 1)
(KON 309E)
LECTURE NOTES
(WEEK 1)
Introduction
The main difference from a microprocessor is that external components (such as peripheral
units, memory, clock, etc.) are required to operate a microprocessor as a computer.
However, all the required modules are included and ready to use in the microcontrollers. It is
the reason for microcontrollers to be sometimes called as a computer-on-a-chip or a single-
chip-computer. For basic microcontroller definition and tools for programming, you may
refer to “Lecture Notes-2.pdf” document.
There are hundreds of different microcontrollers that differ from each other by features
such as processing speed, memory size, the intention of use, number and variety of
peripheral units, etc. Microcontrollers are used in automatically controlled products and
devices, such as automobile engine control systems, implantable medical devices, remote
controls, office machines, appliances, power tools, toys, and other embedded systems [2].
For an overview on the selection of microcontrollers and basic issues on the programming
tools and languages, you may refer to the document Lecture Notes-1V1.pdf included in the
course materials directory.
Clock: For the operation of all sequential (logic) circuits, such as memory and
registers, in a microcontroller, a clock signal is a must. The execution speed of the
instructions in the CPU also depends on the frequency of this clock signal.
Furthermore, the clock is required for data transfer via communication protocols.
The source of the clock signal can be internal or external depending on the
microcontroller and mostly provided by the oscillators.
Program memory: The on-chip program memory or ROM (Read Only Memory) is a
reserved area where the program code (instructions) is stored. It is also called as a
(programmable) flash memory. Some data used by the microcontroller during
program execution may also be stored in ROM.
Data memory: The data memory or RAM (Random Access Memory) is a reserved
area which is used to store the temporary variables, constants, registers, etc. used
during the operation of the microcontroller.
In this course, it is planned to use an STM32 board which has an ARM Cortex-M3 based core
operating at 72MHz, high-speed embedded memories, and an extensive range of peripheral
units. In the following figure, a mini development board that consists of the STM32F103C8T6
microcontroller is illustrated.
Detailed information for this development board and pin-out scheme can be found in the
laboratory experiment sheets.
STM32 microcontrollers are classified as low, medium, high, and XL-density devices
depending on the model and flash memory size. STM32F103C8T6 microcontroller has 64
Kbytes of flash memory; therefore, it can be found under the medium-density devices. It is
important to know this information since it can be important during the usage of some
peripheral units.
ICode Bus: It provides connection between the instruction bus of the core and flash memory
instruction interface.
DCode Bus: It connects the load and debug access bus (DCode Bus) of the core to the flash
memory data interface.
System Bus: This bus connects the system bus of the core (peripherals bus) to the bus matrix
that manages arbitration between the core and the DMA.
DMA Bus: DMA bus provides connection between the AHB (master interface) and bus matrix
that manages the access of CPU DCode and DMA to RAM, Flash and peripherals.
Figure 2.2: System architecture for the medium-density STM32 devices [3].
Note: DMA (direct memory access) is a structure used for data communication between the
memory and other devices. Its advantage is that the CPU is partially disabled during the data
communication, thus speeding up the data flow and making the central processing unit less
busy. As a result, the CPU will cease to be the main element in the data flow and provide
opportunities for other processes. The data flow will also be accelerated due to a shorter
route.
Bus Matrix: It manages the access arbitration between the core system bus and the DMA
master bus.
AHB (Advanced High performance Bus): It is a bus protocol introduced by ARM, and used for
connecting components that need higher bandwidth on a shared bus. It is also capable of
waits, errors, and burst data transfers.
APB (Advanced Peripheral Bus): It is another bus protocol designed for low bandwidth
control accesses, such as register interfaces on system peripherals. APB has a much reduced
and low complexity signal list, and burst data transfers are not supported.
3. Preliminaries for Programming
Finally, the truth table for the XOR operation is given as below:
Binary is, on the other hand, the most commonly used non-base 10 system, and consists of
the numbers 0 and 1. Please check some examples illustrated below.
Table 3.4: Conversion between the decimal and binary numbers.
Base-10 Base-2
1 0 0 0 0 1 0b00001
4 0 0 1 0 0 0b00100
14 0 1 1 1 0 0b01110
29 1 1 1 0 1 0b11101
There exist another number base, also known as the hexadecimal system, which is
commonly used in coding and computer systems. In this number base, the digits 0−9 and the
letters, which represent two digits A(10), B(11), C(12), D(13), E(14), F(15), are used.
The conversion between the binary and hexadecimal system is used much in embedded
programming. For this purpose, first of all, any digit of hexadecimal number system can be
represented using only 4 bit as follows, since there exist only 16 digits in hexadecimal
number system.
Therefore, the simplest way is to create a group of 4 bit of binary numbers, and then replace
the groups with its equivalent hexadecimal digits.
Examples:
⏟ ⏟
⏟ ⏟
⏟ ⏟
Bitwise operations allow us to perform logical operations for each bit in the number. These
operations are given in the following table:
Table 3.6: Bitwise operations and examples.
Operator Symbol Example
Bitwise AND & 0b01110100 & 0b00111101 0b00110100
Bitwise OR | 0b01110100 | 0b00111101 0b01111101
Bitwise XOR ^ 0b01110100 ^ 0b00111101 0b01001001
Bitwise Left Shift << 0b00000000 |= (1 << 4) 0b00010000
Bitwise Right Shift >> 0b01000000 >> 3 0b00001000
Bitwise NOT ~ ~ 0b01100001 0b10011110
Bitwise operations are going to be used many times during the programming of the STM32
microcontroller, especially while writing to the registers.
References:
[1] R. Toulson and T. Wilmshurst, Fast and effective embedded systems design: applying the
ARM mbed, Newnes, pp.3-16, 2016.
[2] URL-1, https://en.wikipedia.org/wiki/Microcontroller, “Microcontroller”, Wikipedia,
reached in 24.09.2020.
[3] URL-2, https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-
stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-
mcus-stmicroelectronics.pdf, STM32F103xx Reference Manual, RM0008, reached in:
24.09.2020.