Skip to content

Commit

Permalink
Improve Getting Started section
Browse files Browse the repository at this point in the history
  • Loading branch information
JcZou committed Jul 24, 2023
1 parent 5230d0d commit 18ba1d5
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 77 deletions.
Binary file added docs/figures/cox_hexa_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/cox_quad_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/fixwing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/hexa_+.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/hexa_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/octo_+.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/octo_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/quad_+.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/quad_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 150 additions & 0 deletions docs/introduction/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
## Directory Structure

Understanding the directory structure of FMT-Firmware is crucial before compiling the firmware. Below is a general overview of the typical directory structure you can expect to find in the FMT-Firmware project:

```
FMT-Firmware/
|-- rtos/
| |-- rt-thread
|-- src/
| |-- driver
| |-- hal
| |-- lib
| |-- model
| |-- module
| |-- protocol
| |-- task
| |-- startup.c
| |-- ...
|-- target/
| |-- amov
| |-- coolflt
| |-- cuav
| |-- cubepilot
| |-- minimum
| |-- pixhawk
| |-- qemu
|-- unit_test/
| |-- test_case1.c
| |-- ...
|-- .clang-format
|-- README.md
|-- LICENSE
|-- .gitignore
|-- ...
```

Explanation of directories and files:

1. **src/**: This directory holds the primary source code files of the firmware. The `startup.c` file is typically the entry point of the firmware. Other directories, such as `driver`, `hal`, `lib`, `modules`, etc., represent distinct components of the firmware, making it modular and organized.
2. **rtos/**: Within this directory, you'll find the code related to the Real-Time Operating System (RTOS) utilized in the FMT-Firmware project. It specifically contains the RTOS implementation, and in this case, it utilizes the "rt-thread" RTOS.
3. **target/**: This folder accommodates the Board Support Package (BSP) specific to the hardware targeted for the firmware. The BSP is a crucial component that facilitates interaction between the firmware and the hardware it runs on.
4. **unit_test/**: The `unit_test/` directory comprises code for unit tests, which play a vital role in testing individual components or units of the firmware in isolation, ensuring robustness and correctness. Unit tests are essential for maintaining the reliability of the firmware.

This enhanced explanation provides a clearer understanding of the directory structure of the FMT-Firmware project, highlighting the role and content of each directory within the context of firmware development.


## Build

To learn how to build and download the firmware, kindly consult the README file of the each BSP. For this explanation, we will use ICF5 as an example to illustrate the firmware building process. The README file typically provides detailed instructions on the necessary steps, dependencies, and configurations required for a successful firmware compilation and download.

- [AMOV ICF5](https://github.com/Firmament-Autopilot/FMT-Firmware/blob/master/target/amov/icf5/README.md)
- [CUAV V5+](https://github.com/Firmament-Autopilot/FMT-Firmware/blob/master/target/cuav/v5_plus/README.md)
- [Pixhawk 4](https://github.com/Firmament-Autopilot/FMT-Firmware/blob/master/target/pixhawk/fmu-v5/README.md)
- [Pixhawk 2.4.6](https://github.com/Firmament-Autopilot/FMT-Firmware/blob/master/target/pixhawk/fmu-v2/README.md)
- [QEMU vexpress-a9](https://github.com/Firmament-Autopilot/FMT-Firmware/blob/master/target/qemu/qemu-vexpress-a9/README.md)

### Build Firmware

To build the firmware for a quadcopter, follow these steps:

1. Navigate to the relevant directory for the quadcopter target:

```
cd FMT-Firmware/target/amov/icf5
```

2. Initiate the build process with the `scons` command:

```
scons -j4
```

The `-j4` flag enables parallel building with 4 jobs, accelerating the build process and reducing compilation time. By default, the firmware is built for the Quadcopter vehicle (`vehicle=Multicopter --airframe=1`). For other vehicle and airframe types, please refer to the [Vehicle/Airframe](introduction/vehicle_type.md) section.

### Download Firmware

There are two methods available for downloading firmware to the hardware:

1. **Download Script**: To use the download script, navigate to the `icf5` directory and execute the command `python3 uploader.py`. Ensure that your hardware is connected via USB.

```shell
FMT-Firmware\target\amov\icf5> python .\uploader.py
waiting for the bootloader...
Error: no serial connection found
wait for connect fmt-fmu...
Error: no serial connection found
wait for connect fmt-fmu...

Found board id: 50,0 bootloader version: 5 on COM7
sn: 000000000000000000000000
chip: 22020419
family: b'GD32F4[5|7]x'
revision: b'?'
flash: 1015808 bytes
Windowed mode: False

Erase : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting. Elapsed Time 9.687
```

> If you encounter a `"ModuleNotFoundError: No module named 'serial'"` error, it indicates that the **pyserial** component is missing. You can install it by running `pip3 install pyserial`.

If the script is unable to automatically detect the port, you have the option to specify the port manually using the `--port` option. For example, you can use the following command to indicate the port explicitly:

```
python3 uploader.py --port COM3
```
2. **J-Link**: If you have a JLink, you can connect it to the board's debug port to download the firmware. For more detailed information, please refer to the [Debug](https://firmament-autopilot.github.io/FMT-DOCS/#/introduction/debug) section in the documentation.
> Take caution not to overwrite the bootloader during the firmware download process.
These two methods provide different options for downloading the firmware onto the hardware, offering flexibility and ease of use to suit your specific requirements.
When the system is up and running, the system banner is displayed either via `serial0` (serial console) or can be viewed by entering `boot_log` in the QGroundControl (QGC) mavlink console. This banner provides important information about the system's status and configurations, allowing users to monitor the system's behavior and ensure it is functioning correctly.
```
-----------FMT Bootloader v1.x-----------
Board Type: 50
Board Revision: 0
Board Flash Size: 1015808
App Load Address: 0x8010000

_____ __
/ __(_)_____ _ ___ ___ _ ___ ___ / /_
/ _// / __/ ' \/ _ `/ ' \/ -_) _ \/ __/
/_/ /_/_/ /_/_/_/\_,_/_/_/_/\__/_//_/\__/
Firmware.....................FMT FW v0.5.5
Kernel....................RT-Thread v4.0.3
RAM.................................448 KB
Target...........................Amov-ICF5
Vehicle........................Multicopter
Airframe.................................1
INS Model..................Base INS v0.3.2
FMS Model..................Base FMS v0.4.0
Control Model.......Base Controller v0.2.4
Task Initialize:
mavobc................................OK
mavgcs................................OK
logger................................OK
status................................OK
vehicle...............................OK

```
102 changes: 102 additions & 0 deletions docs/introduction/download.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

## Download Firmware

The FMT code is available on [Github](https://github.com/Firmament-Autopilot). To download the FMT-Firmware, use the following git command. If you don't have [git](https://git-scm.com/downloads) installed, please install it before proceeding.

```
git clone https://github.com/Firmament-Autopilot/FMT-Firmware.git --recursive --shallow-submodules
```

> Please be aware that the FMT-Firmware includes submodules. To ensure you download the submodules as well, use the *--recursive* flag when fetching the repository.
## Toolchain

FMT utilizes cross-platform toolchains, enabling its development across various operating systems, such as Windows, Linux, and Mac. This flexibility ensures that developers can work on the project seamlessly, regardless of their preferred platform.

### Compiler

FMT-Firmware specifically relies on the **arm-none-eabi- toolchain 7-2018-q2-update** version, which can be obtained from [this link](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads). It is essential to adhere to this specified compiler version to prevent any unforeseen errors or unpredictable behaviors during development. Using other compiler versions is not recommended to maintain stability and consistency in the project.

After installing the compiler, the next step is to create a new environment variable called `RTT_EXEC_PATH`. This variable should point to the full path of the compiler's bin directory. Here's how you can set up the environment variable:

1. Find the path to the compiler's bin directory, which contains executable files like `gcc`, `gdb`, etc.

2. Set the `RTT_EXEC_PATH` environment variable to this full path. The process varies depending on your operating system:

- **Windows**: Open the Control Panel, go to System and Security > System > Advanced system settings > Environment Variables. Click on "New" under "User variables" and enter the variable name as `RTT_EXEC_PATH` and the variable value as the full path to the compiler's bin directory.

<img src="../figures/win_exec_path.png" width="30%">

- **Linux/Mac**: Open a terminal and edit the shell configuration file (e.g., `~/.bashrc`, `~/.bash_profile`, or `~/.zshrc`, depending on your shell). Add the following line to the file:

```bash
export RTT_EXEC_PATH=/path/to/compiler/bin
```

Save the file and run `source ~/.bashrc` (or the corresponding file for your shell) to apply the changes to the current terminal session.

By setting the `RTT_EXEC_PATH` environment variable, you enable the system to locate and use the compiler tools easily during the development process.

### Construction Tool

FMT employs SCons as its construction tool, which serves as an enhanced and cross-platform alternative to the traditional Make utility. SCons configuration files are written in Python, offering a user-friendly and powerful approach to address build-related challenges. Python's flexibility and ease of use make configuring the build process a more intuitive and efficient experience. With SCons, developers can enjoy a streamlined and effective build system that adapts smoothly across different platforms.
Prior to installing SCons, it is essential to verify whether Python 3 is already installed on your system. If you don't have Python 3 installed, you can download it from [the official website](https://www.python.org/downloads/). Python serves as a prerequisite for SCons, as SCons configuration files are written in Python scripts. Once Python 3 is installed, you can proceed with the installation of SCons to enable a smoother and more efficient build process for your projects.

After ensuring that Python 3 is installed on your system, follow these steps in the terminal:

1. To install the latest version of SCons, enter the following command:

```bash
> pip3 install scons
```

2. Once the installation is complete, you can check if SCons was installed successfully by entering the following command:

```bash
> scons --version
```

3. If the version information is printed on the terminal, it indicates that SCons has been installed successfully, and you are now ready to use it as your construction tool for projects.

```bash
> scons --version
SCons by Steven Knight et al.:
SCons: v4.4.0.fc8d0ec215ee6cba8bc158ad40c099be0b598297, Sat, 30 Jul 2022 14:11:34 -0700, by bdbaddog on M1Dog2021
SCons path: ['C:\\Users\\zouji\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\SCons']
Copyright (c) 2001 - 2022 The SCons Foundation
```

### IDE

Using Visual Studio Code (VS Code) as the Integrated Development Environment (IDE) is highly recommended for working with FMT and SCons. You can download VS Code from [the official website](https://code.visualstudio.com/).

VS Code provides a powerful and user-friendly development environment with a wide range of extensions and features, making it ideal for working on projects like FMT that utilize SCons as the build tool. Its flexibility, extensibility, and compatibility with various programming languages make it a popular choice among developers.

To begin coding for the FMT-Firmware project in Visual Studio Code, follow these steps:

1. Open Visual Studio Code.
2. Click on the "File" menu in the top-left corner.
3. Select "Open Folder" from the dropdown menu.
4. A file explorer dialog will appear. Navigate to the location where you have the FMT-Firmware folder stored.
5. Select the FMT-Firmware folder and click "Open."

Now, you have the FMT-Firmware project opened in Visual Studio Code, and you can start coding, modifying, and managing the project using the various features and extensions provided by the IDE. Happy coding!

<img src="../figures/vscode.png" width="50%">


Absolutely, installing useful Visual Studio Code (VS Code) plugins can significantly enhance your development experience when working with the FMT-Firmware project. Two essential plugins for the FMT-Firmware project are:

1. **C/C++**: This plugin provides excellent support for C and C++ languages in VS Code, offering features like code highlighting, IntelliSense, code navigation, and debugging capabilities tailored for these languages.
2. **Clang-Format**: Clang-Format is a code formatting tool for C, C++, and other programming languages. The Clang-Format plugin in VS Code allows you to automatically format your code according to specific style guidelines, ensuring consistent and readable code.

To install these plugins, follow these steps:

1. Open Visual Studio Code.
2. Click on the "Extensions" icon on the left sidebar (or use the shortcut `Ctrl+Shift+X` or `Cmd+Shift+X` on macOS).
3. In the Extensions marketplace search bar, type "C/C++" and "Clang-Format."
4. Click on the "Install" button for each plugin.
5. After installation, you may need to restart Visual Studio Code to activate the plugins.

With these plugins installed, your development environment will be better equipped to handle the intricacies of the FMT-Firmware project, making coding and formatting tasks more efficient and convenient.
76 changes: 0 additions & 76 deletions docs/introduction/quickstart.md

This file was deleted.

Loading

0 comments on commit 18ba1d5

Please sign in to comment.