rohfle
STM32-E407 support added to Mbed OS

I have recently worked on adding support for the Olimex STM32-E407 in Mbed OS, an OS for IoT devices based on 32-bit ARM Cortex-M MCUs. Mbed OS is developed by ARM and its partners and is licensed under Apache 2.0.

UPDATE: Support has been merged and is included in release 5.15.0

Why Mbed?

I started adding support due to frustration with the GUI-based tools available for STM32. I prefer to work from the command-line usually, but I found working with STM32Cube and STM32CubeMX to be especially complicated and tedious. Having USER CODE BEGIN etc every 4 lines diluted the code down making it harder to digest, and STM32CubeMX is not optimised for 13 inch laptop screens.

Another thing that frustrated me was the complexity of working with the standard STM32 libraries. Despite finding multiple examples, I found using Ethernet, TCP/IP and USB to be messy and difficult. On the the other hand, Mbed OS had great documentation, and was really simple to use. It feels to me like a grown up Arduino, with RTOS, networking, USB and more included out of the box.

Example code

Here is a short example that sets up Ethernet, connects to the network and makes a HTTP request to the ARM website (taken from https://os.mbed.com/docs/mbed-os/v5.14/apis/ethernet.html)

#include "mbed.h"
#include "EthernetInterface.h"

// Network interface
EthernetInterface net;

// Socket demo
int main() {
    // Bring up the ethernet interface
    printf("Ethernet socket example\n");
    net.connect();

    // Show the network address
    const char *ip = net.get_ip_address();
    printf("IP address is: %s\n", ip ? ip : "No IP");

    // Open a socket on the network interface, and create a TCP connection to mbed.org
    TCPSocket socket;
    socket.open(&net);
    socket.connect("www.arm.com", 80);

    // Send a simple http request
    char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
    int scount = socket.send(sbuffer, sizeof sbuffer);
    printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);

    // Recieve a simple http response and print out the response line
    char rbuffer[64];
    int rcount = socket.recv(rbuffer, sizeof rbuffer);
    printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);

    // Close the socket to return its memory and bring down the network interface
    socket.close();

    // Bring down the ethernet interface
    net.disconnect();
    printf("Done\n");
}

Pretty straightforward right?

How do I get it working?

I have created a tutorial here to help setup Mbed OS and program the STM32-E407