0% found this document useful (0 votes)
11 views

LAB4_RTOSforSTM32 (1)

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

LAB4_RTOSforSTM32 (1)

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

School of Engineering and Sciences

Robotics and Digital Systems Engineering


TE2003B. System Design on Chip
Module 3 Real Time Operating Systems

LAB 4 RTOS for STM32

Purpose
Create Tasks using the CMSIS-RTOS layer for the STM32 devices.

Hardware
● Nucleo-F103RB
○ 1 Nucleo-F103RB development board
○ 1 USB-miniUSB cable for connecting Nucleo kit to your PC

Software
● STM32CubeIDE

Procedure
Setting Up your project for CMSIS-RTOS.
1. Create a New Project from an existing ‘.ioc’ configuration.
○ File → New → STM32 Project
2. Select the NUCLEO-F103RB as the Board.
3. Change the Project Name, select the Location, select STM32Cube as the Project
Type and click the Finish button.
○ If an ‘Initialize all peripherals with their default Mode?’ message
appears after clicking the Finish button, click on the Yes button.
School of Engineering and Sciences
Robotics and Digital Systems Engineering
TE2003B. System Design on Chip
Module 3 Real Time Operating Systems

4. Make the following configurations in the .ioc file.


○ The Pinout view should be like the following:
 Default initializations for:
USER Led, USER PushButton, and USART 2 (used by USB
cable, 115200 bps, 8 data, 1 stop)

○ Verify that in the Clock Configuration section, the HCLK is at 64 MHz.


○ Select the Pinout & Configuration section.
 Select the System Core section
● In the SYS section, select Serial Wire as the Debug option and
TIM4 as the Timebase Source.

 Select the Middleware and Software section


● Select the FREERTOS section
a. In the Mode section, select CMSIS_V1 as the Interface
option.
School of Engineering and Sciences
Robotics and Digital Systems Engineering
TE2003B. System Design on Chip
Module 3 Real Time Operating Systems

b. In the Configuration section, select Advanced settings


tab and Enabled as the USE_NEWLIB_REENTRANT
configuration.

c. In the Configuration section, select the Tasks and


Queues tab and double click on the ‘defaultTask.’ Select
osPriorityIdle as the Priority option.

5. Save (Ctrl+S) the configurations and generate the code, click on Yes.
6. Setup the printf( ) function:
○ Include the <stdio.h> library:

/* Private includes
------------------------------------------------ */
/* USER CODE BEGIN Includes */
#include <stdio.h>
/* USER CODE END Includes */
School of Engineering and Sciences
Robotics and Digital Systems Engineering
TE2003B. System Design on Chip
Module 3 Real Time Operating Systems
○ Rewrite the _write() function:

/* Private user code


------------------------------------------------ */
/* USER CODE BEGIN 0 */
int _write(int file, char *ptr, int len){
int DataIdx;
for(DataIdx=0; DataIdx<len; DataIdx++){
while(!( USART2->SR & USART_SR_TXE ));
USART2->DR = *ptr++;
}
return len;
}
/* USER CODE END 0 */

○ Use the printf() in the StartDefaultTask():

/* USER CODE END Header_StartDefaultTask */


void StartDefaultTask(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
printf("Hello RTOS World!!\r\n");
osDelay(1);
}
/* USER CODE END 5 */
}

7. Compile and Run you project. You should see the “Hello from RTOS World!!”
message in a serial terminal.

You might also like