Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
FreeRTOS peripheral control functions and FreeRTOS+CLI Example

Introduction

************* Introduction **************************************************

The examples defined in this project demonstrate:

  • The blocking FreeRTOS UART API being used with FreeRTOS+CLI to create a command console.
  • The fully asynchronous FreeRTOS USART API being used to send a string to an RS232 echo server, and receive the reply. A loopback connector can be used in place of an echo server.
  • The blocking FreeRTOS USART API being used with FreeRTOS+CLI to create a command console.
  • The standard ASF USB CDC driver being used with FreeRTOS+CLI to create a command console.
  • The FreeRTOS TWI API being used to write to, and read from, an I2C EEPROM. The example can be configured to use either the fully asynchronous FreeRTOS API, or the blocking FreeRTOS API.
  • The FreeRTOS SPI API being used to write to, and read from, an SPI flash. The example can be configured to use either the fully asynchronous FreeRTOS API, or the blocking FreeRTOS API.

A FreeRTOS software timer is used to give visual feedback of the system status. The software timer toggles LED mainSOFTWARE_TIMER_LED every 200ms to show the system is running, and turns LED mainERROR_LED on if any errors have been latched.

This file also provides default implementations of the FreeRTOS idle, tick malloc failed, and stack overflow hook functions. See http://www.freertos.org/a00016.html.

Readers are recommended to also read the application note that accompanies the FreeRTOS ASF API.

USART Echo/Loopback Example

************* USART Echo/Loopback Example ***********************************

  • Functionality -

Two tasks are created; A transmit (or Tx) task, and a receive (or Rx) task. The transmit task periodically sends one of a set of strings to the USART peripheral. The receive task expects to receive each transmitted string. The receive task latches an error is the characters it receives do not exactly match the characters it expects to receive.

  • Software Configuration -

The USART loopback example is created if the confINCLUDE_USART_ECHO_TASKS constant is defined. confINCLUDE_USART_ECHO_TASKS can be defined in conf_example.h.

The USART loopback example and the USART CLI example cannot be used at the same time as both examples access the same USART port.

  • Hardware Setup -

The example needs every character that is transmitted on the USART port to be received on the same USART port. This can be achieved using an RS232 echo server (see http://www.serialporttool.com/CommEcho.htm for an example), or by simply linking pin 2 on the RS232 port to pin 3 on the same RS232 port.

By default, the RS232 communication is configured to use 115200 baud, 8 data bits, no parity, one stop bit, and no flow control.

USART Command Console using FreeRTOS+CLI

************* USART Command Console using FreeRTOS+CLI **********************

  • Functionality -

A task is created that receives command line input on a USART, then sends the results of executing the command to the same USART peripheral.

A number of example command implementations are provided. These include:

  • "echo-parameters". This command accepts a variable number of parameters. Each parameter entered is echoed back individually.
  • "echo-three-parameters". This command is similar to "echo-parameters", but will only accept exactly three parameters.
  • "task-stats". This command displays a table that includes a line for each executing task. The table displays information including the task state, and the task's stack high water mark. (the closer the stack high water mark value is to zero the closer the task has come to overflowing its stack).
  • "run-time-stats". This command also displays a table that also includes a line for each executing task. This time the table displays the amount of time each task has spent in the "Running" state (actually executing). Both absolute and percentage times are shown. See http://www.freertos.org/rtos-run-time-stats.html
  • "create-task". This command takes a single numerical parameter. It creates a new task and passes the command line parameter into the task as the task parameter. The task that is created displays the parameter value on the command console. The "task-stats" command can be used both before and after executing the "create-task" command to see the newly created task appear in the table of running tasks.
  • "delete-task". This command deletes the task that was created by the "create-task" command.

Software Configuration -

The USART command console example is created if the confINCLUDE_USART_CLI constant is define. confINCLUDE_USART_CLI can be defined in conf_example.h.

The USART loopback example and the USART CLI example cannot be used at the same time as both examples access the same USART port.

  • Hardware Setup -

The RS232 USART port needs to be connected to a dumb terminal, such as TeraTerm. For the cleanest output, the terminal should be set not to echo characters, transmit line feeds (LF), and receive carriage returns (CR).

By default, the RS232 communication is configured to use 115200 baud, 8 data bits, no parity, one stop bit, and no flow control.

UART Command Console using FreeRTOS+CLI

************* UART Command Console using FreeRTOS+CLI **********************

  • Functionality -

The functionality is exactly as that described for the USART command console above. Only the communication interface is different. The UART peripheral is used as a com port.

  • Software Configuration -

The UART command console example is created if the confINCLUDE_UART_CLI constant is define. confINCLUDE_UART_CLI can be defined in conf_example.h.

  • Hardware Setup -

The RS232 UART port needs to be connected to a dumb terminal, such as TeraTerm. For the cleanest output, the terminal should be set not to echo characters, transmit line feeds (LF), and receive carriage returns (CR).

By default, the RS232 communication is configured to use 115200 baud, 8 data bits, no parity, one stop bit, and no flow control.

USB/CDC Command Console using FreeRTOS+CLI

************* USB/CDC Command Console using FreeRTOS+CLI ********************

  • Functionality -

The functionality is exactly as that described for the USART command console above. Only the communication interface is different. The standard ASF USB CDC driver is used as a virtual com port.

  • Software Configuration -

The USB/CDC command console example is created if the confINCLUDE_CDC_CLI constant is defined. confINCLUDE_CDC_CLI can be defined in conf_example.h.

You may be asked to install a USB driver the first time the host computer is plugged into the target. The file atmel_devices_cdc.inf is provided with this demo for this purpose. Select the provided atmel_devices_cdc.inf file if the install new hardware wizard executes on the host computer when the USB cable is inserted.

  • Hardware Setup -

The virtual com port was tested with the following settings: 115200 baud, 8 data bits, no parity, one stop bit, and no flow control. The settings might not be critical.

TWI EEPROM Read and Write

************* TWI EEPROM Read and Write ***********************************

  • Functionality -

A task is created that writes a bit pattern to an I2C EEPROM, then reads back from the EEPROM to ensure the data read back matches the data previously written. An error is latched if the data read back does not match the data that was written.

The example can be configured to use either the blocking or the fully asynchronous FreeRTOS functions.

  • Software Configuration -

The TWI EEPROM example is created if the confINCLUDE_TWI_EEPROM_TASK constant is define. confINCLUDE_TWI_EEPROM_TASK can be defined in conf_example.h.

Set mainDEMONSTRATE_ASYNCHRONOUS_API to 1 to use the fully asynchronous FreeRTOS API, or 0 to use the blocking FreeRTOS API. Other tasks will execute while the task is blocked. mainDEMONSTRATE_ASYNCHRONOUS_API is defined in this file.

  • Hardware Setup -

The example requires that a TWI/I2C EEPROM be present on the evaluation kit. As the example uses the EEPROM built onto the evaluation kit, no hardware configuration is required.

SPI flash Read and Write

************* SPI flash Read and Write ***********************************

  • Functionality -

A task is created that writes a bit pattern to an SPI flash, then reads back from the flash to ensure the data read back matches the data previously written. An error is latched if the data read back does not match the data that was written.

The example can be configured to use either the blocking or the fully asynchronous FreeRTOS functions.

  • Software Configuration -

The SPI flash example is created if the confINCLUDE_SPI_FLASH_TASK constant is define. confINCLUDE_SPI_FLASH_TASK can be defined in conf_example.h.

Set mainDEMONSTRATE_ASYNCHRONOUS_API to 1 to use the fully asynchronous FreeRTOS API, or 0 to use the blocking FreeRTOS API. Other tasks will execute while the task is blocked. mainDEMONSTRATE_ASYNCHRONOUS_API is defined in this file.

  • Hardware Setup -

The example requires that an SPI flash be present on the evaluation kit. As the example uses the flash built onto the evaluation kit (SAM3N-EK only), no hardware configuration is required.