Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create working cmake files for examples (version 2) #302

Merged
merged 14 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/obc_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: OBC Examples
Navtajh04 marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:
push:
branches:
- main

jobs:
setup:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup
run: |
sudo apt-get update
sudo apt-get -y install build-essential cmake

build:
runs-on: ubuntu-latest
needs: setup

strategy:
matrix:
example:
[
DMA_SPI,
FRAM_PERSIST,
FRAM_SPI,
LM75BD,
# MPU6050,
RE_SD,
# RTC,
UART_RX,
UART_TX,
VN100,
# CC1120_SPI,
RS,
ADC,

# ADD NEW EXAMPLES ABOVE THIS LINE, MUST BE INLINE WITH OTHER EXAMPLES
]
board: [
RM46_LAUNCHPAD,
OBC_REVISION_1,
OBC_REVISION_2,
]

steps:
- uses: actions/checkout@v3

- name: Create binary directory
run: |
mkdir build

- name: Build (Examples-${{ matrix.board }} ${{ matrix.example }})
run: |
cd build
cmake .. -DCMAKE_BUILD_TYPE=Examples -DEXAMPLE_TYPE=${{matrix.example}} -DBOARD_TYPE=${{matrix.board}} -G"Unix Makefiles" -DDEBUG=1
make
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ elseif(${CMAKE_BUILD_TYPE} MATCHES HIL)
elseif(${CMAKE_BUILD_TYPE} MATCHES Test)
include(${CMAKE_SOURCE_DIR}/cmake/fetch_googletest.cmake)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_linux_gcc.cmake)
elseif(${CMAKE_BUILD_TYPE} MATCHES Examples)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/toolchain)
include(${CMAKE_SOURCE_DIR}/cmake/download_arm_toolchain.cmake)
endif()
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_arm_none_eabi.cmake)
else()
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
Expand Down Expand Up @@ -46,6 +51,12 @@ if(${CMAKE_BUILD_TYPE} MATCHES Test)
add_subdirectory(test)
endif()

if (${CMAKE_BUILD_TYPE} MATCHES Examples)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
enable_language (C ASM)
add_subdirectory (obc)
endif()

# Build tiny-aes and lib-correct libs
add_subdirectory(libs)

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,40 @@ cmake --build .
ctest --verbose
```

#### **Example files**
From the top-level directory, run the following to build the example source file.
```
mkdir build_examples && cd build_examples
cmake .. -DCMAKE_BUILD_TYPE=Examples -DEXAMPLE_TYPE=[EXAMPLE_TO_BE_COMPILED]
cmake --build .
```
Options for `EXAMPLE_TYPE` include:

- `DMA_SPI` - for `dma_spi_demo`
- `FRAM_PERSIST` - for `test_app_fram_persist`
- `FRAM_SPI` - for `test_app_fram_spi`
- `LM75BD` - for `test_app_lm75bd`
- `MPU6050` - for `test_app_mpu6050`
- `RE_SD` - for `test_app_reliance_sd`
- `RTC`- for `test_app_rtc`
- `UART_RX` - for `test_app_uart_rx`
- `UART_TX` - for `test_app_uart_tx`
- `VN100` - for `vn100_demo`
- `CC1120_SPI` - for `test_app_cc1120_spi`
- `ADC` - for `test_app_adc`

Instructions on how to add examples:

- Decide on a code for the example, the code must only contain uppercase letters, numbers and/or `_` referred to as `EXAMPLE_ID` from now on
- Add the code and destination above to the list of examples in the form to the `README.md`: `EXAMPLE_ID` - for `example_name`
- Add the following to the `OBC/CMakeLists.txt` above the comment that says `# ADD MORE EXAMPLES ABOVE THIS COMMENT`
```
elseif(${EXAMPLE_TYPE} MATCHES EXAMPLE_ID)
add_executable(${OUT_FILE_NAME} path_to_main_file_in_example)
```
Where `path_to_main_file_in_example` is relative to the project root, see `OBC/CMakeLists.txt` for examples
- Add the `EXAMPLE_ID` to the `.github/workflows/obc_examples.yml` above the comment that starts with `# ADD NEW EXAMPLES ABOVE THIS LINE`

### Flashing
To flash the RM46 (our microcontroller), we use Uniflash. Open Uniflash and select the appropriate device and connection.
#### **RM46 Launchpad:**
Expand Down
3 changes: 2 additions & 1 deletion cmake/toolchain_arm_none_eabi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
add_compile_options(-mcpu=cortex-r4 -march=armv7-r -mtune=cortex-r4 -marm -mfpu=vfpv3-d16)

# Common flags
add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter -fstack-protector-strong -fstack-usage -fdump-ipa-cgraph -MMD)
# NOTE: -Werror is defined in obc/CMakeLists.txt
add_compile_options(-Wall -Wextra -Wno-unused-parameter -fstack-protector-strong -fstack-usage -fdump-ipa-cgraph -MMD)
Yarik-Popov marked this conversation as resolved.
Show resolved Hide resolved

# Conditional flag for C code
add_compile_options($<$<COMPILE_LANGUAGE:C>:-std=gnu99>)
Expand Down
68 changes: 57 additions & 11 deletions obc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,52 @@ endif()
# Pass the address to the linker
add_link_options(-Wl,--defsym,CUSTOM_START_ADDRESS=${CUSTOM_START_ADDRESS})

add_executable(OBC-firmware.out app/app_main.c)
# Select main for build
if(${CMAKE_BUILD_TYPE} MATCHES OBC)
set(OUT_FILE_NAME OBC-firmware.out)
set(BIN_FILE_NAME OBC-firmware.bin)
add_compile_options(-Werror) # TODO: Move this back to download_arm_toolchain once all examples warnings are fixed
add_executable(${OUT_FILE_NAME} app/app_main.c)
elseif(${CMAKE_BUILD_TYPE} MATCHES Examples)
set(OUT_FILE_NAME OBC-firmware-${EXAMPLE_TYPE}.out)
set(BIN_FILE_NAME OBC-firmware-${EXAMPLE_TYPE}.bin)
if (${EXAMPLE_TYPE} MATCHES DMA_SPI)
add_executable(${OUT_FILE_NAME} examples/dma_spi_demo/main.c)
elseif(${EXAMPLE_TYPE} MATCHES FRAM_PERSIST)
add_executable(${OUT_FILE_NAME} examples/test_app_fram_persist/main.c)
elseif(${EXAMPLE_TYPE} MATCHES FRAM_SPI)
add_executable(${OUT_FILE_NAME} examples/test_app_fram_spi/main.c)
elseif(${EXAMPLE_TYPE} MATCHES LM75BD)
add_executable(${OUT_FILE_NAME} examples/test_app_lm75bd/main.c)
elseif(${EXAMPLE_TYPE} MATCHES MPU6050)
add_executable(${OUT_FILE_NAME} examples/test_app_mpu6050/main.c examples/test_app_mpu6050/source/mpu6050.c)
target_include_directories (${OUT_FILE_NAME} PRIVATE examples/test_app_mpu6050/include)
elseif(${EXAMPLE_TYPE} MATCHES RE_SD)
add_executable(${OUT_FILE_NAME} examples/test_app_reliance_edge_sd/main.c)
elseif(${EXAMPLE_TYPE} MATCHES RTC)
add_executable(${OUT_FILE_NAME} examples/test_app_rtc/main.c)
elseif(${EXAMPLE_TYPE} MATCHES UART_RX)
add_executable(${OUT_FILE_NAME} examples/test_app_uart_rx/main.c)
elseif(${EXAMPLE_TYPE} MATCHES UART_TX)
add_executable(${OUT_FILE_NAME} examples/test_app_uart_tx/main.c)
elseif(${EXAMPLE_TYPE} MATCHES VN100)
add_executable(${OUT_FILE_NAME} examples/vn100_demo/test_binary_reading/main.c)
elseif(${EXAMPLE_TYPE} MATCHES ADC)
add_executable(${OUT_FILE_NAME} examples/test_app_adc/main.c)
elseif(${EXAMPLE_TYPE} MATCHES CC1120_SPI)
add_executable(${OUT_FILE_NAME} examples/test_app_cc1120_spi/main.c examples/test_app_cc1120_spi/cc1120_spi_tests.c)
target_include_directories (${OUT_FILE_NAME} PRIVATE examples/test_app_cc1120_spi)
elseif(${EXAMPLE_TYPE} MATCHES RS)
add_executable(${OUT_FILE_NAME} examples/test_app_rs/main.c)
Yarik-Popov marked this conversation as resolved.
Show resolved Hide resolved

# ADD MORE EXAMPLES ABOVE THIS COMMENT
else ()
message (FATAL_ERROR "Invalid example type: ${EXAMPLE_TYPE} ")
endif()
else()
message (FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()

add_executable(OBC-bl.out)
add_executable(debug-tool.out)

Expand All @@ -40,16 +85,16 @@ add_subdirectory(shared/config)
add_subdirectory(shared/hal)

# Application
target_link_options(OBC-firmware.out PRIVATE
target_link_options(${OUT_FILE_NAME} PRIVATE
-specs=nosys.specs
-Wl,-Map=OBC-firmware.map -T${APP_LINKER_SCRIPT}
-Wl,--print-memory-usage
-Wl,-L${LD_DIR_PATH}
)

target_compile_options(OBC-firmware.out PRIVATE ${TARGET_OPTIMIZATION_FLAGS})
target_compile_options(${OUT_FILE_NAME} PRIVATE ${TARGET_OPTIMIZATION_FLAGS})

target_compile_definitions(OBC-firmware.out PRIVATE
target_compile_definitions(${OUT_FILE_NAME} PRIVATE
${BOARD_TYPE}
LOG_DEFAULT_OUTPUT_LOCATION=${LOG_DEFAULT_OUTPUT_LOCATION}
LOG_DEFAULT_LEVEL=${LOG_DEFAULT_LEVEL}
Expand All @@ -73,7 +118,7 @@ execute_process(
# Set the SOURCE_PATH using the detected REPO_ROOT
add_compile_definitions(SOURCE_PATH="${REPO_ROOT}/")

target_include_directories(OBC-firmware.out PUBLIC
target_include_directories(${OUT_FILE_NAME} PUBLIC
${CMAKE_BINARY_DIR}/toolchain/arm-none-eabi/include
)

Expand All @@ -84,7 +129,7 @@ add_subdirectory(app/sys)
add_subdirectory(app/drivers)
add_subdirectory(app/reliance_edge)

target_link_libraries(OBC-firmware.out PRIVATE
target_link_libraries(${OUT_FILE_NAME} PRIVATE
tiny-aes
lib-correct
obc-gs-interface
Expand All @@ -96,8 +141,9 @@ target_link_libraries(OBC-firmware.out PRIVATE
)

# Generate .bin for the app
string(CONCAT commentStr "Generating " ${BIN_FILE_NAME})
add_custom_command(
OUTPUT OBC-firmware.bin
OUTPUT ${BIN_FILE_NAME}
COMMAND toolchain/bin/arm-none-eabi-objcopy -O binary --only-section=.intvecs
--only-section=.kernelTEXT
--only-section=.text
Expand All @@ -107,16 +153,16 @@ add_custom_command(
--only-section=.init_array
--only-section=.fini_array
--only-section=.data
OBC-firmware.out OBC-firmware.bin
${OUT_FILE_NAME} ${BIN_FILE_NAME}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS OBC-firmware.out
COMMENT "Generating OBC-firmware.bin"
DEPENDS ${OUT_FILE_NAME}
COMMENT commentStr
)

add_custom_target(
OBC-firmware_bin
ALL
DEPENDS OBC-firmware.bin
DEPENDS ${BIN_FILE_NAME}
)

# Bootloader
Expand Down
4 changes: 2 additions & 2 deletions obc/app/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ SET(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/vn100/vn100_binary_parsing.c
)

target_include_directories(OBC-firmware.out PUBLIC ${INCLUDES})
target_sources(OBC-firmware.out PUBLIC ${SOURCES})
target_include_directories(${OUT_FILE_NAME} PUBLIC ${INCLUDES})
target_sources(${OUT_FILE_NAME} PUBLIC ${SOURCES})

target_include_directories(debug-tool.out PUBLIC ${INCLUDES})
target_sources(debug-tool.out PUBLIC ${SOURCES})
4 changes: 2 additions & 2 deletions obc/app/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/app_intvecs.s
)

target_include_directories(OBC-firmware.out PUBLIC ${INCLUDES})
target_sources(OBC-firmware.out PUBLIC ${SOURCES})
target_include_directories(${OUT_FILE_NAME} PUBLIC ${INCLUDES})
target_sources(${OUT_FILE_NAME} PUBLIC ${SOURCES})
4 changes: 2 additions & 2 deletions obc/app/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ set(SOURCES

)

target_include_directories(OBC-firmware.out PUBLIC ${INCLUDES})
target_sources(OBC-firmware.out PUBLIC ${SOURCES})
target_include_directories(${OUT_FILE_NAME} PUBLIC ${INCLUDES})
target_sources(${OUT_FILE_NAME} PUBLIC ${SOURCES})

target_include_directories(debug-tool.out PUBLIC ${INCLUDES})
target_sources(debug-tool.out PUBLIC ${SOURCES})
4 changes: 2 additions & 2 deletions obc/app/modules/camera_mgr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.15)

target_include_directories(OBC-firmware.out PUBLIC
target_include_directories(${OUT_FILE_NAME} PUBLIC
include
)

target_sources(OBC-firmware.out PUBLIC
target_sources(${OUT_FILE_NAME} PUBLIC
source/arducam.c
source/camera_reg.c
source/ov5642_reg.c
Expand Down
29 changes: 0 additions & 29 deletions obc/app/modules/comms_link_mgr/tests/rs_test.c

This file was deleted.

3 changes: 0 additions & 3 deletions obc/app/modules/comms_link_mgr/tests/rs_test.h

This file was deleted.

4 changes: 2 additions & 2 deletions obc/app/modules/eps_mgr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.15)

target_include_directories(OBC-firmware.out PUBLIC
target_include_directories(${OUT_FILE_NAME} PUBLIC
include
)

target_sources(OBC-firmware.out PUBLIC
target_sources(${OUT_FILE_NAME} PUBLIC
source/eps_manager.c
)
4 changes: 2 additions & 2 deletions obc/app/modules/gnc_mgr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.15)

target_include_directories(OBC-firmware.out PUBLIC
target_include_directories(${OUT_FILE_NAME} PUBLIC
include
)

target_sources(OBC-firmware.out PUBLIC
target_sources(${OUT_FILE_NAME} PUBLIC
source/gnc_manager.c
)
4 changes: 2 additions & 2 deletions obc/app/reliance_edge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ set(SOURCES
projects/freertos_rm46/host/redconf.c
)

target_include_directories(OBC-firmware.out PUBLIC ${INCLUDE_DIRS})
target_sources(OBC-firmware.out PUBLIC ${SOURCES})
target_include_directories(${OUT_FILE_NAME} PUBLIC ${INCLUDE_DIRS})
target_sources(${OUT_FILE_NAME} PUBLIC ${SOURCES})

target_include_directories(debug-tool.out PUBLIC ${INCLUDE_DIRS})
target_sources(debug-tool.out PUBLIC ${SOURCES})
4 changes: 2 additions & 2 deletions obc/app/rtos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/obc_scheduler_config.c
)

target_include_directories(OBC-firmware.out PUBLIC ${INCLUDES})
target_sources(OBC-firmware.out PUBLIC ${SOURCES})
target_include_directories(${OUT_FILE_NAME} PUBLIC ${INCLUDES})
target_sources(${OUT_FILE_NAME} PUBLIC ${SOURCES})

target_include_directories(debug-tool.out PUBLIC ${INCLUDES})
target_sources(debug-tool.out PUBLIC ${SOURCES})
4 changes: 2 additions & 2 deletions obc/app/sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ SET(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/utils/obc_heap.c
)

target_include_directories(OBC-firmware.out PUBLIC ${INCLUDES})
target_sources(OBC-firmware.out PUBLIC ${SOURCES})
target_include_directories(${OUT_FILE_NAME} PUBLIC ${INCLUDES})
target_sources(${OUT_FILE_NAME} PUBLIC ${SOURCES})

target_include_directories(debug-tool.out PUBLIC ${INCLUDES})
target_sources(debug-tool.out PUBLIC ${SOURCES})
Loading
Loading