Difference between revisions of "Getting Started with CutiPy and FreeRTOS"

From wiki.emacinc.com
Jump to: navigation, search
Line 139: Line 139:
 
[[CutiPy FreeRTOS Documentation | CutiPy FreeRTOS Documentation]]
 
[[CutiPy FreeRTOS Documentation | CutiPy FreeRTOS Documentation]]
  
[[ Cutipy_Test | Cutipy Test Software ]]
+
[[ STM32CubeIDE | STM32CubeIDE ]]
  
[[ Cutipy-MicroPython Bluetooth LE demo | Cutipy-MicroPython Bluetooth LE demo ]]
+
[[FreeRTOS | FreeRTOS]]
 
 
[[ Micropython | Micropython ]]
 
 
 
[[CutiPy-Installing_MicroPython_Firmware | CutiPy-Installing Micropython Firmware]]
 

Revision as of 16:53, 23 March 2020

This page outlines a basic guide to getting starting using the Cutipy.

General Information

Tools Required

  • Desktop PC (Windows/Linux/Mac will work)
  • Micro-USB to USB Cable
  • ST-LINK/V2 in-circuit debugger/programmer for STM8 and STM32 with JTAG 20 pin to SWD 10pin adaptor


Setup

1. Download and install STM32CubeIDE (The IDE used for CutiPy FreeRTOS development, For more information on the STM32CubeIDE click HERE)
2. Download EMAC's CutiPy FreeRTOS project master branch HERE
3. Connect the ST-Link programmer to the CutiPy board for programming

  • Connect the 10 pin SWD connector (small ribbon cable) to the CutiPy Board HDR6. Ensure the the painted red wire of the cable is on the same side as the arrow.Connect the other end to the adaptor, again ensuring the arrow is aligned with painted red wire. Connect the ST-Link to the adaptor with the large ribbon cable, and connect the ST-LINK to your desktop with it's provided USB cable

4. Connect your CutiPy to Desktop using the micro-USB to USB cable. Your board is now powered.
5. Open STM32CubeIDE and import the CutiPy FreeRTOS project

  • If needed, upgrade your ST-LINK firmware by navigating to Help and selecting ST-LINK Upgrade. The ST Link upgrade window will open. Select refresh device list, and then select Open in update mode, and finally Upgrade

STLinkUpgrade.png
6. Build and upload the firmware

  • To build and upload select the debug symbol (To just build select the hammer symbol).

DebugToolbar1.png


Developing with the Cutipy

1.The baseline CutiPy FreeRTOS build has now been uploaded. Connect to the USB virtual com port on a serial terminal using Putty or TerraTerm. The USB virtual com port driver should install automatically after plugging the CutiPy to your PC. After successful installation of the driver STMMicroelectronics Virtual COM Port should be displayed as an available port. Connect to it as you would any normal serial port.
USBcomPORT.png

  • Using a serial terminal program like Putty or Tera Term connect to the port at a baud rate of 115200.

Serial.png



NOTE
The USB virtual com port will adjust it's baud rate to that selected by the terminal. It has been tested to work with standard baud rate selections from 110 to 921600.


2.After connecting the CutiPy FreeRTOS menu will be displayed. Navigate to tests for a demonstration of CutiPy functionality.

TestMenu.png

EMAC CutiPy FreeRTOS Software Description

Project Layout

The CutiPy_FreeRTOS project was developed using the STM32CubeIDE. It contains auto-generated program files and code along with custom files/folders provided by EMAC.



NOTE
editing of auto-generated code blocks and files should be avoided as these portions of the project will be overwritten if the auto-code generation feature of STM32CubeIDE is used (STM32CubeMX). Instead we recommend the user create their own custom folders in the project or just use the EMAC provided folder, CutiPy_User for project development.


Custom EMAC folder include:

  • CutiPy_Drivers provides custom written EMAC driver functions geared towards use with the CutiPy device. All functions are documented in their respective source files, hence the user should look here for function usage-rules and functionality. The functions written at a CutiPy module (COM A, COM B, SD_CARD, RS9116 radio, etc.) or individual driver level and were written with ease of use in mind.CP_FRTOS.c/h contains all FreeRTOS element declarations (Task handles, mutex handle, etc.) Here system level tasks and priorities can be adjusted if needed. CutiPy_Config.h, contains options to turn off the menu to save memory space.
  • CutiPy_Tasks contains the header and source files for the CutiPy freeRTOS for all EMAC provided system tasks. Task descriptions are provided in their respective source files
  • CutiPy_User is an empty project folder dedicated for use by the user.
  • RS9116_1_2_1 and 'RS9116_1_2_1/examples/utilities contain driver files for the Redpine Signals RS9116 radio module.

The only folders of real importance to the user is the CutiPy_Drivers folder. In addition to containing key driver functions it also contains CP_FRTOS.c that lists system task priority, handle and size, and

Other project folders include:

  • Middlewares- contains source files for the USB Virtual Com Port, fatfs (used mainly in conjuction with the sd card), and FreeRTOS.
  • Drivers -contains STMicroelectronic's driver files. The user should look here for driver functionality not covered by the provide emac driver files
  • Src -contains initialization functions, and main.c
  • Inc -contains various include files, but the only one of primary importance FreeRTOSConfig.h file



Software Overview

Diagrammm.png

CutiPy RTOS system-level tasks and synchronization have been provided by EMAC to ease user development.

Feature Description

EMAC has provided custom driver functions for the CutiPy's main peripherals. These are located under CutiPy_Drivers. See the source files for function descriptions. All of EMAC's custom functions will be prefixed by CP_ followed by the the DRIVER_NAME. Functions with the prefix CP_FRTOS utilize an RTOS element and should only be called with the scheduler running. We recommend user files be added to the CutiPy_User or that the user add their own custom folders, and not modify the project code directly. EMAC has provide custom system tasks to ease CutiPy use and jump-start user development.


ADCs- The CutiPy utilizes the STM32F407's 3 internal ADCs. Thirteen ADC pins are available to the user on HDR2. CP_ADC.c CP_FRTOS functions provide thread safe functionality through mutex control of the 3 ADC's. Aside from 'external' pin sampling this driver file also provide functions for sampling the internal temp sensor, the ram back up battery voltage, and the internal reference voltage (used for calculating the voltage from a raw read)

BATTERIES -The CuitPy has the option of being powered by an external 3.7 V 1200mah lithium ion rechargeable battery (EMAC Part#: PER-PWR0101PR0). It also has an onboard, jumper-enable 3.3V RTC-Ram Retention battery (See the CutiPy User Manual for more information. CP_BATTERIES.c contains functions for reading these battery voltages.

'BUTTONS - Depending on the model of your CutiPy there can be up to 5 buttons, 1 Reset button + 4 user buttons (PB1 through PB4). All user buttons except PB3 are interrupt driven (rising and falling edge), hence there respective tasks block (don't run) until the interrupt is generated. PB3 is polled intermittently enough to avoid missed presses, but not so much as to block out other tasks. Callback functions are provided in CP_BUTTONS.C. The user may simply edit these functions directly, to implement unique callback functionality. Button Tasks are located in C

CAN-CAN communication is provided through HDR4 CAN1. The CAN1 subsystem consists of the STM32407's onboard CAN1 module an external CAN tranceiver (TCAN334GDCNT). CP_CAN.c contains easy-to-use functions for message reception/transmission, and module/tranceiver mode manipulation. An example use function is also included, as well as an internal loopback test. Note CAN1 is currently configured for baud rate of 500kHz.

COM_A COM_A consists of UART2 routed to an external RS-232 transceiver connected to the CN2 (The DB9 port). It is configured for baud rate of 115200. CP_COM_A.c provide driver functions for transceiver configuration and message transmission and reception. Two seperate mutexes are provided (CP_COM_A_RX_RecursiveMutexHandle and CP_COM_A_TX_RecursiveMutexHandle).

COM_B COM_B consists of UART3 an RS232 transceiver and an RS422/485 transceiver. The active transceiver is user selectable, and only one can be active at a time. CP_COM_B.c provides driver functions for message transmission/receipt and transceiver selection. For thread safe usage a mutex is provided (CP_COM_B_RecursiveMutexHandle).

DACs The STM32F407 two digital analog converter channels are available on HDR2, pins 20 and 21. Driver functions are provided CP_DAC.c.

DARLINGTON OPEN COLLECTOR DRIVERS Eight gpios are connected and control 8 darlington pair open collector transistors. The Darlington pair transistors have superior current sinking capabilities when compared to the on-board GPIOs. (See the ULN2803A datasheet for more information). A pull-up resistor connects the Collector end of the Darlington transistor to V_HIDRV-This is left floating, but can be used by the user to enable digital toggling between GND and V_HIDRV. With V_HIDRV left unconnected the darlington transistor is used as a switch, that sinks current in the ON position. CP_DARLINGTON_OC.c provides functions for setting/resetting. Thread safe control is achieved through the use of mutexes(CP_DARLINGTON_OC_PGX_RecursiveMutexHandle).

LCD On some models of the CutiPy an NHD-C12832A1Z-FSW-3V3 Liquid Crystal Display (LCD) Module is available for the display of text and simple images. The LCD communicates with the MCU via SPI2. CP_LCD.c contains functions for displaying text, writing individual pixels, issuing commands, etc. Note that mutex control of SPI2 is required as it is shared between the radio module and the LCD module. This feature has already been implemented by EMAC, thus all LCD and radio functions can be used together, from multiple threads/tasks without worrying about conflict.

LEDs Four LEDs are present on the CutiPy board (LD1 - LD4). They are controlled through the toggling of GPIO outputs on the MCU. CP_LEDs.c contains easy to use function for the controlling the LEDs (ON, OFF, Toggle)

RNG The STM32F407 true random number generator (RNG) is pre-initialized. The RNG generates 32 bit random numbers. CP_RNG.c contains simple 'get value' functions. The radio utilizes the RNG for certain encrpytion purposes, for this reason CP_FRTOS_GetRandomValue() should be use for thread-safe access.

RS9116 Wireless Module The external RS9116 Wireless Module enables the development of Bluetooth Low Energy (BLE), Bluetooth (BT) and WLAN applications. In WLAN mode the RS9116 is able function as an access point or a client. The module also has the ability to operate in dual mode (WLAN +BLE). RS9116.c contains initialization functions for the radio, as well as basic use functions like connect/disconnect and sleep. Other functions and advanced usage is covered in the RS9116 documentation.

MicroSD Card The CutiPy comes with a MicroSD slot.The CutiPy_FreeRTOS build comes with FatFs for the manipulation of files (See the FatFs documentation for more information). A Demo functions are provided in CP_SD_CARD.c




Documentation

CutiPy FreeRTOS Documentation




Pages with Related Content

CutiPy FreeRTOS Documentation

STM32CubeIDE

FreeRTOS