18
Embedded systems Exercise session 6 Preparation of Lab 1

Embedded systems Exercise session 6 Preparation of Lab 1

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Embedded systemsExercise session 6

Preparation of Lab 1

Lab 1: Playing with a RTOS

Goals:

Programming an embedded application relying on a RTOS.

Deploying it on an advanced microcontroller.

Experimenting with tasks and semaphores.

Programming environment:

STM32F429/469 discovery board

GCC (C language)

OpenOCD

LibOpenCM3

FreeRTOS

Installing the development tools

Note: All explanations are given for Linux systems!

1. Cross-compiler and libraries

Packages to install:

gcc-arm-none-eabi, binutils-arm-none-eabi,libnewlib-arm-none-eabi (Ubuntu / Mint)

arm-none-eabi-gcc-cs, arm-none-eabi-binutils-cs,arm-none-eabi-newlib (Fedora)

Check that the compiler works:

test.c:

int main(void){return 0;

}

% arm-none-eabi-gcc -nostartfiles test.c

/usr/lib/gcc/arm-none-eabi/10.2.0/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol _start;defaulting to 0000000000008000

2. Programmer

Package to install: openocd

Check that it works:

Unpack your STM32F429/469 development board (to be handledwith care!).

Check the jumpers:

Connect the board to your computer using the USB Mini-Bconnector.

(The demo program should run.)

% openocd -f /usr/share/openocd/scripts/board/stm32f429disc1.cfg

Open On-Chip Debugger 0.10.0Licensed under GNU GPL v2For bug reports, read

http://openocd.org/doc/doxygen/bugs.htmlInfo : The selected transport took over low-level target control.The results might differ compared to plain JTAG/SWDadapter speed: 2000 kHzadapter_nsrst_delay: 100none separate

srst_only separate srst_nogate srst_open_drain connect_deassert_srstInfo : Unable to match requested speed 2000 kHz, using 1800 kHzInfo : Unable to match requested speed 2000 kHz, using 1800 kHzInfo : clock speed 1800 kHzInfo : STLINK v2 JTAG v36 API v2 SWIM v26 VID 0x0483 PID 0x374BInfo : using stlink api v2Info : Target voltage: 2.860082Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints

^C

Notes:

This command launches a server1, that can be stopped withCtrl-C.

In case of a problem:

Confirm the location of the init script stm32f429disc1.cfg.

Check the permissions of the USB device.

If using a VM, check that the USB device is accessible from within.

1Accessible by telnet 4444.

3. LibOpenCM3

In a newly created working directory:

% git clone https://github.com/libopencm3/libopencm3% cd libopencm3% make

4. FreeRTOS

Download it from https://www.freertos.org.

% cd ..% unzip FreeRTOSv202107.00.zip% ln -s FreeRTOSv202107.00 freertos

5. Test program

Download the test program from the webpage of the course. Besure to select the version suited for your board! (STM32F429 orSTM32F469).

% tar xvfz test-stm32f4x9.tgz

At this stage, your directory structure should look like this:

drwxr-xr-x .drwxr-xr-x ..lrwxrwxrwx freertos -> FreeRTOSv202107.00drwxr-xr-x FreeRTOSv202107.00drwxr-xr-x libopencm3drwxr-xr-x test-stm32f429 or test-stm32f469

6. Adapting the Makefile

cd test-stm32f429 (or test-stm32f469)

In Makefile, check that the following definitions are correct foryour system:

## Local configuration ############################################LIBOPENCM3-DIR = ../libopencm3/FREERTOS-DIR = ../freertos/LIBC-DIR = /usr/arm-none-eabi/lib/thumb/v7e-m+fp/hard/LIBGCC-DIR = /usr/lib/gcc/arm-none-eabi/10.2.0/thumb/v7e-m+fp/hard/

PGM-CONFIG = /usr/share/openocd/scripts/board/stm32f429disc1.cfg

## Project files ##################################################

EXEC = mainSRCS = main.c

###################################################################

7. Building the test program

% make

8. Deployment on the development board

Connect the board to your computer.

% make flash

In case of a problem:

Recheck everything carefully.

Ask for help!

Lab 1

Problem statement: Program a dining philosophers simulation, usingseparate tasks for each philosopher.

Note: The number of philosophers is arbitrarily fixed at 6.

Procedure:

1. Make a fresh copy of the test program into a new directory.

Remove everything but the initialization code and the creation ofone task.

Check that everything works, and take some time to play around.

The following functions are available:

set_led(led, on_off): turns a LED on or off, where

led is LED_GREEN or LED_RED (also LED_ORANGE and LED_BLUEon STM32F469).

on_off is 0 (off) or 1 (on).

vTaskDelay(pdMS_TO_TICKS(δ)): suspends the current taskduring δ milliseconds.

xTaskCreate(code, name, depth, param, prio, NULL):creates a new task, where

code is the entry point of the task.

name is the task name, used for debugging.

depth is the size of the stack, expressed in words.

param is a void * parameter passed to the new task.

prio is the priority of the task.

Note:

Low priority numbers correspond to low priorities.

The maximum priority is defined in the configuration fileFreeRTOSConfig.h.

For this lab: use priorities from 1 to 6.

2. Create a task that implements a single philosopher, identified by anumber from 1 to 6. Make him/her repeatedly think, sit down, eat,and leave.

The following functions are available for implementing thephilosophers’ actions:

think(void)

eat(void)

sit(int n)

leave(int n)

take_fork(int n, int s)

release_fork(int n, int s)

Note: n is the philosopher’s number; s is the side (0: left, 1: right).

Check that everything works as expected.

3. Program a loop creating 6 tasks, each managing a differentphilosopher.

Use a single function implementing the same code for each task.

When creating a task, use the parameter to pass it a number from 1to 6. (The simplest solution is to cast the void * value to an int.)

Assign a different priority (from 1 to 6) to each task.

Check that the program works correctly.

Do you know whether your solution can lead to a deadlock?

4. Implement an access control mechanism to limit the occupancy ofthe room to 3 philosophers.

The simplest solution is to use a semaphore.

The following functions are available:

xSemaphoreCreateCounting(max_v, initial_v): createsa new semaphore, where

max_v is the maximum value that it can take,

initial_v is its initial value.

This function returns a handle (of type SemaphoreHandle_t) thatidentifies the newly created semaphore.

xSemaphoreTake(handle, timeout): implements the waitoperation, where

handle is the handle of the semaphore,

setting timeout to portMAX_DELAY specifies an infinite timeout.

xSemaphoreGive(handle): implements the signal operation,where handle is the handle of the semaphore.

Does it work? Do you think that a deadlock is still possible?

5. Send your code (only main.c) [email protected], using the subject“[INFO0064] Lab 1 result”. List the members of your group in thebody of your message.