Skip to content

Commit a219b2e

Browse files
authored
Merge branch 'main' into gjiang/finish_arducam_driver
2 parents a20f7be + 3133e4d commit a219b2e

File tree

46 files changed

+221
-1216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+221
-1216
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ elseif(${CMAKE_BUILD_TYPE} MATCHES HIL)
1515
elseif(${CMAKE_BUILD_TYPE} MATCHES Test)
1616
include(${CMAKE_SOURCE_DIR}/cmake/fetch_googletest.cmake)
1717
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_linux_gcc.cmake)
18+
elseif(${CMAKE_BUILD_TYPE} MATCHES Examples)
19+
if(NOT EXISTS ${CMAKE_BINARY_DIR}/toolchain)
20+
include(${CMAKE_SOURCE_DIR}/cmake/download_arm_toolchain.cmake)
21+
endif()
22+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_arm_none_eabi.cmake)
1823
else()
1924
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
2025
endif()
@@ -46,6 +51,12 @@ if(${CMAKE_BUILD_TYPE} MATCHES Test)
4651
add_subdirectory(test)
4752
endif()
4853

54+
if (${CMAKE_BUILD_TYPE} MATCHES Examples)
55+
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
56+
enable_language (C ASM)
57+
add_subdirectory (obc)
58+
endif()
59+
4960
# Build tiny-aes and lib-correct libs
5061
add_subdirectory(libs)
5162

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,40 @@ cmake --build .
192192
ctest --verbose
193193
```
194194

195+
#### **Example files**
196+
From the top-level directory, run the following to build the example source file.
197+
```
198+
mkdir build_examples && cd build_examples
199+
cmake .. -DCMAKE_BUILD_TYPE=Examples -DEXAMPLE_TYPE=[EXAMPLE_TO_BE_COMPILED]
200+
cmake --build .
201+
```
202+
Options for `EXAMPLE_TYPE` include:
203+
204+
- `DMA_SPI` - for `dma_spi_demo`
205+
- `FRAM_PERSIST` - for `test_app_fram_persist`
206+
- `FRAM_SPI` - for `test_app_fram_spi`
207+
- `LM75BD` - for `test_app_lm75bd`
208+
- `MPU6050` - for `test_app_mpu6050`
209+
- `RE_SD` - for `test_app_reliance_sd`
210+
- `RTC`- for `test_app_rtc`
211+
- `UART_RX` - for `test_app_uart_rx`
212+
- `UART_TX` - for `test_app_uart_tx`
213+
- `VN100` - for `vn100_demo`
214+
- `CC1120_SPI` - for `test_app_cc1120_spi`
215+
- `ADC` - for `test_app_adc`
216+
217+
Instructions on how to add examples:
218+
219+
- 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
220+
- Add the code and destination above to the list of examples in the form to the `README.md`: `EXAMPLE_ID` - for `example_name`
221+
- Add the following to the `OBC/CMakeLists.txt` above the comment that says `# ADD MORE EXAMPLES ABOVE THIS COMMENT`
222+
```
223+
elseif(${EXAMPLE_TYPE} MATCHES EXAMPLE_ID)
224+
add_executable(${OUT_FILE_NAME} path_to_main_file_in_example)
225+
```
226+
Where `path_to_main_file_in_example` is relative to the project root, see `OBC/CMakeLists.txt` for examples
227+
- Add the `EXAMPLE_ID` to the `.github/workflows/obc_examples.yml` above the comment that starts with `# ADD NEW EXAMPLES ABOVE THIS LINE`
228+
195229
### Flashing
196230
To flash the RM46 (our microcontroller), we use Uniflash. Open Uniflash and select the appropriate device and connection.
197231
#### **RM46 Launchpad:**

cmake/toolchain_arm_none_eabi.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
3737
add_compile_options(-mcpu=cortex-r4 -march=armv7-r -mtune=cortex-r4 -marm -mfpu=vfpv3-d16)
3838

3939
# Common flags
40-
add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter -fstack-protector-strong -fstack-usage -fdump-ipa-cgraph -MMD)
40+
# NOTE: -Werror is defined in obc/CMakeLists.txt
41+
add_compile_options(-Wall -Wextra -Wno-unused-parameter -fstack-protector-strong -fstack-usage -fdump-ipa-cgraph -MMD)
4142

4243
# Conditional flag for C code
4344
add_compile_options($<$<COMPILE_LANGUAGE:C>:-std=gnu99>)

obc/CMakeLists.txt

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ include(${CMAKE_SOURCE_DIR}/cmake/obc_build_options.cmake)
55

66
include(${CMAKE_CURRENT_SOURCE_DIR}/shared/hal/cmake/board_lib_defs.cmake)
77

8+
# Load setup-specific definitions
9+
include(${CMAKE_SOURCE_DIR}/obc/shared/config/peripheral_config_definitions.cmake)
10+
811
set(LD_DIR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/shared/hal/common/ld")
912
set(APP_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/shared/hal/common/ld/app_link.ld")
1013
set(BL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/shared/hal/common/ld/bl_link.ld")
@@ -28,7 +31,52 @@ endif()
2831
# Pass the address to the linker
2932
add_link_options(-Wl,--defsym,CUSTOM_START_ADDRESS=${CUSTOM_START_ADDRESS})
3033

31-
add_executable(OBC-firmware.out app/app_main.c)
34+
# Select main for build
35+
if(${CMAKE_BUILD_TYPE} MATCHES OBC)
36+
set(OUT_FILE_NAME OBC-firmware.out)
37+
set(BIN_FILE_NAME OBC-firmware.bin)
38+
add_compile_options(-Werror) # TODO: Move this back to download_arm_toolchain once all examples warnings are fixed
39+
add_executable(${OUT_FILE_NAME} app/app_main.c)
40+
elseif(${CMAKE_BUILD_TYPE} MATCHES Examples)
41+
set(OUT_FILE_NAME OBC-firmware-${EXAMPLE_TYPE}.out)
42+
set(BIN_FILE_NAME OBC-firmware-${EXAMPLE_TYPE}.bin)
43+
if (${EXAMPLE_TYPE} MATCHES DMA_SPI)
44+
add_executable(${OUT_FILE_NAME} examples/dma_spi_demo/main.c)
45+
elseif(${EXAMPLE_TYPE} MATCHES FRAM_PERSIST)
46+
add_executable(${OUT_FILE_NAME} examples/test_app_fram_persist/main.c)
47+
elseif(${EXAMPLE_TYPE} MATCHES FRAM_SPI)
48+
add_executable(${OUT_FILE_NAME} examples/test_app_fram_spi/main.c)
49+
elseif(${EXAMPLE_TYPE} MATCHES LM75BD)
50+
add_executable(${OUT_FILE_NAME} examples/test_app_lm75bd/main.c)
51+
elseif(${EXAMPLE_TYPE} MATCHES MPU6050)
52+
add_executable(${OUT_FILE_NAME} examples/test_app_mpu6050/main.c examples/test_app_mpu6050/source/mpu6050.c)
53+
target_include_directories (${OUT_FILE_NAME} PRIVATE examples/test_app_mpu6050/include)
54+
elseif(${EXAMPLE_TYPE} MATCHES RE_SD)
55+
add_executable(${OUT_FILE_NAME} examples/test_app_reliance_edge_sd/main.c)
56+
elseif(${EXAMPLE_TYPE} MATCHES RTC)
57+
add_executable(${OUT_FILE_NAME} examples/test_app_rtc/main.c)
58+
elseif(${EXAMPLE_TYPE} MATCHES UART_RX)
59+
add_executable(${OUT_FILE_NAME} examples/test_app_uart_rx/main.c)
60+
elseif(${EXAMPLE_TYPE} MATCHES UART_TX)
61+
add_executable(${OUT_FILE_NAME} examples/test_app_uart_tx/main.c)
62+
elseif(${EXAMPLE_TYPE} MATCHES VN100)
63+
add_executable(${OUT_FILE_NAME} examples/vn100_demo/test_binary_reading/main.c)
64+
elseif(${EXAMPLE_TYPE} MATCHES ADC)
65+
add_executable(${OUT_FILE_NAME} examples/test_app_adc/main.c)
66+
elseif(${EXAMPLE_TYPE} MATCHES CC1120_SPI)
67+
add_executable(${OUT_FILE_NAME} examples/test_app_cc1120_spi/main.c examples/test_app_cc1120_spi/cc1120_spi_tests.c)
68+
target_include_directories (${OUT_FILE_NAME} PRIVATE examples/test_app_cc1120_spi)
69+
elseif(${EXAMPLE_TYPE} MATCHES RS)
70+
add_executable(${OUT_FILE_NAME} examples/test_app_rs/main.c)
71+
72+
# ADD MORE EXAMPLES ABOVE THIS COMMENT
73+
else ()
74+
message (FATAL_ERROR "Invalid example type: ${EXAMPLE_TYPE} ")
75+
endif()
76+
else()
77+
message (FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
78+
endif()
79+
3280
add_executable(OBC-bl.out)
3381
add_executable(debug-tool.out)
3482

@@ -37,16 +85,16 @@ add_subdirectory(shared/config)
3785
add_subdirectory(shared/hal)
3886

3987
# Application
40-
target_link_options(OBC-firmware.out PRIVATE
88+
target_link_options(${OUT_FILE_NAME} PRIVATE
4189
-specs=nosys.specs
4290
-Wl,-Map=OBC-firmware.map -T${APP_LINKER_SCRIPT}
4391
-Wl,--print-memory-usage
4492
-Wl,-L${LD_DIR_PATH}
4593
)
4694

47-
target_compile_options(OBC-firmware.out PRIVATE ${TARGET_OPTIMIZATION_FLAGS})
95+
target_compile_options(${OUT_FILE_NAME} PRIVATE ${TARGET_OPTIMIZATION_FLAGS})
4896

49-
target_compile_definitions(OBC-firmware.out PRIVATE
97+
target_compile_definitions(${OUT_FILE_NAME} PRIVATE
5098
${BOARD_TYPE}
5199
LOG_DEFAULT_OUTPUT_LOCATION=${LOG_DEFAULT_OUTPUT_LOCATION}
52100
LOG_DEFAULT_LEVEL=${LOG_DEFAULT_LEVEL}
@@ -57,6 +105,7 @@ target_compile_definitions(OBC-firmware.out PRIVATE
57105
OBC_UART_BAUD_RATE=${OBC_UART_BAUD_RATE}
58106
CSDC_DEMO_ENABLED=${CSDC_DEMO_ENABLED}
59107
ENABLE_TASK_STATS_COLLECTOR=${ENABLE_TASK_STATS_COLLECTOR}
108+
${PERIPHERAL_CONFIG}
60109
)
61110

62111
# Determine the root of the repository
@@ -69,7 +118,7 @@ execute_process(
69118
# Set the SOURCE_PATH using the detected REPO_ROOT
70119
add_compile_definitions(SOURCE_PATH="${REPO_ROOT}/")
71120

72-
target_include_directories(OBC-firmware.out PUBLIC
121+
target_include_directories(${OUT_FILE_NAME} PUBLIC
73122
${CMAKE_BINARY_DIR}/toolchain/arm-none-eabi/include
74123
)
75124

@@ -80,7 +129,7 @@ add_subdirectory(app/sys)
80129
add_subdirectory(app/drivers)
81130
add_subdirectory(app/reliance_edge)
82131

83-
target_link_libraries(OBC-firmware.out PRIVATE
132+
target_link_libraries(${OUT_FILE_NAME} PRIVATE
84133
tiny-aes
85134
lib-correct
86135
obc-gs-interface
@@ -92,8 +141,9 @@ target_link_libraries(OBC-firmware.out PRIVATE
92141
)
93142

94143
# Generate .bin for the app
144+
string(CONCAT commentStr "Generating " ${BIN_FILE_NAME})
95145
add_custom_command(
96-
OUTPUT OBC-firmware.bin
146+
OUTPUT ${BIN_FILE_NAME}
97147
COMMAND toolchain/bin/arm-none-eabi-objcopy -O binary --only-section=.intvecs
98148
--only-section=.kernelTEXT
99149
--only-section=.text
@@ -103,16 +153,16 @@ add_custom_command(
103153
--only-section=.init_array
104154
--only-section=.fini_array
105155
--only-section=.data
106-
OBC-firmware.out OBC-firmware.bin
156+
${OUT_FILE_NAME} ${BIN_FILE_NAME}
107157
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
108-
DEPENDS OBC-firmware.out
109-
COMMENT "Generating OBC-firmware.bin"
158+
DEPENDS ${OUT_FILE_NAME}
159+
COMMENT commentStr
110160
)
111161

112162
add_custom_target(
113163
OBC-firmware_bin
114164
ALL
115-
DEPENDS OBC-firmware.bin
165+
DEPENDS ${BIN_FILE_NAME}
116166
)
117167

118168
# Bootloader
@@ -135,6 +185,7 @@ target_compile_definitions(OBC-bl.out PRIVATE
135185
OBC_UART_BAUD_RATE=${OBC_UART_BAUD_RATE}
136186
CSDC_DEMO_ENABLED=${CSDC_DEMO_ENABLED}
137187
ENABLE_TASK_STATS_COLLECTOR=${ENABLE_TASK_STATS_COLLECTOR}
188+
${PERIPHERAL_CONFIG}
138189
)
139190

140191
add_subdirectory(bl)
@@ -165,6 +216,7 @@ target_compile_definitions(debug-tool.out PRIVATE
165216
OBC_UART_BAUD_RATE=${OBC_UART_BAUD_RATE}
166217
CSDC_DEMO_ENABLED=${CSDC_DEMO_ENABLED}
167218
ENABLE_TASK_STATS_COLLECTOR=${ENABLE_TASK_STATS_COLLECTOR}
219+
${PERIPHERAL_CONFIG}
168220
)
169221

170222
add_subdirectory(app/tools/interface_debug_tool)

obc/app/drivers/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ SET(SOURCES
5757
${CMAKE_CURRENT_SOURCE_DIR}/vn100/vn100_binary_parsing.c
5858
)
5959

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

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

obc/app/hal/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ set(SOURCES
88
${CMAKE_CURRENT_SOURCE_DIR}/app_intvecs.s
99
)
1010

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

obc/app/modules/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ set(SOURCES
5252

5353
)
5454

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

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

obc/app/modules/comms_link_mgr/comms_manager.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,10 @@ void obcTaskFunctionCommsMgr(void *pvParameters) {
294294
comms_state_t commsState = *((comms_state_t *)pvParameters);
295295

296296
initAllCc1120TxRxSemaphores();
297-
LOG_IF_ERROR_CODE(cc1120Init());
298297

298+
#ifdef CONFIG_CC1120
299+
LOG_IF_ERROR_CODE(cc1120Init());
300+
#endif // CONFIG_CC1120
299301
while (1) {
300302
comms_event_t queueMsg;
301303

obc/app/modules/comms_link_mgr/tests/cc1120_spi_tests.c

Lines changed: 0 additions & 95 deletions
This file was deleted.

obc/app/modules/comms_link_mgr/tests/cc1120_spi_tests.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)