# ISA Compiling and Deployment User Guide
>[color=#00ffaa]Host os version: Ubuntu 18.04.6 LTS
>Board kernel version: 4.9.227

## OS Requirement
* Ubuntu 18.04 LTS
## Toolchain Install
1. Download Toolchain
http://gofile.me/3FXaO/YhfG25ZJs
2. Download Environment setup file
http://gofile.me/3FXaO/xQXstoMtD (invalid)
> **_NOTE:_** The links will be invalid after 12/3
3. Unpack Toolchain Package
```
$ sudo tar -xvzf gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf.tar.gz -C /opt/sigmastar
```
4. Setup Environment
```
$ sudo cp environment-setup /opt/sigmastar/gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf/gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf
```
## CMake Install (3.22.3)
1. Download Cmake install script
http://gofile.me/3FXaO/rW2yTPU6M
2. Execute the script
```
$ sudo . cmake_install.sh
```
3. Check the CMake version
```
$ cmake --version
```
* Result
```
cmake version 3.22.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
```
## Cross Compile
### 1. Setup
Program folder structure:
```
program
+--src
+--includes
+--build
+--bin
+--CMakeLists.txt
```
Put your source codes into src and include files into includes directory
Create CMakeLists.txt file with the header as follows
```
cmake_minimum_required(VERSION 3.0)
set(CMAKE_FIND_ROOT_PATH " ${your tool chain path} /gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf/gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf")
set(INCLUDE_PATH ${CMAKE_FIND_ROOT_PATH}/arm-linux-gnueabihf/libc/usr/include)
message(STATUS "Root path: ${CMAKE_FIND_ROOT_PATH}")
set(CMAKE_C_COMPILER ${CMAKE_FIND_ROOT_PATH}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${CMAKE_FIND_ROOT_PATH}/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_SYSTEM_PROCESSOR "arm")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -fPIC -DPIC -D__STDC_CONSTANT_MACROS -O2 -funwind-tables -ffunction-sections -fdata-sections -MMD -mfpu=neon")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fPIC -DPIC -D__STDC_CONSTANT_MACROS -O2 -funwind-tables -ffunction-sections -fdata-sections -MMD -mfpu=neon")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
project(myprogram)
include_directories(
${CMAKE_SOURCE_DIR}/include
)
file(GLOB MYPROGRAM_SOURCE
${CMAKE_SOURCE_DIR}/src/*.cpp
)
add_executable(myprogram
${MYPROGRAM_SOURCE}
)
link_directories(
${CMAKE_SOURCE_DIR}
)
```
> **_NOTE:_** It's recommanded setup, if you are familiar with cmake and cross compile, you can feel free to use your own one
### 2. Build
Source the toolchain that previous provided to your enviornment
```
$ source /opt/sigmastar/gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf/gcc-sigmastar-9.1.0-2020.07-x86_64_arm-linux-gnueabihf/environment-setup
```
Use cmake and make to compile your program
```
$ cd build
$ cmake ..
$ make -j8
```
The target program will be placed in bin directory
## Code deployment
1. Use putty to connect to board
Serial line: /dev/ttyUSB0 or /dev/ttyUSB1
Speed : 115200
```
$ sudo putty
```

2. Mount SD card
```
$ mount /dev/mmcblk0p1 /mnt/mmc
```
> **_NOTE:_** The SD card should be automatically mounted, you can find your SD card data in /mnt/mmc directory.
3. Copy myprogram to /customer
```
$ cp /mnt/mmc/${your program name} /customer
$ chmod 777 ${your program name}
```
> **_NOTE:_** Only /customer folder is not read-only
4. Execute
```
$ ./${your program name}
```