Overview:
This application starts a DHCPv4 client, gets an IPv4 address from the DHCPv4 server, and prints address, lease time, netmask and router information to a serial console.This example uses Zephyr supported STM32F411re as a Target MCU board and W5500 for ethernet connectivity.
Prerequisite:Set up a command-line Zephyr development environment on Ubuntu..Get the source codeBuild, flash, and run a sample applicationRefer to Zephyr getting started guide before running any native TCP/IP examples.
Zephyr OS
The Zephyr RTOS is a relatively new real-time operating system for a wide variety of MCU architectures.
The majority of other RTOSes focusing on cloud integration are backed by companies and are not really independent. FreeRTOS is backed by Amazon,Azure RTOS (ThreadX) is backed by Microsoft, etc. The Zephyr RTOS however is supported by the Zephyr Project run by the Linux Foundation which is non-profit organization with the aim of building sustainable ecosystems around open source projects to accelerate technology development and commercial adoption.
This background of the Zephyr RTOS accelerates it’s adoption and it’s development in the open source GitHub repository. The Zephyr RTOS receives a massive amount of contributions.
One things which makes Zephyr RTOS kind of unique in comparison to other RTOSes is it’s build and configuration system. The build system is CMake which is common in the (embedded) Linux world and familiar to a lot of C and C++ developers. The configuration system is Kconfigwhich is common in the Linux world as well cause it’s the Kernel’s configuration system. This has a big impact.
Development environment
Set up for Command-line Zephyr development environment on Ubuntu as Zephyr docs provides a detailed steps.Zephyr getting started guide I have used Ubuntu 64-bit 20.04 in virtual machine
Hardware Environment
MCU: STM32 Nucleo F411reEthernet: W5500 Ethernet Shield
Zephyr supported board
STM32 F411re is Zephyr supported board..For a complete and up-to-date list of supported boards and release information please refer to the Zephyr Project website supported boards page, and current release information page.
Wiznet's W5500 is implemented as independent driver in Zephyr tree under drivers/ethernet. You can add device tree adaption and run any native TCP/IP applications.
DHCPv4 client:
Always start with simple model before you become familiar..This particular example has less effort from user..
Probably a good place to start is with the dhcp example, to make sure that works.
Most of the net examples require you to hard-code the network parameters instead of using dhcp.
Configuration:
First thing is to choose which board you are targeting? This example, I have used STM32-Nucleo-F411RE board..
Create your overlay files and config files based on your target board..
And create a boards
folder inside the sample that you're trying out and then add files(conf and overlay) related to the device that you're testing inside boards folder.
You can add subnodes using overlays.
For example, to configure a SPI on an existing bus node, do something like this:
Current project's overlay file is attached below..
Overlay files contain tweaks or changes to the SoC and Board support files.
They can be used to modify Device Tree configurations without having to change the SoC and Board files. See Device Tree Overlays for more information on overlay files and the Zephyr build system.
Zephyr uses that folder to find board specify settings.
Build and Flash:
Build the dhcpv4_client with west build, changing <your-board-name> appropriately for your board:
The -p always option forces a pristine build, and is recommended for new users. Users may also use the -p auto option, which will use heuristics to determine if a pristine build is required, such as when building another sample.
Then flash the sample using west flash:
My environment throw error sometimes for using west flash..
It sometimes shows that it can't communicate with the board.
For stm32 nucleo you can skip flashing with west and mount the virtual USB drive then copy the .bin file to it.
Activate the virtual environment:
Also make sure to activate the virtual environment every time you start working with Zephyr.. The above error can be avoided with setting up virtual environment..
Running the example:
After west build and flash, Once DHCPv4 client address negotiation completed with server, details are shown like this:
To verify the Zephyr application client is running and has received an ip address by typing:
If you want to try RP2040 as your target board with W5500, please refer to Zephyr echo server..
Also Zephyr has discord server for support..
Comments
Please log in or sign up to comment.