admin
发表于: 2015-4-28 16:50:34 | 显示全部楼层

ST ARM Cortex-M7 STM32 F7 RTOS Demo

With projects for the IAR and ARM Keil Embedded Compilers


Introduction


This page provides documentation for the FreeRTOS demo that targets the STM32756G-EVAL Evaluation Kit, which incorporates an STM32F7 ARM Cortex-M7 microcontroller from STMicroelectronics. Pre-configured build projects are provided for both the IAR and ARM Keil tools.


Notes on using the STM32F7 Cortex-M7 RTOS demo


Please read all the following points before using this RTOS port.

Source Code Organisation

The Demo Application

RTOS Configuration and Usage Details

See also the FAQ My application does not run, what could be wrong?, noting in particular the recommendation to develop with configASSERT() defined in FreeRTOSConfig.h.


Source Code Organisation


The FreeRTOS distribution available from this site contains the source files for all the FreeRTOS ports, and the projects for all the FreeRTOS demo applications. It therefore contains many more files than are required to use the STM32 F7 microcontroller. See the Source Code Organization section for a description of the directory structure and information on creating a new FreeRTOS project.

The IAR Embedded Workbench for ARM worksapce for the STM32F7 demo application is called RTOSDemo.eww, and is located in the FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL directory.


The ARM Keil project for the STM32F7 demo application is called RTOSDemo.uvprojx, and is located in the FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL directory.


The ST ARM Cortex-M7 Demo Application


Hardware Setup


The demo uses an LED that is connected to port F pin 10 by positioning jumper JP24 so the jumper is connecting pin 2 to pin 3.

STM32F7_Cortex_M7_Jumper_Setting.png

jumper setting to connect LED to Cortex-M7 device

JP24 is used to connect pin F10 to the LED


Functionality


The STM32 F7 demo application can be built to create either a simple blinky demo, or a comprehensive test and demo application. The constant mainCREATE_SIMPLE_BLINKY_DEMO_ONLY, which is defined at the top of main.c, is used to switch between the two.


Functionality with mainCREATE_SIMPLE_BLINKY_DEMO_ONLY set to 1


To build the simple blinky demo set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to 1, which results in main() calling main_blinky(). main_blinky() creates a simple demo as follows:

The main_blinky() Function:

main_blinky() creates two tasks and one queue before starting the RTOS scheduler.


The Queue Send Task:

The queue send task is implemented by prvQueueSendTask() in main_blinky.c. It writes to the queue every 200 milliseconds.


The Queue Receive Task:

The queue receive task is implemented by prvQueueReceiveTask() in main_blinky.c. It blocks on queue reads to wait for messages from the queue send task - toggling an LED each time a message is received. As the queue send task writes to the queue every 200 milliseconds the queue receive task receives a message and toggles the LED every 200 milliseconds.


Functionality with mainCREATE_SIMPLE_BLINKY_DEMO_ONLY set to 0


To build the comprehensive test and demo set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to 0, which results in main() calling main_full(). The comprehensive test and demo application demonstrates:

Task notifications

Event groups

Software timers

Queues

Semaphores

Mutexes

Most of the created tasks are from the set of standard demo tasks, which have no specific purpose other than to demonstrate how to use the FreeRTOS API, and to test the RTOS port.

A 'check' task is also created which periodically inspects the standard demo tasks to ensure they are executing as expected. The check task also toggles an LED. The LED will toggle every 3 seconds if the check task has determined the demo is executing as expected, and every 200ms if the check task has detected a potential error in any of the standard demo tasks.


Building and executing the demo application - IAR


Open FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/RTOSDemo.eww from within the IAR Embedded Workbench IDE.

Open main.c, and set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to generate either the simply blinky demo, or the full test and demo application, as required.

Ensure the target hardware is connected to the host computer using a suitable debugger interface - the demo was developed and debugged using a J-Link.

Select 'Rebuild All' from the IDE's 'Project' menu, the RTOSDemo project should build without any errors or warnings.

After the build completes, select "Download and Debug" from the IDE's 'Project' menu to program the Cortex-M7 microcontroller, start a debug session, and have the debugger break on entry into the main() function.


Building and executing the demo application - Keil


Open FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/RTOSDemo.uvprojx from within the Keil uVision IDE.

Open main.c, and set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to generate either the simply blinky demo, or the full test and demo application, as required.

Ensure the target hardware is connected to the host computer using a suitable debugger interface - the demo was developed and debugged using a J-Link.

Select 'Build Target' from the IDE's 'Project' menu, the RTOSDemo project should build without any errors or warnings.

After the build completes, select "Start/Stop Debug Session" from the IDE's 'Debug' menu to program the Cortex-M7 microcontroller, start a debug session, and have the debugger break on entry into the main() function.


RTOS Configuration and Usage Details


ARM Cortex-M7 FreeRTOS port specific configuration

Configuration items specific to this demo are contained in FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application. In particular -

configTICK_RATE_HZ

This sets the frequency of the RTOS tick interrupt. The supplied value of 1000Hz is useful for testing the RTOS kernel functionality but is faster than most applications need. Lowering the frequency will improve efficiency.


configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY

See        the RTOS kernel configuration documentation for full information on these configuration constants.


configLIBRARY_LOWEST_INTERRUPT_PRIORITY and configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY

Whereas configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY are full eight bit un-shifted values, defined to be used as raw numbers directly in the ARM Cortex-M7 NVIC registers, configLIBRARY_LOWEST_INTERRUPT_PRIORITY and

onfigLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY are equivalents that are defined using just the 4 priority bits implemented in the STM32F7 NVIC. These values are provided because the CMSIS library function NVIC_SetPriority() requires the un-shifted 4 bit format.


Attention please!: See the page dedicated to setting interrupt priorities on ARM Cortex-M devices. Remember that ARM Cortex-M cores use numerically low priority numbers to represent HIGH priority interrupts. This can seem counter-intuitive and is easy to forget! If you wish to assign an interrupt a low priority do NOT assign it a priority of 0 (or other low numeric value) as this will result in the interrupt actually having the highest priority in the system - and therefore potentially make your system crash if this priority is above configMAX_SYSCALL_INTERRUPT_PRIORITY. Also, do not leave interrupt priorities unassigned, as by default they will have a priority of 0 and therefore the highest priority possible.


The lowest priority on a ARM Cortex-M core is in fact 255 - however different ARM Cortex-M microcontroller manufacturers implement a different number of priority bits and supply library functions that expect priorities to be specified in different ways. For example, on ST STM32F7 ARM Cortex-M7 microcontrollers, the lowest priority you can specify is in fact 15 - this is defined by the constant configLIBRARY_LOWEST_INTERRUPT_PRIORITY in FreeRTOSConfig.h. The highest priority that can be assigned is always zero.


It is also recommended to ensure that all priority bits are assigned as being preemption priority bits, and none as sub priority bits as is done in the demo project by the function call


HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );

Each port #defines 'BaseType_t' to equal the most efficient data type for that processor. This port defines BaseType_t to be of type long.


Interrupt service routines

Unlike many FreeRTOS ports, interrupt service routines that cause a context switch have no special requirements, and can be written as per the compiler documentation. The macro portEND_SWITCHING_ISR() can be used to request a context switch from within an interrupt service routine.

Note that portEND_SWITCHING_ISR() will leave interrupts enabled.

The following source code snippet is provided as an example. The interrupt uses a direct to task notification to synchronise with a task (not shown), and calls portEND_SWITCHING_ISR to ensure the interrupt returns directly to the task.

  1. void Dummy_IRQHandler(void)
  2. {
  3.     long lHigherPriorityTaskWoken = pdFALSE;

  4.     /* Clear the interrupt if necessary. */
  5.     Dummy_ClearITPendingBit();

  6.     /* This interrupt does nothing more than demonstrate how to synchronise a
  7.     task with an interrupt.  A task notificaiton is used for this purpose.  Note
  8.     lHigherPriorityTaskWoken is initialised to zero. */
  9.     vTaskNotifyGiveFromISR()( xTaskToNotify, &lHigherPriorityTaskWoken );

  10.     /* If the task with handle xTaskToNotify was blocked waiting for the notification
  11.     then sending the notification will have removed the task from the Blocked
  12.     state.  If the task left the Blocked state, and if the priority of the task
  13.     is higher than the current Running state task (the task that this interrupt
  14.     interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE
  15.     internally within vTaskNotifyGiveFromISR().  Passing pdTRUE into the
  16.     portEND_SWITCHING_ISR() macro will result in a context switch being pended to
  17.     ensure this interrupt returns directly to the unblocked, higher priority,
  18.     task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */
  19.     portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
  20. }
复制代码

Only FreeRTOS API functions that end in "FromISR" can be called from an interrupt service routine - and then only if the priority of the interrupt is less than or equal to that set by the configMAX_SYSCALL_INTERRUPT_PRIORITY configuration constant (or config LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY).


Resources used by FreeRTOS

FreeRTOS requires exclusive use of the SysTick and PendSV interrupts. SVC number #0 is also used.


Switching between the pre-emptive and co-operative RTOS kernels

Set the definition configUSE_PREEMPTION within FreeRTOSConfig.h to 1 to use pre-emption or 0 to use co-operative. The full demo application may not execute correctly when the co-operative RTOS scheduler is selected.


Compiler options

As with all the ports, it is essential that the correct compiler options are used. The best way to ensure this is to base your application on the provided demo application files.


Memory allocation

Source /Portable/MemMang/heap_4.c  is included in the ARM Cortex-M7 demo application project to provide the memory allocation required by the RTOS kernel. Please refer to the Memory Management section of the API documentation for full information.


Miscellaneous

Note that vPortEndScheduler() has not been implemented.




跳转到指定楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 33 | 回复: 52



手机版|

GMT+8, 2024-12-21 21:25 , Processed in 0.054663 second(s), 9 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表