1. Code Architecture
The overall code project of remote control consists of 7 working groups, namely Remoter, Show, Driver, STM32_LIB, USB, USB/Lib and Drv_Point, as shown in the figure below.
The specific code functions of each group are shown in the following table.
Group
|
Function
|
Remoter
|
Contains remote control data, joystick button processing, etc.
|
show
|
Responsible for the display menu UI and other code implementation of the remote control
|
Driver
|
The underlying driver of each module
|
STM32_LIB
|
STM32 Standard Library
|
USB
|
USB related
|
USB/Lib
|
USB Library
|
Drv_Point
|
System key library
|
2. Code Walkthrough
The main function of the system is the starting point of the entire code. There are three main things to do in the main function: 1. Initialize peripherals and parameters, 2. Poll thread functions, 3. Menu display logic. The code is shown in the figure below.
Each thread function in the system has been assigned a running cycle, and different things are executed in different threads. The thread switching is done through simple logical processing, and the system running time is provided by sysTick, which is the system's "tick" clock. The entry of each thread is as follows.
There are functions with a period of 1000ms, a period of 50ms, a period of 10ms, a period of 4ms, and a period of 2ms.
The core parts of the entire remote control's logic processing and data exchange are all in the Remoter working group. The code framework in this group is shown in the figure below.
DT.c is responsible for communication data processing with the flight control, host computer, etc., that is, disassembling packages, encapsulating packages, extracting key data, etc. The following figure shows the processing of data transmitted by the flight control.
Among them, Stick.c is the joystick logic processing, which mainly analyzes the ADC value collected by the joystick and determines the logic that needs to be executed. The last cocobit.c is responsible for the communication between the cocobit programming board.
The working group "show" is mainly responsible for the overall menu UI display, which has been encapsulated here.
The working group "Driver" is responsible for the underlying drivers of each module, such as the joystick ADC configuration, NRF24L01 SPI driver, etc.
The working groups "USB" and "USB/Lib" are responsible for creating a virtual serial port through the STM32's built-in USB to facilitate communication with the host computer.
Save, compile and finally burn the code into the remote control, and it can be used normally with the flight control. As shown in the figure below, 1 is saving, 2 is compiling, and 3 is downloading and burning.