diff --git a/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/.gitignore b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/.gitignore new file mode 100644 index 000000000..c05de9b7f --- /dev/null +++ b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/.gitignore @@ -0,0 +1,6 @@ +readbutton_isr +build +*_exe +*.bin +*.map +*.py diff --git a/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/CMakeLists.txt b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/CMakeLists.txt new file mode 100644 index 000000000..43243b9b6 --- /dev/null +++ b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/CMakeLists.txt @@ -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} + "$<$:${PRECFLAGS}>" + "$<$:${CFLAGS}>" + "$<$:${PRECXXFLAGS}>" + "$<$:${CXXFLAGS}>" + "$<$:${PRECFLAGS}>" + "$<$:${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)" +) + diff --git a/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/README.md b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/README.md new file mode 100644 index 000000000..554c7b69b --- /dev/null +++ b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/README.md @@ -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 +``` diff --git a/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/readbutton_isr.c b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/readbutton_isr.c new file mode 100644 index 000000000..98f5d41a8 --- /dev/null +++ b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/readbutton_isr.c @@ -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" diff --git a/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/readbutton_isr.oil b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/readbutton_isr.oil new file mode 100644 index 000000000..13c156bde --- /dev/null +++ b/examples/cortex-m/armv7em/stm32h743/Nucleo-144/readbutton_isr/readbutton_isr.oil @@ -0,0 +1,111 @@ +OIL_VERSION = "2.5"; + +IMPLEMENTATION trampoline { + /* This fix the default STACKSIZE of tasks */ + TASK { + UINT32 STACKSIZE = 300 ; + } ; + + /* This fix the default STACKSIZE of ISRs */ + ISR { + UINT32 STACKSIZE = 200 ; + } ; +}; + +CPU readbutton_isr { + OS config { + STATUS = EXTENDED; + + BUILD = TRUE { + TRAMPOLINE_BASE_PATH = "../../../../../.."; + APP_SRC = "readbutton_isr.c"; + APP_NAME = "readbutton_isr_exe"; + CFLAGS = "-O0"; + LDFLAGS = "-Map=readbutton_isr.map"; + COMPILER = "arm-none-eabi-gcc"; + ASSEMBLER = "arm-none-eabi-as"; + LINKER = "arm-none-eabi-ld"; + COPIER = "arm-none-eabi-objcopy"; + //SYSTEM = PYTHON; + SYSTEM = CMAKE {VSCODE=TRUE;}; + }; + SYSTEM_CALL = TRUE; + MEMMAP = TRUE { + COMPILER = gcc; + LINKER = gnu_ld { SCRIPT = "script.ld"; }; + ASSEMBLER = gnu_as; + MEMORY_PROTECTION = FALSE; + }; + }; + + APPMODE std {}; + + TASK read_button { + PRIORITY = 2; + AUTOSTART = FALSE; + ACTIVATION = 1; + SCHEDULE = FULL; + }; + + TASK blink { + PRIORITY = 1; + AUTOSTART = FALSE; + ACTIVATION = 1; + SCHEDULE = FULL; + }; + + ALARM blink_alarm { + COUNTER = SystemCounter; + ACTION = ACTIVATETASK { + TASK = blink; + }; + AUTOSTART = FALSE; + }; + + /* + * Connect a category 2 ISR to D2 (PA12) + * of the board. + * + * The description allows to program the GPIO, the corresponding + * external interrupt line and the NVIC + * + */ + ISR isr_button { + CATEGORY = 2; + PRIORITY = 2; + //CATEGORY = 1; + //PRIORITY = 10; + SOURCE = EXTI15_10_IRQ { + PINON12 = PA12 { + TRIGGER = FALLING; + PULL = UP; + }; + }; + }; + + ISR isr_button2 { + CATEGORY = 2; + PRIORITY = 4; + //CATEGORY = 1; + //PRIORITY = 10; + SOURCE = EXTI15_10_IRQ { + PINON14 = PC14 { + TRIGGER = BOTH; + PULL = NONE; + }; + }; + }; + + ISR isr_button3 { + CATEGORY = 2; + PRIORITY = 2; + //CATEGORY = 1; + //PRIORITY = 10; + SOURCE = EXTI15_10_IRQ { + PINON10 = PA10 { + TRIGGER = RISING; + PULL = UP; + }; + }; + }; +}; diff --git a/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupt_call_and_ack.goilTemplate b/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupt_call_and_ack.goilTemplate index 899a1e04a..05acd30fa 100644 --- a/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupt_call_and_ack.goilTemplate +++ b/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupt_call_and_ack.goilTemplate @@ -14,21 +14,21 @@ end foreach let num := [pin subString: 2, 2] if exists isISR2 then #called for ISR2 -% if(EXTI->PR1 & EXTI_PR1_PIF%!num%) { +% if(EXTI->PR1 & EXTI_PR1_PR%!num%) { tpl_fast_central_interrupt_handler(%!obj::NAME%_id); - EXTI->PR1 = EXTI_PR1_PIF%!num%; /* ack */ + EXTI->PR1 = EXTI_PR1_PR%!num%; /* ack */ } % elsif exists isISR1 then #called for ISR1 -% if(EXTI->PR1 & EXTI_PR1_PIF%!num%) { +% if(EXTI->PR1 & EXTI_PR1_PR%!num%) { %!obj::NAME %_function(); - EXTI->PR1 = EXTI_PR1_PIF%!num%; /* ack */ + EXTI->PR1 = EXTI_PR1_PR%!num%; /* ack */ } % elsif exists isCounter then #called for Counter -% if(EXTI->PR1 & EXTI_PR1_PIF%!num%) { +% if(EXTI->PR1 & EXTI_PR1_PR%!num%) { tpl_tick_% !objCounter_KEY %(); - EXTI->PR1 = EXTI_PR1_PIF%!num%; /* ack */ + EXTI->PR1 = EXTI_PR1_PR%!num%; /* ack */ } % else #error here: "should not happen: either ISR1 or ISR2" diff --git a/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupts_c.goilTemplate b/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupts_c.goilTemplate index 87c8411e5..216c20e08 100755 --- a/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupts_c.goilTemplate +++ b/goil/templates/code/cortex-m/armv7em/stm32h743/tpl_external_interrupts_c.goilTemplate @@ -174,15 +174,15 @@ end foreach % foreach pin in usedPortPin do if pin::TRIGGER == "RISING" | pin::TRIGGER == "BOTH" then - % EXTI->RTSR1 |= EXTI_RTSR1_RT%!pin::NUMBER%;% + % EXTI->RTSR1 |= EXTI_RTSR1_TR%!pin::NUMBER%;% else - % EXTI->RTSR1 &= ~EXTI_RTSR1_RT%!pin::NUMBER%;% + % EXTI->RTSR1 &= ~EXTI_RTSR1_TR%!pin::NUMBER%;% end if % /* P%!pin::GPIO !pin::NUMBER% : %!pin::TRIGGER% */\n% if pin::TRIGGER == "FALLING" | pin::TRIGGER == "BOTH" then - % EXTI->FTSR1 |= EXTI_FTSR1_FT%!pin::NUMBER%;\n% + % EXTI->FTSR1 |= EXTI_FTSR1_TR%!pin::NUMBER%;\n% else - % EXTI->FTSR1 &= ~EXTI_FTSR1_FT%!pin::NUMBER%;\n% + % EXTI->FTSR1 &= ~EXTI_FTSR1_TR%!pin::NUMBER%;\n% end if between %\n% end foreach