Skip to content

Commit

Permalink
[stm32h743] first build with external it (nor tested yet..)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaël BRIDAY committed Feb 21, 2024
1 parent b1beded commit 4531eb9
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
readbutton_isr
build
*_exe
*.bin
*.map
*.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
#to compile the project:
# mkdir _build
# cd _build
# cmake -D CMAKE_TOOLCHAIN_FILE=../readbutton_isr/compiler.cmake ..
# make
# make flash
cmake_minimum_required(VERSION 3.5)

# with this option, cmake will not try to compile a
# simple test program (that may fail for an embedded target)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

#project name
project(readbutton_isr_exe)
enable_language(C CXX ASM)


set(TRAMPOLINE_BASE_PATH ${CMAKE_SOURCE_DIR}/../../../../../..)
set(TRAMPOLINE_MACHINE_PATH ${TRAMPOLINE_BASE_PATH}/machines)
set(TRAMPOLINE_GOIL_TEMPLATES ${TRAMPOLINE_BASE_PATH}/goil/templates)
set(APP_GENERATED_PATH ${CMAKE_SOURCE_DIR}/readbutton_isr)

#goil
set(OILFILE ${CMAKE_SOURCE_DIR}/readbutton_isr.oil)
set(OILCOMPILER goil)
set(OILFLAGS -t=cortex-m/armv7em/stm32h743 --templates=${TRAMPOLINE_GOIL_TEMPLATES})

#cross compiler
include("readbutton_isr/compiler.cmake")

set(CFLAGS #CFLAGS
#C flags from target options
--specs=nosys.specs
#C flags from .oil file
-O0
)

set(PRECFLAGS #PRE CFLAGS
#PRE C flags from target options
)

set(CXXFLAGS #C++ FLAGS
#C++ flags from target options
-fno-rtti
-felide-constructors
-fno-threadsafe-statics
-fno-use-cxa-get-exception-ptr
-fno-enforce-eh-specs
)

set(PRECXXFLAGS #PRE C++ FLAGS
#PRE C++ flags from target options
)

set(COMMONFLAGS #COMMON FLAGS (C/C++/ASM)
#common flags from target options
-mcpu=cortex-m7
-mthumb
-mfloat-abi=soft
-mfpu=fpv5-d16
-DSTM32H743xx
-g
-Wno-unused-but-set-variable
-Wmissing-field-initializers
-nostartfiles
-fno-builtin
-fno-exceptions
-nostdlib
-ffunction-sections
-fdata-sections
)

set(PRECOMMONFLAGS #PRE COMMON FLAGS (C/C++/ASM)
#PRE common flags from target options
)

add_compile_options(
${PRECOMMONFLAGS}
${COMMONFLAGS}
"$<$<COMPILE_LANGUAGE:C>:${PRECFLAGS}>"
"$<$<COMPILE_LANGUAGE:C>:${CFLAGS}>"
"$<$<COMPILE_LANGUAGE:CXX>:${PRECXXFLAGS}>"
"$<$<COMPILE_LANGUAGE:CXX>:${CXXFLAGS}>"
"$<$<COMPILE_LANGUAGE:ASM>:${PRECFLAGS}>"
"$<$<COMPILE_LANGUAGE:ASM>:${CFLAGS}>"
)

#Application sources
set(APP_SRCS
#--- C files of the application
readbutton_isr.c
)

#Trampoline kernel sources
set(TRAMPOLINE_OS_SRCS
${TRAMPOLINE_BASE_PATH}/os/tpl_os_kernel.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_timeobj_kernel.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_action.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_error.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_os_kernel.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_os.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_interrupt_kernel.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_task_kernel.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_resource_kernel.c
${TRAMPOLINE_BASE_PATH}/os/tpl_os_alarm_kernel.c
)

#Trampoline generated files
set(APP_GENERATED_SRCS
#os generated files
${APP_GENERATED_PATH}/tpl_app_config.c
${APP_GENERATED_PATH}/tpl_dispatch_table.c
${APP_GENERATED_PATH}/tpl_invoque.S
#platform dependant generated files
${APP_GENERATED_PATH}/tpl_primary_irq.S
${APP_GENERATED_PATH}/tpl_vectors.c
${APP_GENERATED_PATH}/tpl_external_interrupts.c
${APP_GENERATED_PATH}/tpl_app_interrupts.c
)

#Trampoline target dependant files
set(TRAMPOLINE_MACHINE_SRCS
${TRAMPOLINE_MACHINE_PATH}/cortex-m/tpl_machine_cortex.c
${TRAMPOLINE_MACHINE_PATH}/cortex-m/tpl_sc_handler.S
${TRAMPOLINE_MACHINE_PATH}/cortex-m/tpl_startup.S
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/tpl_ctx_switch.S
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/tpl_ctx_switch_under_it.S
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/tpl_interrupts.S
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/lib/pinAccess.c
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/handlers_stm32h743.c
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/startup_stm32h743.c
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/system_stm32h7xx.c
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/tpl_machine_stm32h743.c
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/tpl_trace.c
)

# Trampoline target library sources (drivers)
set(TARGET_LIBRARY_SRCS
)

#Include directories
include_directories(
${TRAMPOLINE_BASE_PATH}/com
${TRAMPOLINE_BASE_PATH}/debug
${TRAMPOLINE_BASE_PATH}/ioc
${TRAMPOLINE_BASE_PATH}/os
${TRAMPOLINE_MACHINE_PATH}/cortex-m
${TRAMPOLINE_MACHINE_PATH}/cortex-m/CMSIS/Include
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/CMSIS/Device/ST/STM32H7xx/Include
${TRAMPOLINE_MACHINE_PATH}/cortex-m/armv7em/stm32h743/lib
readbutton_isr
)

#Executable (should be defined after compile options)
add_executable(${PROJECT_NAME}
${APP_SRCS}
${TRAMPOLINE_OS_SRCS}
${APP_GENERATED_SRCS}
${TARGET_LIBRARY_SRCS}
${TRAMPOLINE_MACHINE_SRCS}
)

#Linker
set(LINKER_DIR ${APP_GENERATED_PATH})
set(LINKER_SCRIPT script.ld)
set(LINKER_FLAGS
#linker flags from target options
--fatal-warnings
--warn-common
--no-undefined
--gc-sections
#linker flags from .oil file
-Map=readbutton_isr.map
#link script
-L${LINKER_DIR}
-T${LINKER_SCRIPT}
)

#
function(add_gcc_library libCmd)
#use gcc to get the full path to libs (libgcc, libc)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${PRECOMMONFLAGS} ${PRECFLAGS} ${COMMONFLAGS} ${CFLAGS} ${libCmd}
RESULT_VARIABLE returnValue
OUTPUT_VARIABLE full_lib_path
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (${returnValue} EQUAL 0)
#ok, now extract only the directory
get_filename_component(libgcc_path ${full_lib_path} DIRECTORY)
set(libpath ${libgcc_path} PARENT_SCOPE)
else()
message("library ${libCmd} not found!")
endif()
endfunction()

if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
add_gcc_library("-print-libgcc-file-name") #try to find libgcc
list(APPEND LINKER_FLAGS -L${libpath} -lgcc)
add_gcc_library("-print-file-name=libc.a") #try to find libc
list(APPEND LINKER_FLAGS -L${libpath} -lc)
endif()

#should be defined after 'add_executable'
target_link_libraries(${PROJECT_NAME}
${LINKER_FLAGS}
)

set_property(TARGET ${PROJECT_NAME}
PROPERTY LINK_DEPENDS ${LINKER_DIR}/${LINKER_SCRIPT}
)

#post build commands (bin file, flash, …)
# POSTBUILD rules
add_custom_command(OUTPUT ${PROJECT_NAME}.bin
DEPENDS ${PROJECT_NAME}
COMMAND ${CMAKE_OBJCOPY} -O binary ${PROJECT_NAME} ${PROJECT_NAME}.bin
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
)

# POSTCOMMAND rules
add_custom_target(burn
DEPENDS ${PROJECT_NAME}.bin
COMMAND st-flash write ${PROJECT_NAME}.bin 0x8000000
)


#TODO: add alias avec dependance.
#add_custom_target(burn
# DEPENDS flash
#)

#goil (will update generated files, and depends on .oil input file)
add_custom_command(OUTPUT ${APP_GENERATED_SRCS}
DEPENDS ${OILFILE}
COMMAND ${OILCOMPILER} ${OILFLAGS} ${OILFILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} #build dir
COMMENT "call Goil (.oil to code source)"
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
|=-----=[ readbutton_isr example ]=-----=|

This application deals with alarms.
There are two tasks : "blink" and ""read_button".

The task "blink" is activated by the alarm "blink_alarm".
The task "blink" toggles the Green LED (PB0) user led whenever it is executed.

The task "read_button" is activated by the alarm "read_button_alarm".
The push button is connected to RST signal, we use D2 instead (PA12), as it can be connected to GND using a jumper. TODO UPDATE for Nucleo 144
This task "read_button" is activated by the interrupt (external interrupt on "push button" (D2)) and toggles the alarm "blink_alarm".

Have a look into "alarm.oil" file.
This application deals with alarms and ISR2.
There are two tasks `blink` and `read_button` and one ISR2 `isr_button`.

The system is based scheduled with a 1ms SysTick `SystemCounter`.

Configure the application with:

```
goil --target=cortex-m/armv7em/stm32H743 --templates=../../../../../../goil/templates/ readbutton_isr.oil
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "tpl_os.h"
#include "pinAccess.h"

#define APP_Task_read_button_START_SEC_CODE
#include "tpl_memmap.h"

#define LED_GREEN_PORT GPIOB
#define LED_GREEN_PIN 0
#define LED_BLUE_PORT GPIOB
#define LED_BLUE_PIN 7
#define LED_RED_PORT GPIOB
#define LED_RED_PIN 14

FUNC(int, OS_APPL_CODE) main(void)
{
pinMode(LED_GREEN_PORT,LED_GREEN_PIN,OUTPUT);
pinMode(LED_BLUE_PORT,LED_BLUE_PIN,OUTPUT);
pinMode(LED_RED_PORT,LED_RED_PIN,OUTPUT);
//We use a jumper between D2 and GND to simulate a push button.

pinMode(GPIOA,12,INPUT_PULLUP); // TODO: update for Nucleo144
StartOS(OSDEFAULTAPPMODE);
return 0;
}

TASK(read_button)
{
static int a = 0;
if (a == 0) {
SetRelAlarm(blink_alarm, 100, 100);
a = 1;
}
else {
CancelAlarm(blink_alarm);
a = 0;
}
TerminateTask();
}
#define APP_Task_read_button_STOP_SEC_CODE
#include "tpl_memmap.h"

#define APP_Task_blink_START_SEC_CODE
#include "tpl_memmap.h"
TASK(blink)
{
digitalToggle(LED_GREEN_PORT,LED_GREEN_PIN);
TerminateTask();
}
#define APP_Task_blink_STOP_SEC_CODE
#include "tpl_memmap.h"

#define APP_ISR_isr_button_START_SEC_CODE
#include "tpl_memmap.h"
ISR(isr_button)
{
ActivateTask(read_button);
}
#define APP_ISR_isr_button_STOP_SEC_CODE
#include "tpl_memmap.h"

#define APP_ISR_isr_button2_START_SEC_CODE
#include "tpl_memmap.h"
ISR(isr_button2)
{
digitalToggle(LED_BLUE_PORT,LED_BLUE_PIN);
}
#define APP_ISR_isr_button2_STOP_SEC_CODE
#include "tpl_memmap.h"

#define APP_ISR_isr_button3_START_SEC_CODE
#include "tpl_memmap.h"
ISR(isr_button3)
{
digitalToggle(LED_RED_PORT,LED_RED_PIN);
}
#define APP_ISR_isr_button3_STOP_SEC_CODE
#include "tpl_memmap.h"
Loading

0 comments on commit 4531eb9

Please sign in to comment.