Eced4402 Lab1
Eced4402 Lab1
Written by
Zhouhan Jin (B00838153)
Yuan Chang (B00860600)
Submitted to
5.1
Q1) Size of the Program Flash, and RAM. By referring to the FreeRTOS Chapter 2 Manual, explain
how the Flash and RAM are utilized in a real-time embedded processor. Also, explain how the
memory constrains the task allocation.
STM32F411 has up to 512 Kbytes of Flash memory and 128 Kbytes of SRAM. Flash memory in real-
time embedded processors primarily stores the FreeRTOS code, application code, and other firmware,
retaining its contents even when powered off. RAM provides volatile storage for kernel objects like
tasks and queues, task-specific stack space, and general data.
Each task needs its stack and Task Control Block (TCB); consuming RAM, and insufficient RAM can
lead to task creation failures. Kernel objects like semaphores and queues also require additional.
FreeRTOS provides memory allocation schemes, such as heap_4 and heap_5, that handle dynamic
memory allocations. If the heap becomes exhausted, further dynamic allocations for tasks or other
kernel objects) will fail. Besides, memory fragmentation also constrains task allocation even if total
free memory seems sufficient.
Q2) CPU clock frequency. By referring to the datasheet, define the minimum and maximum input
clock frequency allowed using the crystal oscillator (without adjusting the base speed of the
oscillator). Define the maximum frequency allowed by the microcontroller. (This document may
provide you more information.) How can this be achieved, i.e. what hardware and software tools to do
you have to configure the clock frequency? What are the benefits of having a higher or lower clock
speed. List one benefit for each.
CPU clock frequency is 100MHz. The minimum and maximum input clock frequency allowed using
the crystal oscillator are 4 and 26MHz. The maximum frequency is 100MHz.
With higher clock speed, the CPU could execute the instructions more quickly. With lower clock
speed, the microcontroller’s power consumption can be reduced.
Q3) Describe the characteristics of the different timers (size, speed, modes) that can be useful for
different design requirements.
The table below lists the characteristics of each timer.
The advanced-control timer (TIM1) can be seen as three-phase PWM generators multiplexed on 4
independent channels. Its four independent channels can be used for Input capture, Output compare,
PWM generation (edge- or center-aligned modes), and One-pulse mode output. The advanced-control
timer can work together with the TIMx timers via the Timer Link feature for synchronization or event
chaining. For TIM2, TIM3, TIM4, and TIM5, they all feature four independent channels for input
capture/output compare, PWM or one-pulse mode output. Any of these general-purpose timers can be
used to generate PWM outputs. TIM10 and TIM11 feature one independent channel, whereas TIM9
has two independent channels for input capture/output compare, PWM or one-pulse mode output.
These timers can be synchronized with the TIM2, TIM3, TIM4, TIM5 full-featured general-purpose
timers. They can also be used as simple time bases.
Q4) What timer is the FreeRTOS tick running from? (This may be answered once the lab
manipulations are completed).
Q5) Referring to the STM32F411 datasheet, explain how interrupts are handled by the ARM micro-
controller in a few short sentences. Identify applications for interrupts from different peripherals.
The STM32F411 ARM micro-controller features a Nested Vectored Interrupt Controller (NVIC)
which can manage up to 62 maskable interrupt channels in addition to the 16 interrupt lines of the
Cortex-M4 core, with 16 priority levels. The closely coupled NVIC ensures quick interrupt
processing, automatically saves the processor state during an interrupt, and restores it upon exit with
no overhead. Additionally, there's an External Interrupt/Event Controller (EXTI) with 21 edge-
detector lines, configurable for various trigger events, capable of being connected to up to 81 GPIOs.
Applications: external device communications through GPIOs, clocks and startup, internal reset, real-
time clock, waking up the CPU in sleep mode, and window watchdog.
Q6) Characteristics of the GPIOs. Define the maximum speed, the nominal voltage of the
microcontroller pinout, as well as the voltage tolerance). What is the default voltage level produced
by each pin. Explain the pull-up/pull-down circuitry used by STM32 to define the default level.
The maximum speed is 100 The nominal voltage of the pinout is 3.3V. the input voltage on RST, FT
and TC pins should be in the range from -0.3 to 5.5V when VDD is less than 3.6V but greater than 2V.
If VDD is less than 2V, then the range will change to -0.3 to 5.2V. The input voltage on BOOT0 pin is
from 0 to 9V. The STM32 microcontrollers offer pull-up and pull-down resistors on their GPIO pins
to set a default voltage level. When a pull-up resistor is activated, the GPIO pin defaults to a high
(logical '1') state unless driven low. Conversely, with a pull-down resistor enabled, the pin defaults to
a low (logical '0') state unless driven high. These internal resistors prevent pins from floating and
ensure they remain at a predictable voltage level when not actively driven, essential for reliable
system behavior. Pull-up resistors are designed with a true resistance in series with a switchable
PMOS. Pull-down resistors are designed with a true resistance in series with a switchable NMOS. To
sustain a voltage higher than VDD +0.3 V, the internal pull-up/pull-down resistors must be disabled.
5.2
Q1) What are the libraries that are board specific required for FreeRTOS?
ECED4402_2022/Drivers/CMSIS/Device/ST/STM32F4xx/Include
ECED4402_2022/Drivers/ STM32F4xx_HAL_Driver/Inc
ECED4402_2022/Drivers/ STM32F4xx_HAL_Driver/Inc/Legacy
Q2) What are the FreeRTOS libraries that are common to all micro-controllers?
ECED4402_2022/Drivers/CMSIS/Include
ECED4402_2022\Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2
ECED4402_2022\Middlewares\Third_Party\FreeRTOS\Source\include
ECED4402_2022\Middlewares\Third_Party\FreeRTOS\Source\portable/GCC/ARM_CM4F
Q5) Explain what are the parameters for the xTaskCreate(· · · ) parameters, and how they impact the
code.
xTaskCreate() has following parameters: pvTaskCode, pcName, usStackDepth, pvParameters,
uxPriority, and px CreatedTask. Following table shows the description of each parameter in the book.
Q6) Does it match your predicted output? Why, or why not?
Yes it matched. Since after the reset button is pressed, the main counter has been reset to 0, the
iteration restarts from 0 again.
Q8) What is the difference in behaviour using vTaskDelay(...), in comparison to the use
of a for() loop that implements a delay?
vTaskDelay(...) is more suitable for the multitasking scenarios. Since when it is called, the task will
enter a blocked state, which allows other tasks to execute during the delay period. However, the for
loop will consume CPU cycles while waiting, therefore, other tasks are prevented from running
concurrently. In addition, vTaskDelay(…) will provide more precise and accurate timing as it relies on
the tick timer and scheduler, but timing by for loop might be affected by the CPU.
Code:
/*
* main_user.c
* Created on: Aug 8, 2022
* Author: Andre Hendricks
*/
#include <stdio.h>
//STM32 generated header files
#include "main.h"
//User generated header files
#include "User/main_user.h"
#include "User/util.h"
//Required FreeRTOS header files
#include "FreeRTOS.h"
#include "task.h"
char main_string[50];
uint32_t main_counter = 0;
char LED_string[50];
uint32_t LEDCount = 0;
static void main_task(void *param){
while(1){
print_str("Main task loop executing\r\n");
sprintf(main_string,"Main task iteration: 0x%08lx\r\n",main_counter++);
print_str(main_string);
vTaskDelay(1000/portTICK_RATE_MS);
}
}
void main_user(){
util_init();
xTaskCreate(main_task,"Main Task", configMINIMAL_STACK_SIZE + 100, NULL, tskIDLE_PRIORITY + 2,
NULL);
vTaskStartScheduler();
while(1);
}
5.3
Q1) Identify the period at which the kernel runs. Note that the period is defined by the
configTICK_RATE_HZ in the FreeRTOSConfig.h file.
The input parameter is number of ticks to delay, here is 500/ portTICK_RATE_MS for LED task, and
is 1000/ portTICK_RATE_MS for the main task.
Q4) Explain how the FreeRTOS libraries allow these two functions to operate. For this purpose, draw
a representation of the time slice for this program. Explain your diagram.
The purple column represents the main task and the orange column represents the LED task. The
delay time for the main task is 1000ms, therefore it is executed every 1 second. The delay time for the
LED task is 500ms, therefore it is executed every 0.5 second. The first execution of LED task is let
the LED on and the second execution is let the LED off, as the result, the LED could blink at the
period of 1 second.
Q5 Explain in your own words what is the effect of breaking the code. If necessary, research what this
tool does to the real-time system.
By adding breakpoints, the program will be paused during running. Users could then execute the code
point to point to debug the code. However, the breakpoints may affect the FreeRTOS performance by
disturbing the timing.
Q6 Explain the value of the variables in the RAM as well as the content of the flash during the
execution of the program.
Flash
RAM
Since the RAM stores the variables, data structures and stack for function call, therefore, the values
will change during the program running. The Flash is used to store the program codes therefore the
content of Flash memory do not typically change when the program is executing.
Q7
The video is attached to submission dropbox.
Code:
/*
* main_user.c
Conclusion
In conclusion, we learned the basic operation with the STM32Cube Integrated Development
Environment and used the IDE to add FreeRTOS to a known micro-controller. Through this lab we
learned the FreeRTOS libraries and functionality.