Trying to get lwIP to work
Posted: Mon Jan 30, 2017 10:28 am
Hello,
I've been trying to get a baseline project working with the LWIP stack on ChibiOS for a few days now and it's making my head hurt because I am not getting it to work as there aren't any really good examples out there on how to get it working properly. I am using the EasyMX PRO V7 board with a STM32F407VGT6 MCU card.
There's clearly something wrong with my combination of board/Makefile/chconf/mcuconf but I can't really pinpoint what's wrong.
First of all I started by doing what the readme.txt under ChibiOS/os/various/lwip-bindings is saying as you can see below:
Then I add the $(LWSRC) and &(LWINC) variables defined in the lwip.mk file to CSRC and INCDIR respectively in my makefile below.
In order for this to work I also need to enable the MAC peripheral on the STM32F407 in halconf.h
Once this is done I try to compile the project which results in a bunch of errors in mac_lld.c and most of the errors are due to the MACDriver struct in mac_lld.h "could not be resolved" and when I look in mac_lld.h everything is "grey" because my #define HAL_USE_MAC TRUE in halconf.h is not getting recognition.
The file should be included from platform.mk since the file mac_lld.h is located in chibios/os/hal/ports/STM32/LLD
If I add #include "mac_lld.h" in mac_lld.c all the definitions and declarations are not grey any more but then the MACDriver struct is still not working because the type macstate_t (which is defined in mac.h) "could not be resolved" even though it should be included through hal.mk.
And the mac.h file is there locally in the folder so it's not like the header isn't there and I can clearly see the macstate_t struct definition if I open the file:
I am using ChibiOS 3.0.2 and LWIP 1.4.0.
I've been trying to get a baseline project working with the LWIP stack on ChibiOS for a few days now and it's making my head hurt because I am not getting it to work as there aren't any really good examples out there on how to get it working properly. I am using the EasyMX PRO V7 board with a STM32F407VGT6 MCU card.
There's clearly something wrong with my combination of board/Makefile/chconf/mcuconf but I can't really pinpoint what's wrong.
First of all I started by doing what the readme.txt under ChibiOS/os/various/lwip-bindings is saying as you can see below:
Code: Select all
This directory contains the ChibiOS/RT "official" bindings with the lwIP
TCP/IP stack: http://savannah.nongnu.org/projects/lwip
In order to use lwIP within ChibiOS/RT project, unzip lwIP under
./ext/lwip then include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk
in your makefile.Then I add the $(LWSRC) and &(LWINC) variables defined in the lwip.mk file to CSRC and INCDIR respectively in my makefile below.
Code: Select all
##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99
USE_OPT += -DBOARD_OTG_NOVBUSSENS $(build_args)
USE_OPT += -fsingle-precision-constant -Wdouble-promotion
endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT =
endif
# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -fno-rtti
endif
# Enable this if you want the linker to remove unused code and data
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
endif
# Linker extra options here.
ifeq ($(USE_LDOPT),)
USE_LDOPT =
endif
# Enable this if you want link time optimizations (LTO)
ifeq ($(USE_LTO),)
USE_LTO = no
endif
# If enabled, this option allows to compile the application in THUMB mode.
ifeq ($(USE_THUMB),)
USE_THUMB = yes
endif
# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
USE_VERBOSE_COMPILE = yes
endif
# If enabled, this option makes the build process faster by not compiling
# modules not used in the current configuration.
ifeq ($(USE_SMART_BUILD),)
USE_SMART_BUILD = yes
endif
#
# Build global options
##############################################################################
##############################################################################
# Architecture or project specific options
#
# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
USE_PROCESS_STACKSIZE = 0x400
endif
# Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
USE_EXCEPTIONS_STACKSIZE = 0x400
endif
# Enables the use of FPU on Cortex-M4 (no, softfp, hard).
ifeq ($(USE_FPU),)
USE_FPU = hard
endif
# Enable this if you really want to use the STM FWLib.
ifeq ($(USE_FWLIB),)
USE_FWLIB = yes
endif
#
# Architecture or project specific options
##############################################################################
##############################################################################
# Project, sources and paths
#
# Define project name here
PROJECT = eth
# Imported source files and paths
CHIBIOS = ChibiOS_3.0.2
# Startup files.
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk
include $(CHIBIOS)/os/hal/boards/ST_STM32F4_DISCOVERY/board.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# lwIP stack
include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk
# Define linker script file here
LDSCRIPT= ld_eeprom_emu.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC = $(STARTUPSRC) \
$(KERNSRC) \
$(PORTSRC) \
$(OSALSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
$(CHIBIOS)/os/various/syscalls.c \
$(LWSRC) \
main.c \
adconv.c \
eeprom.c \
comm_usb_serial.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CPPSRC =
# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACSRC =
# C++ sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACPPSRC =
# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCSRC =
# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCPPSRC =
# List ASM source files here
ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/various \
$(CHIBIOS)/os/hal/lib/streams \
$(LWINC) \
$(CC2520INC) $(CC1120INC)
#
# Project, sources and paths
##############################################################################
##############################################################################
# Compiler settings
#
MCU = cortex-m4
#TRGT = arm-elf-
TRGT = arm-none-eabi-
CC = $(TRGT)gcc
CPPC = $(TRGT)g++
# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
# runtime support makes code size explode.
LD = $(TRGT)gcc
#LD = $(TRGT)g++
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
AR = $(TRGT)ar
OD = $(TRGT)objdump
SZ = $(TRGT)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
# ARM-specific options here
AOPT =
# THUMB-specific options here
TOPT = -mthumb -DTHUMB
# Define C warning options here
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
# Define C++ warning options here
CPPWARN = -Wall -Wextra -Wundef
#
# Compiler settings
##############################################################################
##############################################################################
# Start of user section
#
# List all user C define here, like -D_DEBUG=1
UDEFS =
# Define ASM defines here
UADEFS =
# List all user directories here
UINCDIR =
# List the user directory to look for the libraries here
ULIBDIR =
# List all user libraries here
ULIBS = -lm
#
# End of user defines
##############################################################################
ifeq ($(USE_FWLIB),yes)
include $(CHIBIOS)/ext/stdperiph_stm32f4/stm32lib.mk
CSRC += $(STM32SRC)
INCDIR += $(STM32INC)
USE_OPT += -DUSE_STDPERIPH_DRIVER
endif
build/$(PROJECT).bin: build/$(PROJECT).elf
$(BIN) build/$(PROJECT).elf build/$(PROJECT).bin
# Program
upload: build/$(PROJECT).bin
#qstlink2 --cli --erase --write build/$(PROJECT).bin
openocd -f interface/stlink-v2.cfg -c "set WORKAREASIZE 0x2000" -f target/stm32f4x_stlink.cfg -c "program build/$(PROJECT).elf verify reset"
#openocd -f board/stm32f4discovery.cfg -c "reset_config trst_only combined" -c "program build/$(PROJECT).elf verify reset exit" # For openocd 0.9
#program with olimex arm-usb-tiny-h and jtag-swd adapter board. needs openocd>=0.9
upload-olimex: build/$(PROJECT).bin
openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f interface/ftdi/olimex-arm-jtag-swd.cfg -c "set WORKAREASIZE 0x2000" -f target/stm32f4x.cfg -c "program build/$(PROJECT).elf verify reset"
debug-start:
openocd -f stm32-bv_openocd.cfg
RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
include $(RULESPATH)/rules.mkIn order for this to work I also need to enable the MAC peripheral on the STM32F407 in halconf.h
Code: Select all
#define HAL_USE_MAC TRUEOnce this is done I try to compile the project which results in a bunch of errors in mac_lld.c and most of the errors are due to the MACDriver struct in mac_lld.h "could not be resolved" and when I look in mac_lld.h everything is "grey" because my #define HAL_USE_MAC TRUE in halconf.h is not getting recognition.
The file should be included from platform.mk since the file mac_lld.h is located in chibios/os/hal/ports/STM32/LLD
Code: Select all
# Required include directories
PLATFORMINC := $(CHIBIOS)/os/hal/ports/common/ARMCMx \
$(CHIBIOS)/os/hal/ports/STM32/STM32F4xx \
$(CHIBIOS)/os/hal/ports/STM32/LLD \
$(CHIBIOS)/os/hal/ports/STM32/LLD/DACv1 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/GPIOv2 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/I2Cv1 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/OTGv1 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/RTCv2 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/SPIv1 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/TIMv1 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv1 \
$(CHIBIOS)/os/hal/ports/STM32/LLD/FSMCv1 If I add #include "mac_lld.h" in mac_lld.c all the definitions and declarations are not grey any more but then the MACDriver struct is still not working because the type macstate_t (which is defined in mac.h) "could not be resolved" even though it should be included through hal.mk.
Code: Select all
# Required include directories
HALINC = $(CHIBIOS)/os/hal/includeAnd the mac.h file is there locally in the folder so it's not like the header isn't there and I can clearly see the macstate_t struct definition if I open the file:
Code: Select all
/**
* @brief Driver state machine possible states.
*/
typedef enum {
MAC_UNINIT = 0, /**< Not initialized. */
MAC_STOP = 1, /**< Stopped. */
MAC_ACTIVE = 2 /**< Active. */
} macstate_t;
I am using ChibiOS 3.0.2 and LWIP 1.4.0.