lab2

.pdf

School

McMaster University *

*We aren’t endorsed by this school

Course

4DS4

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

25

Uploaded by GrandIce96200

Report
McMaster University Dept. Electrical and Comp. Engineering 4DS4 - Winter 2023 LAB 2 Introduction to FreeRTOS 1 Lab Rules You have to stick to your Lab slot assigned to you on Mosaic. You have to use the Teams you created in Lab0 on github classroom. Prepare a demonstration for all the Lab experiments, and get ready to be asked in any part of the experiments. The demonstrations of Lab 0 will be held starting from Feb 26th at the first hour of each lab slot . All the activities and questions written in blue should be documented and answered in your lab report. Each team needs to submit one report for all the members, and the first page of the report should contain the team number and the names of its members. The submission should be through github classroom at 12pm on the day of your demo. Put the report in a PDF format. submission will be through github classroom. The first page (After the title page) of the report must include a Declaration of Contributions , where each team member writes his own individual tasks conducted towards the completion of the lab. You also need to submit all source files that you modify or add through out the lab. General Note: Make sure to push all your code to the assignment repository from the lab computer before leaving the lab room because your saved work may be deleted after the lab slot. 2 Lab Rules 3 Lab Goals - Build FreeRTOS and run it on FMUK66. - Understand and reate tasks in FreeRTOS. - Learn different techniques for inter-tasks communication and synchronization. - Configure interrupts inside FreeRTOS. - Use timers to create single shot and periodic events. 1
McMaster University Dept. Electrical and Comp. Engineering 4DS4 - Winter 2023 - Setup and use the radio controller. - Interpret the UART signal returned from the radio receiver. 4 Github Classroom You should accept the lab assignment through this link: https://classroom.github.com/a/1Ia7lPTx Again, you have to use the same Team you have created for your group in Lab0. 5 Lab Components Prepare the following modules before starting the in-lab experiments. 1. 1x RDDRONE-FMUK66 board. 2. 1x Segger J-Link EDU Mini debugger. 3. 3x micro USB cables. 4. 1x Debug breakout board with the 7-wire cable. 5. 2x Telemetry modules. 2
McMaster University Dept. Electrical and Comp. Engineering 4DS4 - Winter 2023 6. 1x 6-wire cable. 7. 1x FlySky controller (radio transmitter). 8. 1x FlySky receiver (radio receiver). 3
McMaster University Dept. Electrical and Comp. Engineering 4DS4 - Winter 2023 6 Experiments Experiment 1: FreeRTOS Hello World In this experiment, we import the FreeRTOS “Hello World” project from the SDK to the base project for all the following experiments. Then we will create multiple tasks with different priorities. Experiment Setup: Part A In this part, we create a task that prints “Hello World” in the console. 1. In the MCUXpresso IDE, select ”Import from SDK examples(s)” under the Quickstart Panel. 2. Select ”frdmk6ff” and click Next rtos examples check freertos hello and select semihost Finish 3. From Miscellaneous under Quickstart Panel, select Quick Settings SDK Debug Console Semihost Console. 4. In freertos hello.c file, clear everything except the includes, and create an empty main function. 5. Make sure the project builds successfully. 6. Add the following code in the main function. 1 int main( void ) 2 { 3 BaseType_t status; 4 5 /* Init board hardware. */ 6 BOARD_InitBootPins(); 7 BOARD_InitBootClocks(); 8 BOARD_InitDebugConsole(); 9 10 status = xTaskCreate(hello_task, "Hello_task" , 200, NULL, 2, NULL); 11 if (status != pdPASS) 12 { 13 PRINTF( "Task creation failed!.\r\n" ); 14 while (1); 15 } 16 17 vTaskStartScheduler(); 18 while (1) 19 {} 20 } In line 10, xTaskCreate creates a new task, which has the name “Hello task” - the second argument to the function. The first argument is a pointer to the task func- tion, which we will define below. The third argument is the required stack size for the task execution, so it should be large enough for the local variables and the function calls 4
McMaster University Dept. Electrical and Comp. Engineering 4DS4 - Winter 2023 in the task. To pass values to the parameters of the task function, you can provide the address of those values through the fourth argument. If the task does not require any arguments, a NULL can be passed as in our case. The fifth argument is used to specify the priority of the task, where 0 is the lowest priority and 4 is the highest. Finally, the last argument is for returning a handler for the task, and NULL can be passed if the handler is not needed. You do not have to memorize these inputs. Luckily, FreeRTOS documentation is more than enough to understand its APIs (functions). The documentation is coupled with the header files. For instance, in your workspace, you can find the documentation for xTaskCreate in “freertos freertos kernel include task.h” along with an example on how to use it. Alternatively, you can also use the FreeRTOS manual (FreeRTOS Reference Manual V10.0.0.pdf) uploaded on Avenue under Labs/Documentation. Refer to Section 2.6 for more details regarding vTaskCreate. In line 17, vTaskStartScheduler begins the FreeRTOS system scheduler. The tasks will not execute until the scheduler 7. Add the function of “hello task” above the main. Note that any task function should return void and accept void pointer as an input. void hello_task( void *pvParameters) { while (1) { PRINTF( "Hello World\r\n" ); vTaskDelay(1000 / portTICK_PERIOD_MS); } } This task will print “Hello World” every second. The delay in the task is created using vTaskDelay, which is different from the software delays we used to create in the previous labs. vTaskDelay removes the task from the running state to the waiting state, and leaves the CPU free to execute another task. Also, note that vTaskDelay accepts the delay in terms of number of ticks (FreeRTOS ticks). To convert the ticks to milliseconds, you need to divide by the constant portTICK PERIOD MS (Check the documentation in task.h or refer to Section 2.9). 8. Connect the J-link debugger to FMUK66. 9. Compile the code and download it to the board. The console must print ”Hello World” every second. Experiment Setup: Part B Now, we build over the previous part by creating another task that accepts arguments passed from xTaskCreate. 1. Make the following edits to your existing code.. 5
McMaster University Dept. Electrical and Comp. Engineering 4DS4 - Winter 2023 char * str = "4DS" ; int main( void ) { BaseType_t status; /* Init board hardware. */ BOARD_InitBootPins(); BOARD_InitBootClocks(); BOARD_InitDebugConsole(); status = xTaskCreate(hello_task, "Hello_task" , 200, NULL, 2, NULL); if (status != pdPASS) { PRINTF( "Task creation failed!.\r\n" ); while (1); } status = xTaskCreate(hello_task2, "Hello_task2" , 200, ( void *)str, 2, NULL); if (status != pdPASS) { PRINTF( "Task creation failed!.\r\n" ); while (1); } vTaskStartScheduler(); for (;;); } The code creates another task, Hello task2, but unlike the original task this one accepts string through the fourth argument of xTaskCreate. 2. Add the following function, hello task2, above the main function. void hello_task2( void *pvParameters) { while (1) { PRINTF( "Hello %s.\r\n" , ( char *) pvParameters); vTaskDelay(1000 / portTICK_PERIOD_MS); } } The input from xTaskCreate reaches the function through its void pointer. 3. Run the code, and you should see both “Hello World” and “Hello 4DS” appear on the console. Problem 1 Write a program that contains two tasks. The first task is responsible for taking an input string from the user through the console and save the string globally . After receiving the string the task should delete itself. On the other hand, the second task waits until the first the string is available, and then it keeps printing it every second. The priority of first task is 2 while it is 3 for the second task. Refer to Section 2.11 for details on ”vTaskDelete”. 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help