micro-ROS / freertos_apps

Sample applications for FreeRTOS + micro-ROS
Apache License 2.0
81 stars 50 forks source link

Create micro-ros build for STM32F407VETX #65

Closed keshavchintamani closed 3 years ago

keshavchintamani commented 3 years ago

Hi,

I have a STM32F407VETX based board and trying to find the right procedure to get a STM32CubeIDE project with micro-ROS. Not fully clear how to get the firmware and toolchain for this specific board ino the scripts. Any suggestions are really welcome!

keshavchintamani commented 3 years ago

After doing some digging, the first step seems to add a new board to the config folder in micro_ros_setup. Thats pretty straighforward. That will pull this repo and the corresponding extensions. Whats not clear in the documentation is how the freertos extensions have been created. Is it possible to clone an extension and modify for my custom board using the STMCube IDE easily. or should I create a new STM32CubeProject for my specific board and copy over all the ROS2 specific extensions...

pablogs9 commented 3 years ago

Hello, @keshavchintamani we don't have a guide or tutorial to port new boards to FreeRTOS + micro-ROS. But I can tell you which files are added to the STCubeMX.

Using the microros_olimex_e407_extensions the files that are not generated from the micro-ROS.ioc are:

        microros_olimex_e407_extensions/FreeRTOS-Plus-POSIX/*
        microros_olimex_e407_extensions/include/*
        microros_olimex_e407_extensions/Inc/allocators.h
        microros_olimex_e407_extensions/Inc/app.h
        microros_olimex_e407_extensions/Inc/microros_transports.h
        microros_olimex_e407_extensions/Src/allocators.c
        microros_olimex_e407_extensions/Src/custom_memory_manager.c
        microros_olimex_e407_extensions/Src/microros_transports.c
        microros_olimex_e407_extensions/arm_toolchain.cmake.in

The important generated files that have been modified are:

diff --git a/microros_olimex_e407_extensions/Inc/FreeRTOSConfig.h b/microros_olimex_e407_extensions/Inc/FreeRTOSConfig.h
index 7c74a83..af7d7e8 100644
--- a/microros_olimex_e407_extensions/Inc/FreeRTOSConfig.h
+++ b/microros_olimex_e407_extensions/Inc/FreeRTOSConfig.h
@@ -44,6 +44,10 @@

 /* USER CODE BEGIN Includes */
 /* Section where include file can be added */
+#define configUSE_POSIX_ERRNO                   1
+#define configUSE_STATS_FORMATTING_FUNCTIONS    1
+#define configUSE_APPLICATION_TASK_TAG          1
+#define INCLUDE_xTaskGetHandle                  1
 /* USER CODE END Includes */

 /* Ensure definitions are only used by the compiler, and not by the assembler. */

``` diff --git a/microros_olimex_e407_extensions/Makefile b/microros_olimex_e407_extensions/Makefile index ba830ff..3577571 100644 --- a/microros_olimex_e407_extensions/Makefile +++ b/microros_olimex_e407_extensions/Makefile @@ -20,151 +20,176 @@ TARGET = micro-ROS # building variables ###################################### # debug build? -DEBUG = 1 +DEBUG ?= 1 # optimization -OPT = -Og + +ifeq ($(DEBUG), 1) + OPT = -O0 + BUILD_TYPE = Debug +else + OPT = -Og + BUILD_TYPE = Release +endif ####################################### # paths ####################################### # Build path -BUILD_DIR = build +EXTENSIONS_DIR = $(shell pwd) +TOPFOLDER = $(EXTENSIONS_DIR)/../.. +UROS_DIR = $(TOPFOLDER)/mcu_ws +BUILD_DIR = $(EXTENSIONS_DIR)/build ###################################### # source ###################################### # C sources -C_SOURCES = \ -Src/main.c \ -Src/freertos.c \ -Src/lwip.c \ -Src/ethernetif.c \ -Src/stm32f4xx_it.c \ -Src/stm32f4xx_hal_msp.c \ -Src/stm32f4xx_hal_timebase_tim.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \ -Src/system_stm32f4xx.c \ -Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ -Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ -Middlewares/Third_Party/FreeRTOS/Source/list.c \ -Middlewares/Third_Party/FreeRTOS/Source/queue.c \ -Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \ -Middlewares/Third_Party/FreeRTOS/Source/tasks.c \ -Middlewares/Third_Party/FreeRTOS/Source/timers.c \ -Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ -Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ -Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/auth.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/ccp.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/chap_ms.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/chap-md5.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/chap-new.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/demand.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/eap.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/eui64.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/fsm.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/ipcp.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/ipv6cp.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/lcp.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/magic.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/mppe.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/multilink.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/ppp.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/pppapi.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/pppcrypt.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/pppoe.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/pppol2tp.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/pppos.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/upap.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/utils.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/vj.c \ -Middlewares/Third_Party/LwIP/src/netif/ethernet.c \ -Middlewares/Third_Party/LwIP/src/netif/slipif.c \ -Middlewares/Third_Party/LwIP/src/netif/lowpan6.c \ -Middlewares/Third_Party/LwIP/src/netif/ppp/ecp.c \ -Middlewares/Third_Party/LwIP/src/api/sockets.c \ -Middlewares/Third_Party/LwIP/src/api/api_lib.c \ -Middlewares/Third_Party/LwIP/src/api/netifapi.c \ -Middlewares/Third_Party/LwIP/src/api/tcpip.c \ -Middlewares/Third_Party/LwIP/src/api/err.c \ -Middlewares/Third_Party/LwIP/src/api/api_msg.c \ -Middlewares/Third_Party/LwIP/src/api/netdb.c \ -Middlewares/Third_Party/LwIP/src/api/netbuf.c \ -Middlewares/Third_Party/LwIP/src/core/pbuf.c \ -Middlewares/Third_Party/LwIP/src/core/timeouts.c \ -Middlewares/Third_Party/LwIP/src/core/netif.c \ -Middlewares/Third_Party/LwIP/src/core/memp.c \ -Middlewares/Third_Party/LwIP/src/core/inet_chksum.c \ -Middlewares/Third_Party/LwIP/src/core/dns.c \ -Middlewares/Third_Party/LwIP/src/core/ip.c \ -Middlewares/Third_Party/LwIP/src/core/tcp.c \ -Middlewares/Third_Party/LwIP/src/core/def.c \ -Middlewares/Third_Party/LwIP/src/core/raw.c \ -Middlewares/Third_Party/LwIP/src/core/init.c \ -Middlewares/Third_Party/LwIP/src/core/mem.c \ -Middlewares/Third_Party/LwIP/src/core/stats.c \ -Middlewares/Third_Party/LwIP/src/core/tcp_in.c \ -Middlewares/Third_Party/LwIP/src/core/sys.c \ -Middlewares/Third_Party/LwIP/src/core/tcp_out.c \ -Middlewares/Third_Party/LwIP/src/core/udp.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/dhcp.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_addr.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/autoip.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/igmp.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/icmp.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/etharp.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_frag.c \ -Middlewares/Third_Party/LwIP/src/core/ipv4/ip4.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/ip6_frag.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/dhcp6.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/ip6.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/ip6_addr.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/icmp6.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/nd6.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/mld6.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/ethip6.c \ -Middlewares/Third_Party/LwIP/src/core/ipv6/inet6.c \ -Middlewares/Third_Party/LwIP/system/OS/sys_arch.c \ -Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c +C_SOURCES = \ +Src/main.c \ +Src/freertos.c \ +Src/stm32f4xx_it.c \ +Src/stm32f4xx_hal_msp.c \ +Src/stm32f4xx_hal_timebase_tim.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ +Src/system_stm32f4xx.c \ +Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ +Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ +Middlewares/Third_Party/FreeRTOS/Source/list.c \ +Middlewares/Third_Party/FreeRTOS/Source/queue.c \ +Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \ +Middlewares/Third_Party/FreeRTOS/Source/tasks.c \ +Middlewares/Third_Party/FreeRTOS/Source/timers.c \ +Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ +Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ +Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ +Src/lwip.c \ +Src/ethernetif.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/auth.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/ccp.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/chap_ms.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/chap-md5.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/chap-new.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/demand.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/eap.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/eui64.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/fsm.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/ipcp.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/ipv6cp.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/lcp.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/magic.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/mppe.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/multilink.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/ppp.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/pppapi.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/pppcrypt.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/pppoe.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/pppol2tp.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/pppos.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/upap.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/utils.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/vj.c \ +Middlewares/Third_Party/LwIP/src/netif/ethernet.c \ +Middlewares/Third_Party/LwIP/src/netif/slipif.c \ +Middlewares/Third_Party/LwIP/src/netif/lowpan6.c \ +Middlewares/Third_Party/LwIP/src/netif/ppp/ecp.c \ +Middlewares/Third_Party/LwIP/src/api/sockets.c \ +Middlewares/Third_Party/LwIP/src/api/api_lib.c \ +Middlewares/Third_Party/LwIP/src/api/netifapi.c \ +Middlewares/Third_Party/LwIP/src/api/tcpip.c \ +Middlewares/Third_Party/LwIP/src/api/err.c \ +Middlewares/Third_Party/LwIP/src/api/api_msg.c \ +Middlewares/Third_Party/LwIP/src/api/netdb.c \ +Middlewares/Third_Party/LwIP/src/api/netbuf.c \ +Middlewares/Third_Party/LwIP/src/core/pbuf.c \ +Middlewares/Third_Party/LwIP/src/core/timeouts.c \ +Middlewares/Third_Party/LwIP/src/core/netif.c \ +Middlewares/Third_Party/LwIP/src/core/memp.c \ +Middlewares/Third_Party/LwIP/src/core/inet_chksum.c \ +Middlewares/Third_Party/LwIP/src/core/dns.c \ +Middlewares/Third_Party/LwIP/src/core/ip.c \ +Middlewares/Third_Party/LwIP/src/core/tcp.c \ +Middlewares/Third_Party/LwIP/src/core/def.c \ +Middlewares/Third_Party/LwIP/src/core/raw.c \ +Middlewares/Third_Party/LwIP/src/core/init.c \ +Middlewares/Third_Party/LwIP/src/core/mem.c \ +Middlewares/Third_Party/LwIP/src/core/stats.c \ +Middlewares/Third_Party/LwIP/src/core/tcp_in.c \ +Middlewares/Third_Party/LwIP/src/core/sys.c \ +Middlewares/Third_Party/LwIP/src/core/tcp_out.c \ +Middlewares/Third_Party/LwIP/src/core/udp.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/dhcp.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_addr.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/autoip.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/igmp.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/icmp.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/etharp.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_frag.c \ +Middlewares/Third_Party/LwIP/src/core/ipv4/ip4.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/ip6_frag.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/dhcp6.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/ip6.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/ip6_addr.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/icmp6.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/nd6.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/mld6.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/ethip6.c \ +Middlewares/Third_Party/LwIP/src/core/ipv6/inet6.c \ +Middlewares/Third_Party/LwIP/system/OS/sys_arch.c \ +Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c \ +FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_utils.c \ +FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_clock.c \ +FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_sched.c \ +FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_unistd.c \ +FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_pthread.c \ +Src/custom_memory_manager.c \ +Src/allocators.c \ +Src/microros_transports.c \ +$(wildcard $(UROS_APP_FOLDER)/*.c) + +# Removing heap4 manager while being polite with STM32CubeMX +TMPVAR := $(C_SOURCES) +C_SOURCES := $(filter-out Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c, $(TMPVAR)) # ASM sources -ASM_SOURCES = \ +ASM_SOURCES = \ startup_stm32f407xx.s ####################################### # binaries ####################################### -PREFIX = arm-none-eabi- # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) # either it can be added to the PATH environment variable. +CROSS_COMPILE_NAME_PREFIX=arm-none-eabi- +CROSS_COMPILE = $(TOPFOLDER)/toolchain/bin/$(CROSS_COMPILE_NAME_PREFIX) + ifdef GCC_PATH -CC = $(GCC_PATH)/$(PREFIX)gcc -AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp -CP = $(GCC_PATH)/$(PREFIX)objcopy -SZ = $(GCC_PATH)/$(PREFIX)size +CC = $(GCC_PATH)/$(CROSS_COMPILE_NAME_PREFIX)gcc +AS = $(GCC_PATH)/$(CROSS_COMPILE_NAME_PREFIX)gcc -x assembler-with-cpp +CP = $(GCC_PATH)/$(CROSS_COMPILE_NAME_PREFIX)objcopy +SZ = $(GCC_PATH)/$(CROSS_COMPILE_NAME_PREFIX)size else -CC = $(PREFIX)gcc -AS = $(PREFIX)gcc -x assembler-with-cpp -CP = $(PREFIX)objcopy -SZ = $(PREFIX)size +CC = $(CROSS_COMPILE)gcc +AS = $(CROSS_COMPILE)gcc -x assembler-with-cpp +CP = $(CROSS_COMPILE)objcopy +SZ = $(CROSS_COMPILE)size endif HEX = $(CP) -O ihex BIN = $(CP) -O binary -S @@ -189,38 +214,67 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) AS_DEFS = # C defines -C_DEFS = \ --DUSE_HAL_DRIVER \ --DSTM32F407xx - +C_DEFS = \ +-DUSE_HAL_DRIVER \ +-DSTM32F407xx \ +-D_TIMEVAL_DEFINED # AS includes -AS_INCLUDES = \ +AS_INCLUDES = \ -IInc # C includes -C_INCLUDES = \ --IInc \ --IMiddlewares/Third_Party/LwIP/src/include \ --IMiddlewares/Third_Party/LwIP/system \ --IDrivers/STM32F4xx_HAL_Driver/Inc \ --IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ --IMiddlewares/Third_Party/FreeRTOS/Source/include \ --IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ --IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \ --IMiddlewares/Third_Party/LwIP/src/include/netif/ppp \ --IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ --IMiddlewares/Third_Party/LwIP/src/include/lwip \ --IMiddlewares/Third_Party/LwIP/src/include/lwip/apps \ --IMiddlewares/Third_Party/LwIP/src/include/lwip/priv \ --IMiddlewares/Third_Party/LwIP/src/include/lwip/prot \ --IMiddlewares/Third_Party/LwIP/src/include/netif \ --IMiddlewares/Third_Party/LwIP/src/include/posix \ --IMiddlewares/Third_Party/LwIP/src/include/posix/sys \ --IMiddlewares/Third_Party/LwIP/system/arch \ --IDrivers/CMSIS/Include \ --IDrivers/CMSIS/Include - +C_INCLUDES = \ +-IInc \ +-IDrivers/STM32F4xx_HAL_Driver/Inc \ +-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ +-IMiddlewares/Third_Party/FreeRTOS/Source/include \ +-IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ +-IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \ +-IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ +-IDrivers/CMSIS/Include \ +-IDrivers/CMSIS/Include \ +-IMiddlewares/Third_Party/LwIP/src/include \ +-IMiddlewares/Third_Party/LwIP/system \ +-IMiddlewares/Third_Party/LwIP/src/include/netif/ppp \ +-IMiddlewares/Third_Party/LwIP/src/include/lwip \ +-IMiddlewares/Third_Party/LwIP/src/include/lwip/apps \ +-IMiddlewares/Third_Party/LwIP/src/include/lwip/priv \ +-IMiddlewares/Third_Party/LwIP/src/include/lwip/prot \ +-IMiddlewares/Third_Party/LwIP/src/include/netif \ +-IMiddlewares/Third_Party/LwIP/src/include/posix \ +-IMiddlewares/Third_Party/LwIP/src/include/posix/sys \ +-IMiddlewares/Third_Party/LwIP/system/arch \ +-IFreeRTOS-Plus-POSIX/include \ +-IFreeRTOS-Plus-POSIX/include/portable/empty_portable \ +-IFreeRTOS-Plus-POSIX/include/portable \ +-Iinclude \ +-Iinclude/private \ +-I$(UROS_APP_FOLDER) + +MICROROS_INCLUDES += $(shell find $(UROS_DIR)/install -name 'include' | sed -E "s/(.*)/-I\1/") +MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/include +MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/include/FreeRTOS_POSIX +C_INCLUDES += $(MICROROS_INCLUDES) + +COLCON_INCLUDES += $(EXTENSIONS_DIR)/FreeRTOS-Plus-POSIX/include +COLCON_INCLUDES += $(EXTENSIONS_DIR)/include +COLCON_INCLUDES += $(EXTENSIONS_DIR)/include/private +COLCON_INCLUDES += $(EXTENSIONS_DIR)/include/FreeRTOS_POSIX +COLCON_INCLUDES += $(EXTENSIONS_DIR)/include/FreeRTOS_POSIX/sys +COLCON_INCLUDES += $(EXTENSIONS_DIR)/src/hal/interface +COLCON_INCLUDES += $(EXTENSIONS_DIR)/src/modules/interface +COLCON_INCLUDES += $(EXTENSIONS_DIR)/src/utils/interface +COLCON_INCLUDES += $(EXTENSIONS_DIR)/src/config +COLCON_INCLUDES += $(EXTENSIONS_DIR)/src/drivers/interface +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Middlewares/Third_Party/LwIP/src/include/posix +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Middlewares/Third_Party/LwIP/src/include +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Inc +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Drivers/STM32F4xx_HAL_Driver/Inc +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Drivers/CMSIS/Device/ST/STM32F4xx/Include +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Drivers/CMSIS/Include +COLCON_INCLUDES += $(EXTENSIONS_DIR)/Middlewares/Third_Party/LwIP/system +COLCON_INCLUDES_STR := $(foreach x,$(COLCON_INCLUDES),$(x)\n) # compile gcc flags ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections @@ -231,10 +285,10 @@ ifeq ($(DEBUG), 1) CFLAGS += -g -gdwarf-2 endif - # Generate dependency information CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" +ARCHCPUFLAGS = $(MCU) $(C_DEFS) $(OPT) -Wall -fdata-sections -ffunction-sections ####################################### # LDFLAGS @@ -245,17 +299,60 @@ LDSCRIPT = STM32F407ZGTx_FLASH.ld # libraries LIBS = -lc -lm -lnosys LIBDIR = -LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections +LDFLAGS = $(MCU) --specs=nosys.specs -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections # default action: build all all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin +####################################### +# build micro-ROS +####################################### + +arm_toolchain: $(EXTENSIONS_DIR)/arm_toolchain.cmake.in + rm -f $(EXTENSIONS_DIR)/arm_toolchain.cmake; \ + cat $(EXTENSIONS_DIR)/arm_toolchain.cmake.in | \ + sed "s/@CROSS_COMPILE@/$(subst /,\/,$(CROSS_COMPILE))/g" | \ + sed "s/@FREERTOS_TOPDIR@/$(subst /,\/,$(TOPFOLDER))/g" | \ + sed "s/@ARCH_CPU_FLAGS@/\"$(ARCHCPUFLAGS)\"/g" | \ + sed "s/@ARCH_OPT_FLAGS@/\"$(ARCHOPTIMIZATION)\"/g" | \ + sed "s/@INCLUDES@/$(subst /,\/,$(COLCON_INCLUDES_STR))/g" \ + > $(EXTENSIONS_DIR)/arm_toolchain.cmake + +colcon_compile: arm_toolchain + cd $(UROS_DIR); \ + colcon build \ + --packages-ignore-regex=.*_cpp \ + --metas $(UROS_DIR)/colcon.meta $(UROS_APP_FOLDER)/app-colcon.meta \ + --cmake-args \ + "--no-warn-unused-cli" \ + -DCMAKE_POSITION_INDEPENDENT_CODE=OFF \ + -DTHIRDPARTY=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_TOOLCHAIN_FILE=$(EXTENSIONS_DIR)/arm_toolchain.cmake \ + -DCMAKE_VERBOSE_MAKEFILE=ON; \ + +libmicroros: colcon_compile + mkdir -p $(UROS_DIR)/libmicroros; cd $(UROS_DIR)/libmicroros; \ + for file in $$(find $(UROS_DIR)/install/ -name '*.a'); do \ + folder=$$(echo $$file | sed -E "s/(.+)\/(.+).a/\2/"); \ + mkdir -p $$folder; cd $$folder; ar x $$file; \ + for f in *; do \ + mv $$f ../$$folder-$$f; \ + done; \ + cd ..; rm -rf $$folder; \ + done ; \ + ar rc libmicroros.a *.obj; mkdir -p $(BUILD_DIR); cp libmicroros.a $(BUILD_DIR); ranlib $(BUILD_DIR)/libmicroros.a; \ + cd ..; rm -rf libmicroros; ####################################### # build the application ####################################### # list of objects OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +OBJECTS += $(BUILD_DIR)/libmicroros.a + vpath %.c $(sort $(dir $(C_SOURCES))) # list of ASM program objects OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) @@ -284,11 +381,11 @@ $(BUILD_DIR): # clean up ####################################### clean: - -rm -fR $(BUILD_DIR) + -rm -fR $(BUILD_DIR); ####################################### # dependencies ####################################### -include $(wildcard $(BUILD_DIR)/*.d) -# *** EOF *** \ No newline at end of file +# *** EOF *** ```
``` diff --git a/microros_olimex_e407_extensions/Src/main.c b/microros_olimex_e407_extensions/Src/main.c index b593afa..9648103 100644 --- a/microros_olimex_e407_extensions/Src/main.c +++ b/microros_olimex_e407_extensions/Src/main.c @@ -6,7 +6,7 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2021 STMicroelectronics. + *

© Copyright (c) 2020 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under Ultimate Liberty license @@ -25,6 +25,24 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "stm32f4xx_hal.h" +#include "api.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "FreeRTOS.h" +#include "task.h" + +#include /* USER CODE END Includes */ @@ -70,12 +88,34 @@ static void MX_USART6_UART_Init(void); void initTaskFunction(void *argument); /* USER CODE BEGIN PFP */ +#define BUFSIZE 4096 +char buffer[BUFSIZE]; +extern struct netif gnetif; +UART_HandleTypeDef * printf_uart = NULL; +// extern appMain; /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +int __io_putchar(int ch) +{ + uint8_t c[1]; + c[0] = ch & 0x00FF; + if (printf_uart != NULL){ + HAL_UART_Transmit(printf_uart, &c[0], 1, 10); + } + return ch; +} +int _write(int file,char *ptr, int len) +{ + int DataIdx; + for(DataIdx= 0; DataIdx< len; DataIdx++){ + __io_putchar(*ptr++); + } + return len; +} /* USER CODE END 0 */ /** @@ -113,6 +153,12 @@ int main(void) MX_USART6_UART_Init(); /* USER CODE BEGIN 2 */ +#ifdef RMW_UXRCE_TRANSPORT_UDP + printf_uart = &huart3; +#elif defined(RMW_UXRCE_TRANSPORT_CUSTOM) + printf_uart = &huart6; +#endif + /* USER CODE END 2 */ /* Init scheduler */ osKernelInitialize(); @@ -357,24 +403,98 @@ static void MX_GPIO_Init(void) } /* USER CODE BEGIN 4 */ - /* USER CODE END 4 */ /* USER CODE BEGIN Header_initTaskFunction */ /** * @brief Function implementing the initTask thread. - * @param argument: Not used + * @param argument: Not used * @retval None */ /* USER CODE END Header_initTaskFunction */ void initTaskFunction(void *argument) { /* USER CODE BEGIN 5 */ - /* Infinite loop */ - for(;;) - { - osDelay(1); + HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, GPIO_PIN_SET); + bool availableNetwork = false; + +#ifdef RMW_UXRCE_TRANSPORT_CUSTOM + availableNetwork = true; + rmw_uros_set_custom_transport( + true, + (void *) &huart3, + freertos_serial_open, + freertos_serial_close, + freertos_serial_write, + freertos_serial_read); +#elif defined(RMW_UXRCE_TRANSPORT_UDP) + printf("Ethernet Initialization\r\n"); + + //Waiting for an IP + printf("Waiting for IP\r\n"); + int retries = 0; + while(gnetif.ip_addr.addr == 0 && retries < 10){ + osDelay(500); + retries++; + }; + + availableNetwork = (gnetif.ip_addr.addr != 0); + if (availableNetwork){ + printf("IP: %s\r\n",ip4addr_ntoa(&gnetif.ip_addr)); + }else{ + printf("Impossible to retrieve an IP\n"); + } +#endif + + // Launch app thread when IP configured + rcl_allocator_t freeRTOS_allocator = rcutils_get_zero_initialized_allocator(); + freeRTOS_allocator.allocate = __freertos_allocate; + freeRTOS_allocator.deallocate = __freertos_deallocate; + freeRTOS_allocator.reallocate = __freertos_reallocate; + freeRTOS_allocator.zero_allocate = __freertos_zero_allocate; + + if (!rcutils_set_default_allocator(&freeRTOS_allocator)) { + printf("Error on default allocators (line %d)\n",__LINE__); } + + osThreadAttr_t attributes; + memset(&attributes, 0x0, sizeof(osThreadAttr_t)); + attributes.name = "microROS_app"; + attributes.stack_size = 4*3000; + attributes.priority = (osPriority_t) osPriorityNormal1; + osThreadNew(appMain, NULL, &attributes); + + osDelay(500); + char ptrTaskList[500]; + vTaskList(ptrTaskList); + printf("**********************************\n"); + printf("Task State Prio Stack Num\n"); + printf("**********************************\n"); + printf(ptrTaskList); + printf("**********************************\n"); + + TaskHandle_t xHandle; + xHandle = xTaskGetHandle("microROS_app"); + + while (1){ + if (eTaskGetState(xHandle) != eSuspended && availableNetwork){ + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); + osDelay(100); + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); + osDelay(100); + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); + osDelay(150); + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); + osDelay(500); + }else{ + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); + osDelay(1000); + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET); + osDelay(1000); + } + } + + /* USER CODE END 5 */ } ```

pablogs9 commented 3 years ago

Hope that this help to figure out how to modify the STCubeMX project to add micro-ROS

pablogs9 commented 3 years ago

Please take a look here: https://github.com/micro-ROS/micro_ros_stm32cubemx_utils