micro-ROS / micro_ros_setup

Support macros for building micro-ROS-based firmware.
Apache License 2.0
364 stars 132 forks source link

how could I build a project by my own #265

Closed Needrom closed 3 years ago

Needrom commented 3 years ago

I learn some thing from a close issue which is https://github.com/micro-ROS/micro_ros_setup/issues/202

but i didn't see any thing about how to add a base project with gpio lwip freertos by ourselves. I want to build it from a makefile project from stm32cubuMX, but don't know how. I try compare the project with a base project from stm32CubeMX and a project in /firmware/......./microros_olimex_e407_extensions/ ,with no idea to transfer my base project to a project can built by a script which is "ros2 run micro_ros_setup build_firmware.sh"

Needrom commented 3 years ago

Could not build it just use some thing like "ros2 run micro_ros_setup create_firmware_ws.sh freertos my-own-board-name" I think it just fetch the repo from github if the script can find that link

image

pablogs9 commented 3 years ago

You need to create micro-ROS support for your board as it is not supported. Some micro-ROS for freeRTOS board support are based in STMCubeMX, check this for an example on how to create new board support.

Although there is a lot of files, most of them are autogenerated, so at the end, you can analyze the main.c and the Makefile to see what is being done there.

Needrom commented 3 years ago

You need to create micro-ROS support for your board as it is not supported. Some micro-ROS for freeRTOS board support are based in STMCubeMX, check this for an example on how to create new board support.

Although there is a lot of files, most of them are autogenerated, so at the end, you can analyze the main.c and the Makefile to see what is being done there.

Thanks for reply. I follow your step ,but I got this. image

pablogs9 commented 3 years ago

I guess that these errors are not related to micro-ROS but related to your FreeRTOS port

Needrom commented 3 years ago

I guess that these errors are not related to micro-ROS but related to your FreeRTOS port

thanks for all. I had already built it, and test for my own gpio setting.

yeah, it did relate to my Freertos setting. I let it to be original on the Freertos setting within my stm32F407CubeMX. this may cause by


# 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))

I comment this two line so I can build it. But any thing I should Know if I put this two line disable. Have no idea what will happen with my Freertos task.

pablogs9 commented 3 years ago

Could you share some details about your project? Are you using a development hardware board that you can contribute to micro-ROS?

Can we close the issue?

Thanks!

Needrom commented 3 years ago

sure.I just use some base gpio function for now, and uart testing no yet. I'm going to add RS485 in it. I'm using a development hardware board, will share it after I test a more bit later.

Needrom commented 3 years ago

some thing is Not going so well. as like I found so much microros thing I haven't write it the freertos.c. After I add the code relate to rcl , wrong come out.

image

pablogs9 commented 3 years ago

Could you please provide steps for replicating this?

Needrom commented 3 years ago

Makefile of Mine

I Makefile little by little copy from the microros_nucleo_f446re_extensions

And finaly , firmware can build without changing the freertos.c in $(my_project)/Core/Src/

With Makfile as follow.

##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.11.0-B13] date: [Mon Jan 25 13:25:54 CST 2021] 
##########################################################################################################################

# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
#   2017-02-10 - Several enhancements + project update mode
#   2015-07-22 - first version
# ------------------------------------------------

######################################
# target
######################################
TARGET = micro-ROS

######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
ifeq ($(DEBUG), 1)
        OPT = -O0
        BUILD_TYPE = Debug
else
        OPT = -Og
        BUILD_TYPE = Release
endif

#######################################
# paths
#######################################
# Build path
EXTENSIONS_DIR = $(shell pwd)
TOPFOLDER = $(EXTENSIONS_DIR)/../..
UROS_DIR = $(TOPFOLDER)/mcu_ws
BUILD_DIR = $(EXTENSIONS_DIR)/build

######################################
# source
######################################
# C sources
C_SOURCES =  \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/freertos.c \
Core/Src/usart.c \
Core/Src/allocators.c \
Core/Src/custom_memory_manager.c \
Core/Src/stm32f4xx_it.c \
Core/Src/stm32f4xx_hal_msp.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 \
Core/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 \
LWIP/Target/ethernetif.c \
LWIP/App/lwip.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/bridgeif.c \
Middlewares/Third_Party/LwIP/src/netif/bridgeif_fdb.c \
Middlewares/Third_Party/LwIP/src/netif/ethernet.c \
Middlewares/Third_Party/LwIP/src/netif/lowpan6.c \
Middlewares/Third_Party/LwIP/src/netif/lowpan6_ble.c \
Middlewares/Third_Party/LwIP/src/netif/lowpan6_common.c \
Middlewares/Third_Party/LwIP/src/netif/slipif.c \
Middlewares/Third_Party/LwIP/src/netif/zepif.c \
Middlewares/Third_Party/LwIP/src/netif/ppp/ecp.c \
Middlewares/Third_Party/LwIP/src/api/api_lib.c \
Middlewares/Third_Party/LwIP/src/api/api_msg.c \
Middlewares/Third_Party/LwIP/src/api/err.c \
Middlewares/Third_Party/LwIP/src/api/if_api.c \
Middlewares/Third_Party/LwIP/src/api/netbuf.c \
Middlewares/Third_Party/LwIP/src/api/netdb.c \
Middlewares/Third_Party/LwIP/src/api/netifapi.c \
Middlewares/Third_Party/LwIP/src/api/sockets.c \
Middlewares/Third_Party/LwIP/src/api/tcpip.c \
Middlewares/Third_Party/LwIP/src/core/altcp.c \
Middlewares/Third_Party/LwIP/src/core/altcp_alloc.c \
Middlewares/Third_Party/LwIP/src/core/altcp_tcp.c \
Middlewares/Third_Party/LwIP/src/core/def.c \
Middlewares/Third_Party/LwIP/src/core/dns.c \
Middlewares/Third_Party/LwIP/src/core/inet_chksum.c \
Middlewares/Third_Party/LwIP/src/core/init.c \
Middlewares/Third_Party/LwIP/src/core/ip.c \
Middlewares/Third_Party/LwIP/src/core/mem.c \
Middlewares/Third_Party/LwIP/src/core/memp.c \
Middlewares/Third_Party/LwIP/src/core/netif.c \
Middlewares/Third_Party/LwIP/src/core/pbuf.c \
Middlewares/Third_Party/LwIP/src/core/raw.c \
Middlewares/Third_Party/LwIP/src/core/stats.c \
Middlewares/Third_Party/LwIP/src/core/sys.c \
Middlewares/Third_Party/LwIP/src/core/tcp.c \
Middlewares/Third_Party/LwIP/src/core/tcp_in.c \
Middlewares/Third_Party/LwIP/src/core/tcp_out.c \
Middlewares/Third_Party/LwIP/src/core/timeouts.c \
Middlewares/Third_Party/LwIP/src/core/udp.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/autoip.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/dhcp.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/etharp.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/icmp.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/igmp.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/ip4.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_addr.c \
Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_frag.c \
Middlewares/Third_Party/LwIP/src/core/ipv6/dhcp6.c \
Middlewares/Third_Party/LwIP/src/core/ipv6/ethip6.c \
Middlewares/Third_Party/LwIP/src/core/ipv6/icmp6.c \
Middlewares/Third_Party/LwIP/src/core/ipv6/inet6.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/ip6_frag.c \
Middlewares/Third_Party/LwIP/src/core/ipv6/mld6.c \
Middlewares/Third_Party/LwIP/src/core/ipv6/nd6.c \
Middlewares/Third_Party/LwIP/system/OS/sys_arch.c \
Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c \
Core/Src/FreeRTOS-openocd.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 =  \
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)/$(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 = $(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

#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m4

# fpu
FPU = -mfpu=fpv4-sp-d16

# float-abi
FLOAT-ABI = -mfloat-abi=hard

# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)

# macros for gcc
# AS defines
AS_DEFS = 

# C defines
C_DEFS =  \
-DUSE_HAL_DRIVER \
-DSTM32F407xx \
-D_TIMEVAL_DEFINE

# AS includes
AS_INCLUDES =  \
-ICore\Inc

# C includes
C_INCLUDES =  \
-ICore/Inc \
-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 \
-ILWIP/App \
-ILWIP/Target \
-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/compat/posix \
-IMiddlewares/Third_Party/LwIP/src/include/compat/posix/arpa \
-IMiddlewares/Third_Party/LwIP/src/include/compat/posix/net \
-IMiddlewares/Third_Party/LwIP/src/include/compat/posix/sys \
-IMiddlewares/Third_Party/LwIP/src/include/compat/stdc \
-IMiddlewares/Third_Party/LwIP/system/arch \
-I$(UROS_APP_FOLDER)

MICROROS_INCLUDES += $(shell find $(UROS_DIR)/install -name 'include' | sed -E "s/(.*)/-I\1/")
MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/lib/include
MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/lib/include/FreeRTOS_POSIX
MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/lib/include/private
MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/lib/FreeRTOS-Plus-POSIX/include
MICROROS_INCLUDES += -I$(EXTENSIONS_DIR)/lib/FreeRTOS-Plus-POSIX/include/portable
C_INCLUDES += $(MICROROS_INCLUDES)

COLCON_INCLUDES += $(EXTENSIONS_DIR)/lib/FreeRTOS-Plus-POSIX/include
COLCON_INCLUDES += $(EXTENSIONS_DIR)/lib/include
COLCON_INCLUDES += $(EXTENSIONS_DIR)/lib/include/private
COLCON_INCLUDES += $(EXTENSIONS_DIR)/lib/include/FreeRTOS_POSIX
COLCON_INCLUDES += $(EXTENSIONS_DIR)/lib/include/FreeRTOS_POSIX/sys
COLCON_INCLUDES += $(EXTENSIONS_DIR)/Core/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_STR := $(foreach x,$(COLCON_INCLUDES),$(x)\n)

# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

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
#######################################
# link script
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,--undefined=uxTopUsedPriority

# 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)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 
    $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
    $(AS) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
    $(CC) $(OBJECTS) $(LDFLAGS) -o $@
    $(SZ) $@

$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
    $(HEX) $< $@

$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
    $(BIN) $< $@    

$(BUILD_DIR):
    mkdir $@        

#######################################
# clean up
#######################################
clean:
    -rm -fR $(BUILD_DIR)

#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)

# *** EOF ***

and when I start to add

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdbool.h>
#include "allocators.h"

#include <rcl/rcl.h>
#include <rmw_microxrcedds_c/config.h>
#include <ucdr/microcdr.h>
#include <uxr/client/client.h>
#include <lwip.h>
/* USER CODE END Includes */

and add feature to void StartDefaultTask(void *argument)

Like

/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
  /* init code for LWIP */
  MX_LWIP_Init();
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET);
  bool availableNetwork = false;

#ifdef MICRO_XRCEDDS_CUSTOM_SERIAL 
  availableNetwork = true;
#elif defined(MICRO_XRCEDDS_UDP)
  printf("Ethernet Initialization \r\n");

  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

  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.stack_size = 5 * 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");

  for(;;)
  {
    if (eTaskGetState(xHandle) != eSuspended && availableNetwork)
    {
        HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET);    
    osDelay(150);
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);
    osDelay(150);   
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET);    
    osDelay(150);
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_RESET);
    osDelay(150);
    }
    else {
        HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET);    
    osDelay(1000);
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);
    osDelay(1000);  
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET);    
    osDelay(1000);
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_RESET);
    osDelay(1000);
    }
  }
  /* USER CODE END StartDefaultTask */
}

Especially with code here

  osThreadAttr_t attributes;
  memset(&attributes, 0x0, sizeof(osThreadAttr_t));
  attributes.stack_size = 5 * 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");

and this One

 if (eTaskGetState(xHandle) != eSuspended && availableNetwork)

the Building error comes out.

pablogs9 commented 3 years ago

Could you please provide steps for replicating this?

This is:

Needrom commented 3 years ago

sorry for taking so long, here is my repo that you can check the project I use and the config file I use https://github.com/Needrom/Microros-on-DIscovery-board

pablogs9 commented 3 years ago

With these changes, I have been able to build it: https://github.com/Needrom/Microros-on-DIscovery-board/pull/1

Needrom commented 3 years ago

With these changes, I have been able to build it: Needrom/Microros-on-DIscovery-board#1

Yes!It can build now ! appreciate for that

pablogs9 commented 3 years ago

Cool, let us know about your progress and projects!

Needrom commented 3 years ago

Sure! Will do.