Wifi for picoos-net & uIP

Picoos-net library has been lacking support for Wifi networks and I have been trying to figure out how to implement it.

I would like to run the network stack on the microcontroller along with my application so I could keep on using APIs I’m familiar with. This rules out modules that have built-in tcp/ip networking. However, writing whole Wifi stack would be a huge task and resulting library might be too big for some microcontrollers I have been using. So this rules out cheap usb-stick style approach.

hlk-rm04Microchip has a nice Wifi module, but documentation for it is not publicly available and their own network stack is limited (by license) for use with their own microcontrollers only.

Broadcom seems to have nice modules also (Wiced) and they seem to provide some kind of SDK, which might make integration of modules easier.

But there is one interesting module made by Hi-Link called HLK-RM04. It’s standard firmware implements a Wifi-rs232 module with AT-command set. But what makes it interesting is the fact that it is supported by OpenWrt firmware also. Flashing the module with OpenWrt allows running any standard Linux stuff on it (well, module has only 16 Mb of memory so small things only).

These modules are also very cheap, one can get them for less than 10€ on ebay or dx.com.

So I started thinking – what if I connect this module with USART or SPI into microcontroller and use that connection to pass raw ethernet frames ? Like I have been using ENC28J60 chip. RM04 module would only take care about Wifi connection setup but rest of network stack would run on microcontroller.

I first implemented a simple linux utility which opens serial port and TAP device and passes packets between TAP and serial port. Ethernet packets needed some extra framing when going over serial line which I solved by using hdlc-like framing used by PPP. Extra framing ensures that packets are not damaged in any way by using CRC checksum. I called this utility “hdlcbridge“.

To get this running on OpenWrt I compiled a minimal distribution using hlk-rm04-defconfig.

	Get OpenWRT Barrier Breaker sources on your Linux box
	./scripts/feeds update -a<
	./scripts/feeds install -a<
	cp hlk-rm04-defconfig .config
	make defconfig
	make

When this ends there is installable (but minimal) OpenWrt version in bin/ramips -directory (detailed build instructions are at OpenWrt web site). After this OpenWrt binary for hdlcbridge can be compiled by using provided openwrt-make.sh script.

Before starting hdlcbridge, OpenWrt wireless network must be configured. I have following configs: /etc/config/network


config interface 'lan'

  option ifname 'eth0.1 tap0'
  option force_link '1'
  option type 'bridge'
  option proto 'static'
  option ipaddr 'n.n.n.205'
  option netmask '255.255.255.0'
  option gateway 'n.n.n.1'
  option dns 'n.n.n.10'

/etc/config/wireless


config wifi-iface
	option device   radio0
	option network  lan
	option mode    sta
	option ssid     mynetwork
	option encryption psk2
	option key 'my password'
	option wds 1

With these configs tap0 is bridged into same network with LAN and Wifi interface (IP address for OpenWrt wouldn’t be strictly necessary but is easier to test and debug when there is network access to OpenWrt module too). Now it is possible to start hdlcbridge:


/root/hdlcbridge --serial /dev/ttyS0 --debug

Hdlcbridge is now runnig and passing packets between ttyS0 and tap0. It also print packet sizes (because –debug was used).

Second step was adding a hdlcbridge driver to picoos-net library. I had an extra Olimex STM32-P152 lying around and as it has an extra serial port available I decided to use it. I wired USART3 RX & TX lines into HLK-RM04’s TX2 & RX2 lines (TX2/RX2 is connected to /dev/ttyS0 in OpenWrt linux). Current picoos-net driver is a over-simplified one, using unoptimized buffering and polling during packet sending as I didn’t want to put too much effort in writing it before I know that this would work.

Indeed it works ! I was able to ping STM32-P152 board from my network. Latency was not optimal, about 20 ms but everything works including TCP connections. I think that latency should actually be better since the USART is running and 115200 baud, there might something left to optimize in hdlcbridge.

hlk-rm04-test-setup

It is a little bit odd to use “big” linux as slave for “small” Pico]OS, though.

Source code is at github. Driver is included in picoos-net library and test program is in net-test module.

Ari Suutari

Father of three 🙂
{ Electronics | Music | Computer | Motorbike } hobbyist.
Factory IT professional.
FreeBSD since day one.

Facebook LinkedIn  

7 Replies to “Wifi for picoos-net & uIP”

  1. Ok, I did some math about latency. If ping results in 79 byte ethernet packet (after hdlc-like framing is applied) that means that over serial line running at 115200 bits/s it will take 6.8 ms to transmit it. So that is almost 14 ms for roundtrip time. This means that about 20 ms ping latency is what really can be expected.

  2. So if I understand correctly, the tcp/ip stack is implemented external to Hi-Link board. The Hi-Link board is placed in a mode that just passes the RAW data serially?

    If so, what’s the biggest advantage of this setup vs having the module pass PROCESSED data? Speed? Protocols?

    Finally, hasn’t Pico]OS been officially discontinued? Have you forked it and maintaining a new version?
    (I had been looking at FreeRTOS and ROS but they seem rather complicated!)

    1. Yes, the HI-LINK board just passes raw data. The idea was to mimic other modules that do just that (like the microchip wifi module). Technically this is just a proof-of-concept and doesn’t make that much sense, but economically as the HI-LINK module is so cheap it does make *some* sense.

      About Pico]OS: Yes, the original author has discontinued development. My version is a fork, which contains newest versions of ports for cpu families I have been supporting (arm cortex-m, lpc2000, msp430 and unix). There are also some minor changes in Pico]OS itself (namely printf-style output).

    2. Another idea with this was that HI-LINK module can be used to convert existing uIP application from ethernet to Wifi just be replacing the driver, without any changes in application code.

    1. Having 32 mb would be nice, at least for other applications. When I experimented with OpenWRT on this module, it was quite easy to run out of ram. Maybe I have to get one of those modules to check it out.

Comments are closed.