This is my eighth week of being an intern at Aeste Works. This week was about setting up and integrating the lwIP stack with the USB CDC ECM device. The device currently does not run with an operating system and so must be configured for the lwIP NOSYS mode using the raw (or native API).
The first step was to create a cc.h file that that describes the compiler and machine architecture to lwIP. The following are defined here: data types, printf formatters for the data types, byte ordering (endianness) which is little-endian for the PIC32 MZ on the USB CDC ECM device, computing checksums, platform specific diagnostic output and structured packing if the processor cannot read from/write to misaligned addresses. The second step was to create a sys_arch.h file. In the case for the NO_SYS environment, in which no operating system adaptation layer is required, this only contains some typedefs and preprocessor definitions. The third step was to create the lwipopts.h file which contains the specified settings that determine which optional portions of lwIP to include as well as how much memory will be used by the stack. The number one setting here is to define the preprocessor symbol NO_SYS to 1. The other settings configured here will override the built-in defaults in lwIP’s opts.h file.
Once these three configuration header files are set, the next step was to create the network driver for the USB CDC ECM device which should include the network interface initialization function, the input function when the lwIP has received a packet and the output function for when packets are ready for transmission. For now, I’ve coded the initialization and the input functions first and I’ll have to make sure that it works before working on the output function. In the initialization function, the following network interface structure variables were set: the hardware address, the number of bytes in the hardware address and the maximum transmission unit for the interface, in the case for ethernet was 1500 bytes. In the input function, the USB_DEVICE_CDC_Read is called once data is made available by the USB Host and will execute a data read from the USB Device CDC Function Driver Layer. Then, memory is allocated for a pbuf structure which is lwIP’s internal representation of a packet and its variables such as length and payload will be set by copying the values from the read buffer.
The last thing I did this week was to code the Network interface management. The first step here was to add the network interface via the netif_add function. Here, the IP address for the interface, its net mask, and gateway address is set. It also contains the callback functions for initialization and input. The last step here was to bring the interface up. In this case, a static IP address was set for the USB CDC ECM device and so the netif_set_up function was used. Next week, I’ll start to test whether the lwIP stack has been configured correctly and whether the interface can be successfully initialized.