I am still working on a device consisting of STM32 Nucleo F103RB with a W5100 Ethernet shield. This time I included a DHCP client, so that when the device is attached to a network, it will ask for an IP address instead of being statically allocated.

STM32 Nucleo connected with Ethernet shield.
The DHCP protocol follows the RFC 2131 and RFC 2132, and I implemented the library following these specifications. The library depends on a generic POSIX interface that I implemented recently, with no direct dependence to the hardware below, but I also created a wrapper for W5100 that can be used to automatically configure the IP address into the Ethernet interface when the DHCP binds the device to an address.
I fired Wireshark on a computer that is connected to the same router, and by sniffing the packets I can look at the interactions between the Nucleo and the router, shown in the figure below. At first there’s a Discover-Offer transaction between client and server that indicates an available IP address, and then a Request-Ack transaction to bind that address to the client. The transactions are also used to retrieve the gateway, subnet and DNS servers that the client can configure.

Wireshark capture of DHCP address allocation.
The address is bound with a lease time, so when the lease is expiring it needs to be renewed, so the library needs to be called again after some time to renew the lease. In order to manage time, I also implemented a rudimentary implementation of POSIX time functions, that use Cortex-M SysTick interrupt to count the passage of time.
If you want to try this library, you need:
- a Nucleo F103RB + W5100 Ethernet shield,
- GCC ARM Embedded toolchain to compile the program,
- OpenOCD to write the program into STM32 embedded flash,
- a router that offers DHCP services.
Then you can:
- clone my GitHub repository,
- change directory to `
tests/dhcp_allocate
`, - run `
make flash
` to compile and upload program, - wait for the Ethernet shield LEDs to indicate that the link is up,
- connect a terminal to the Nucleo serial port with baud rate 57600, for example with `
minicom -b 57600 -D /dev/ttyACM0
`, - press any key in the terminal to start DHCP address allocation.
Alex Rackennene
2015/12/10
Hi Balau. I have a problem with developing embedded apps for a uClinux. I do not understand how to start write code. I installed an u-boot and uClinux on board. i did it, but now can not do any program for uClinux. I have the “arm-none-eabi-” (as,ld,gcc,…etc.) family utils for a work. it is a first part of work. Second part is to begin a write an applied program. How to do it. I downloaded a uClibc – lib, but have a problem for configuring and therefore compiling and building it to *.a for next using to develop a software. So uClinux uses a “bflt” version of elf format. Do not know how to convert arm-elf output file to bflt?! Last question is consist of the tools…..: what the difference between “arm-none-eabi-gcc” and “arm-elf-gcc/m68k-elf-gcc”. Should i use it both for developing or “arm-none-eabi-gcc” pack tools are enough? While solving this one i can not continue to ecomplish my small project.
Best regards
p.s.
I home the writings above are more less coherent and understandable.
Balau
2015/12/10
I have no experience on uClinux, so I can’t be sure, but
arm-none-eabi
toolchain can compile the kernel or bare-metal programs such as u-boot. If I understand correctly you want to build a program that runs on top of an operating system, which is uClinux. In this case you need a toolchain that builds a “userspace” program that uses uClinux system calls. The uClinux website has links to downloadarm-elf-tools
which seems like the toolchain to use.The difference between toolchains is for example answered here, in practice if you have a board with a m68k chip then you need to use m68k-* toolchain, if you have an ARM board you need to use arm-* toolchain.
I think you should use the arm-elf-tools that you find in uClinux for everything, which is compiling u-boot, uClinux and your program. I don’t think arm-none-eabi is suitable for compiling your program.
About the
bflt
part, it could be (reading from here) just a matter of adding-Wl,-elf2flt
to linking step.