Skip to content

About

Course to use FreeRTOS in STM32 mcrocontrollers

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Curso para usar FreeRTOS en microcontroladores STM32

  • Udemy : Mastering RTOS: Hands on FreeRTOS and STM32Fx with Debugging
  • Instructor: Kiran Nayak

001_Tasks

Crea dos tareas e imprime diferentes mensajes con cada una de ellas. Para leer los mensajes se usa la conexión SWO del debugger y se activa la vista SWV ITM Data Console. Anteriormente, es necesario insertar el código del repositorio del curso en el archivo syscalls.c

  • Se copia la librería de la página web FreeRTOS. Se añaden:
    • Los archivos presentes en el directorio FreeRTOS-Kernel
    • La carpeta FreeRTOS-Kernel\include
    • La carpeta FreeRTOS-Kernel\portable (solo GCC-ARM_CM4F y MemMang-heap_4.c)
  • El archivo FreeRTOSConfig.h se copia del repositorio del curso. Existe uno en examples\template_configuration, pero no está configurado.
  • Se usa TIM6 como Timer para las librerías HAL. Esto se configura en el archvo 001_Tasks.ioc en System Core>Sys>Timebase Source

Instalar SEGGER SystemView

Add include paths to:
	SystemView/Config
	SystemView/SEGGER
	SystemView/SYSVIEW
	RTT/Config
	RTT/RTT

Add the sources to your project:
    Core SystemView Sources:
        SystemView/SYSVIEW/*.c
    Core RTT Sources:
        RTT/RTT/*.c
        RTT/RTT/*.s
    SystemView RTOS Interface:
        e.g. SystemView/Sample/embOS/SEGGER_SYSVIEW_embOS.c/.h
    SystemView Target Configuration:
        e.g. SystemView/Sample/embOS/Config/Cortex-M0/*.c

Update SystemView/Config/SEGGER_SYSVIEW_Conf.h and RTT/Config/SEGGER_RTT_Conf.h to match the target system.

(Alternatively: Do not include SystemView/Config and RTT/Config and place a copy of *_Conf.h in the project.)
  • Add sources of assembly code to C/C++ General > Path and Symbols > Includes (Assembly)
ThirdParty/SEGGER/RTT/RTT
ThirdParty/SEGGER/RTT/Config
/* SEGGER Systemview */
#define INCLUDE_xTaskGetIdleTaskHandle  1
#define INCLUDE_pxTaskGetStackStart	1

#define INCLUDE_vTaskDelete	change from 0 to 1

#include "SEGGER_SYSVIEW_FreeRTOS.h" at the end of the file. 
  • Change inside SEGGER_SYSVIEW_ConfDefaults.h
#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE	change from 1024 to (1024 * 4)
  • Change inside SEGGER_SYSVIEW_Config_FreeRTOS.c
// The application name to be displayed in SystemViewer
#define SYSVIEW_APP_NAME        "FreeRTOS Hello World Application"

// The target device name
#define SYSVIEW_DEVICE_NAME     "NUCLEO-L476RG"
  • Enable the CYCCNT counter inside main.c
#define DWT_CTRL	(*(volatile uint32_t*)0xE0001000)
DWT_CTRL |= (1 << 0);

El programa ya compila.

NOTA:

  • Ahora en vez de añadir vInitPrioGroupValue() en void HAL_MspInit(void) de stm32l4xx_hal_msp.c, añado HAL_NVIC_SetPriorityGrouping(0);

  • De esta forma el programa no se queda atascado en un configASSERT.

Generar archivo para SystemView

  • Para guardar el archivo de datos para el SystemView:

    • Debug, Resume, Pause
    • In Expressions write SEGGER_RTT. Copy aUp[1] > pBuffer position of memory
    • In Memory Browser set this position and export in Raw binary, length 4096 (.SVdat)
    • Load this file in SystemView

002_LED_Tasks

Se crean 3 tareas de la misma prioridad para manejar 3 leds de la placa.

Creación de proyecto:

  1. Se crea el proyecto para la NUCLEO-L476RG
  2. Se crea un directorio común (common) que incluye las librerías de FreeRTOS y de SEGGER externo al proyecto.
  3. Se añade los paths:
Assembly:
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\RTT\RTT</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\RTT\Config</includepath>
GNU C:
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\FreeRTOS</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\FreeRTOS\include</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\FreeRTOS\portable\GCC\ARM_CM4F</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\SystemView\Config</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\SystemView\Sample\FreeRTOSV11</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\SystemView\SEGGER</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\SystemView\SYSVIEW</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\RTT\Config</includepath>
<includepath>C:\WorkSpaceST\Course_RTOS\common\Third Party\SEGGER\RTT\RTT</includepath>
  1. Se exportan a "includepathsettings" para facilitar este paso en el próximo proyecto
  2. Se copian los cambios en main.c del proyecto 001_Tasks
  3. Se excluye sysmem.c del proyecto
  4. Se eliminan el syscalls.c las funciones SVC_Handler, PendSV_Handler, SysTick_Handler (generadas por FreeRTOS)

003_LED_Block_Tasks

Se crean 3 tareas de la misma prioridad para manejar 3 leds de la placa. Se usa vTaskDelay()

En la segunda parte de este ejercicio, en la lección 80, se prueba el consumo cuando el microcontrolador se pone en SLEEP.

Para alimentar la placa NUCLEO-L476RG:

  • Cambiar el jumper JP5 hacia la posición más cercana a E5V
  • Alimentar desde CN7 (E5V-GND)

Para que compile bien es necesario usar Clean project antes de compilar.

  • Consumo Sin sleep = 60 mA
  • Consumo Con sleep = 50 mA

005_LED_Tasks_Notify

  1. Se crea el proyecto para la NUCLEO-L476RG.
  2. Arrastrar carpeta common al proyecto (seleccionar Link to files and folders). Eliminar check en Propiedades - C/C++ Build - Exclude resource from build
  3. Importar paths guardados en archivo "includepathsettings.xml" desde Propiedades - C/C++ General - Paths_and_Symbols
  4. Se excluye sysmem.c del proyecto
  5. Systick lo utiliza FreeRTOS, así que tenemos que configurar TIM6 como timebase de la librería HAL en archivo .ioc SYS - Timebase Source
  6. En archivo .ioc desactivar la generación del código de las interrupciones que genera FreeRTOS NVIC - Code_generation (uncheck System service call, Pendable request, System tick)
  7. Añadir configuración de Priority group value en "stm32l4xxhal_msp.c"
  8. Añadir FreeRTOSConfig.h en Core - Inc
  9. Compila correctamente.

006_LED_Btn_ISR and 007_Task_Priority

  1. Seguir los pasos de "005_LED_Tasks_Notify"

  2. Ver resultado en SEGGER_SystemView:

    • Target - Recorder Configuration: UART, COM8, 500000
    • Start Recording (F5)

008_Queues and timers

  1. Seguir los pasos de "005_LED_Tasks_Notify"
  2. Añadir RTC y USART2 marcando interrupción en NVIC y con prioridad igual o mayor que 5 (escogemos 6)
  3. Al usar USART2, excluyo common/ThirdParty/SEGGER, que también usa el USART2.
  4. Cambiar configUSE_TIMERS de 0 a 1 en "FreeRTOSConfig.h". También comentar #include "SEGGER_SYSVIEW_FreeRTOS.h"
  5. Eliminar referencias en main.c a SEGGER SYSVIEW

010_BinSemaTasks

011_CtnSemaTasks

012_Mutex_using_Bin_Sema

013_MutexAPI

  1. Seguir los pasos de "005_LED_Tasks_Notify". Acepto inicializar los periféricos.
  2. Excluyo common/ThirdParty/SEGGER. En otro caso, genera multiples warnings.
  3. Copio código main.c del curso por trozos.
  4. Debug con Tera Term funciona correctamente.

About

Course to use FreeRTOS in STM32 mcrocontrollers

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages