Skip to content
Draft
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
29 changes: 27 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ if(BOARD_NAME STREQUAL "")
message(FATAL_ERROR "BOARD_NAME cannot be empty")
endif()
set(STLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/ST-LIB)
set(LD_SCRIPT ${STLIB_DIR}/STM32H723ZGTX_FLASH.ld)
set(LD_SCRIPT_INPUT ${STLIB_DIR}/LinkerScript.ld)
set(LD_SCRIPT ${CMAKE_BINARY_DIR}/LinkerScript.ld)

find_package(Python3 COMPONENTS Interpreter REQUIRED)

Expand All @@ -30,6 +31,8 @@ endif()
option(USE_ETHERNET "Enable ethernet peripheral" OFF)
option(TARGET_NUCLEO "Targets the STM32H723 Nucleo development board" OFF)
option(BUILD_EXAMPLES "Build Core/Src/Examples sources" OFF)
option(ITCM_BUILD "Build code in ITCM (fast execution, no wait states)" OFF)
set(ITCM_SIZE "64K" CACHE STRING "ITCM size: 64K, 128K, 192K, or 256K")
option(USE_CCACHE "Use ccache if available" ON)
if(NOT DEFINED ENABLE_LTO)
if(CMAKE_CROSSCOMPILING)
Expand All @@ -49,9 +52,26 @@ if(USE_CCACHE)
endif()
endif()

# Preprocess linker script through C preprocessor
add_custom_command(
OUTPUT ${LD_SCRIPT}
COMMAND ${CMAKE_C_COMPILER} -E -P -x c
-D__ITCM_BUILD=$<IF:$<BOOL:${ITCM_BUILD}>,1,0>
-D__ITCM_SIZE=${ITCM_SIZE}
-o ${LD_SCRIPT} ${LD_SCRIPT_INPUT}
DEPENDS ${LD_SCRIPT_INPUT}
COMMENT "Preprocessing linker script (ITCM_BUILD=${ITCM_BUILD}, ITCM_SIZE=${ITCM_SIZE})"
)

add_custom_target(preprocess_linker_script
DEPENDS ${LD_SCRIPT}
)

message(STATUS "Template project: CMAKE_CROSSCOMPILING = ${CMAKE_CROSSCOMPILING}")
message(STATUS "Template project: USE_ETHERNET = ${USE_ETHERNET}")
message(STATUS "Template project: TARGET_NUCLEO = ${TARGET_NUCLEO}")
message(STATUS "Template project: ITCM_BUILD = ${ITCM_BUILD}")
message(STATUS "Template project: ITCM_SIZE = ${ITCM_SIZE}")
message(STATUS "Template project: BOARD_NAME = ${BOARD_NAME}")

add_subdirectory(${STLIB_DIR})
Expand Down Expand Up @@ -142,9 +162,11 @@ if(CMAKE_CROSSCOMPILING)
${SOURCE_H}
${SOURCE_HPP}

$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${STLIB_DIR}/startup_stm32h723zgtx.s>
$<$<BOOL:${CMAKE_CROSSCOMPILING}>:${STLIB_DIR}/StartupCode.s>
)

add_dependencies(${EXECUTABLE} preprocess_linker_script)

target_link_libraries(${EXECUTABLE} PRIVATE
${STLIB_LIBRARY}
)
Expand All @@ -154,13 +176,16 @@ if(CMAKE_CROSSCOMPILING)
CXX_STANDARD_REQUIRED YES
C_STANDARD 17
C_STANDARD_REQUIRED YES
LINK_DEPENDS ${LD_SCRIPT}
)

target_compile_definitions(${EXECUTABLE} PRIVATE
$<$<BOOL:${EXAMPLE_SELECTED}>:EXAMPLE_SELECTED>
$<$<BOOL:${USE_ETHERNET}>:STLIB_ETH>
$<IF:$<BOOL:${TARGET_NUCLEO}>,NUCLEO,BOARD>
$<IF:$<BOOL:${TARGET_NUCLEO}>,HSE_VALUE=8000000,HSE_VALUE=25000000>
__ITCM_BUILD=$<IF:$<BOOL:${ITCM_BUILD}>,1,0>
__ITCM_SIZE=${ITCM_SIZE}
)

target_compile_options(${EXECUTABLE} PRIVATE
Expand Down
22 changes: 13 additions & 9 deletions Core/Src/Examples/ExampleADC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ constexpr const char* kDualChannelWiringHint = "Connect PA0 and PC0 to two analo
void start_terminal() {
#ifdef HAL_UART_MODULE_ENABLED
if (!UART::set_up_printf(UART::uart3)) {
ErrorHandler("Unable to set up UART printf for ADC example");
FAULT("Unable to set up UART printf for ADC example");
}
UART::start();
#endif
Expand All @@ -51,14 +51,15 @@ constexpr auto adc = ADCDomain::ADC(
ADCDomain::Resolution::BITS_12,
ADCDomain::SampleTime::CYCLES_8_5
);
using ExampleADCBoard = ST_LIB::Board<ST_LIB::DefaultFaultPolicy, adc>;

auto& adc_instance = ExampleADCBoard::instance_of<adc>();

extern "C" void BoardInit() { ExampleADCBoard::init(); }

int main(void) {
using ExampleADCBoard = ST_LIB::Board<adc>;
ExampleADCBoard::init();
start_terminal();

auto& adc_instance = ExampleADCBoard::instance_of<adc>();

print_banner("ADC single-channel example", kSingleChannelWiringHint, "t_ms raw voltage[V]");
printf("Reading input: %s\n\r\n\r", adc_input.label);

Expand Down Expand Up @@ -103,14 +104,17 @@ constexpr auto adc_input_1 = ADCDomain::ADC(
ADCDomain::SampleTime::CYCLES_8_5
);

using ExampleADCBoard = ST_LIB::Board<ST_LIB::DefaultFaultPolicy, adc_input_0, adc_input_1>;

extern "C" void BoardInit() { ExampleADCBoard::init(); }

auto& adc_input_0_instance = ExampleADCBoard::instance_of<adc_input_0>();
auto& adc_input_1_instance = ExampleADCBoard::instance_of<adc_input_1>();

int main(void) {
using ExampleADCBoard = ST_LIB::Board<adc_input_0, adc_input_1>;
ExampleADCBoard::init();
start_terminal();

auto& adc_input_0_instance = ExampleADCBoard::instance_of<adc_input_0>();
auto& adc_input_1_instance = ExampleADCBoard::instance_of<adc_input_1>();

print_banner(
"ADC dual-channel example",
kDualChannelWiringHint,
Expand Down
22 changes: 10 additions & 12 deletions Core/Src/Examples/ExampleEXTI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
// Press the nucleo user button (PC13) to toggle the LED (PB0)

using namespace ST_LIB;
constexpr auto led = ST_LIB::DigitalOutputDomain::DigitalOutput(ST_LIB::PB0);
ST_LIB::DigitalOutputDomain::Instance* g_led;
constexpr auto led_req = ST_LIB::DigitalOutputDomain::DigitalOutput(ST_LIB::PB0);

void toggle_led() { g_led->toggle(); }
void toggle_led();

constexpr auto exti_req =
ST_LIB::EXTIDomain::Device(ST_LIB::PC13, ST_LIB::EXTIDomain::Trigger::BOTH_EDGES, toggle_led);
using MainBoard = ST_LIB::Board<led, exti_req>;
using MainBoard = ST_LIB::Board<ST_LIB::DefaultFaultPolicy, led_req, exti_req>;

int main(void) {
MainBoard::init();
auto led_instance = MainBoard::instance_of<led_req>();

void toggle_led() { led_instance.toggle(); }

static auto& led_instance = MainBoard::instance_of<led>();
g_led = &led_instance;
extern "C" void BoardInit() { MainBoard::init(); }

while (1) {
// led_instance.toggle();
// HAL_Delay(200);
}
int main(void) {
while (1)
;
}
#endif

Expand Down
Loading