Trying to get lwIP to work Topic is solved

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

Pethead
Posts: 37
Joined: Mon Jul 11, 2016 1:47 pm
Has thanked: 1 time

Trying to get lwIP to work

Postby Pethead » 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:

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.mk

In 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                 TRUE

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

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/include

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:

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.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Trying to get lwIP to work

Postby Giovanni » Mon Jan 30, 2017 10:48 am

Hi,

I suggest you take a Makefile from one of the provided lwIP demos and start from there, apparently you have wrong paths somewhere.

Giovanni

Pethead
Posts: 37
Joined: Mon Jul 11, 2016 1:47 pm
Has thanked: 1 time

Re: Trying to get lwIP to work

Postby Pethead » Mon Jan 30, 2017 1:38 pm

I've been trying to find where it might be wrong but I kind of gave up and I decided to re-download ChibiOS 3.0.2 without removing or changing anything and then just extract the lwip folder. I then copy the files from one of the demos and I still get the same problem as before.. Although all of the errors are "semantic errors" and show the following:

Code: Select all

Description   Resource   Path   Location   Type
Type 'MACDriver' could not be resolved   mac_lld.c   /eth/ChibiOS_3.0.2/os/hal/ports/STM32/LLD   line 402   Semantic Error

I've never really heard the term "Semantic error" before:
Semantic errors: These are valid code the compiler understands, but they do not what you, the programmer, intended. These may be using the wrong variable, the wrong operation, or operations in the wrong order. There is no way for the compiler to detect them.

I assume this is a problem? :?
Last edited by Pethead on Mon Jan 30, 2017 1:42 pm, edited 1 time in total.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Trying to get lwIP to work

Postby Giovanni » Mon Jan 30, 2017 1:41 pm

You are using Eclipse probably, those errors are not compilation errors, it is the Eclipse static analyser, you can disable it in preferences.

Note that 3.0.2 is quite old now and unsupported, latest is 16.1.7.

Giovanni

Pethead
Posts: 37
Joined: Mon Jul 11, 2016 1:47 pm
Has thanked: 1 time

Re: Trying to get lwIP to work

Postby Pethead » Mon Jan 30, 2017 1:52 pm

Yes I am using eclipse. Thanks for the heads up.

I'm just wondering why the sudden jump in version number or is that I just can't see the different versions on the website? Are there any major differences between the different versions and is 16.x.x also MISRA C compliant?

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Trying to get lwIP to work

Postby Giovanni » Mon Jan 30, 2017 1:57 pm

It is MISRA compliant. The numbering system changed, it is now year.month.revision.

Giovanni

Pethead
Posts: 37
Joined: Mon Jul 11, 2016 1:47 pm
Has thanked: 1 time

Re: Trying to get lwIP to work

Postby Pethead » Wed Feb 01, 2017 2:09 pm

I am still struggling with getting this to actually work...

I am trying to run the OlimexE407 LWIP-FATFS-usb but only the http part and I am getting undefined references from calling the following in lwipthread.c

Code: Select all

  /* Setup event sources.*/
  evtObjectInit(&evt, LWIP_LINK_POLL_INTERVAL);
  evtStart(&evt);


The file evtimer.h is included and I don't think that is the problem since I can call the function evtStart() without any problems from lwipthread.c

Any ideas?

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Trying to get lwIP to work

Postby Giovanni » Wed Feb 01, 2017 2:53 pm

Could you post the compilation log?

Giovanni

Pethead
Posts: 37
Joined: Mon Jul 11, 2016 1:47 pm
Has thanked: 1 time

Re: Trying to get lwIP to work

Postby Pethead » Wed Feb 01, 2017 4:11 pm

compilation log

I also have another problem, similar to this that everything freezes if I have the HAL_USE_MAC defined to true, which is probably (like in the thread mentioned) due to wrong settings in the board.h file so I am trying to configure my board.h file properly.

Try to set HAL_USE_MAC in your halconf.h to FALSE for a try. What you describes happens for example, when the MAC HAL does get initialized but no PHY could have been found.


I assume I only need to fix the settings for the ports that are connected to the LAN8720A chip?
Last edited by Pethead on Wed Feb 01, 2017 4:17 pm, edited 1 time in total.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Trying to get lwIP to work

Postby Giovanni » Wed Feb 01, 2017 4:16 pm

Apparently /os/various is in the inclusion paths but the evttimer.c file is not in the list of files to be compiled, check your makefile or post it here.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 23 guests