Adding a custom USB socket to the STM32 NUCLEO-F746

I’m currently building a design on the STM32F7 which I want to later port to a F4-NUCLEO board and eventually my own design so I want to test the USB host without the supplied electronics.

In order to do this I built a small USB breakout adapter and tried directly connecting this to 5V (for power) and PA11/PA12 (for USB).  The breakout was made by simply soldering some header pins to a USB socket.

I then attached the USB socket to CN12 as shown below.

The complete pinout for CN12 can be found here

You will need to connect the pins on the usb connector as shown below:

  1. VBUS (+5v)
  2. PA11
  3. PA12
  4. GND

GRE tunneling for fun and profit.

I recently subscribed to Netflix and being in the UK I found that they have loads more available in the US to watch.  To get around this in a way that would also allow me to stream programmes to my chromecast is actually quite complicated.  As I have small Linux box on my network to provide IPv6 via a tunnel I thought I would allow this to also allow access via a GRE tunnel to a VPS running in the US.

The first thing you need to do is setup the machine in the US so it can do NAT just like your home router can do with the following:
echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -F FORWARD

iptables -A FORWARD -m state –state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT

iptables -A INPUT -i us-gre -j ACCEPT
iptables -A FORWARD -i us-gre -j ACCEPT
iptables -A INPUT -i us-gre -j ACCEPT
iptables -A FORWARD -i us-gre -j ACCEPT

Your then need to setup a GRE tunnel between your VM running in another country and your home network.  One thing to be aware of is that GRE tunnels use a specific IP protocol number rather than TCP or UDP.  This means that your need to either activate an option which enables this or setup the machine doing the routing on your home network as the DMZ host.

I used the following to setup a GRE tunnel on the VPS which will forward all data to my home network over the tunnel (my home network has addresses in the 192.168.x.x range).

ip tunnel del us-gre
ip tunnel add us-gre mode gre remote local ttl 255

ip link set us-gre up
ip addr add 192.168.X.1/24 dev us-gre

echo add routes

ip route add via 192.168.X.10 dev us-gre
#ip route add dev us-gre

Once you have everything setup on the VPS VM then your need to do the same on your home network with the following:

# VPN hosts.
ip rule add from 192.168.0.x table vpn

# Add default routes for vpn table.
ip route add default via dev tun0 table vpn

ip route flush cache

ip tunnel del us-gre
ip tunnel add us-gre mode gre remote local ttl 255

ip link set us-gre up
ip addr add dev us-gre

echo add default route

ip route add via dev us-gre table vpn

You will also need to run the following to add a table so you can have different routing destinations for different hosts which route via this machine.

echo 200 vpn >> /etc/iproute2/rt_tables

In order to make a machine use the tunnel your need to adjust your DHCP settings so the machine you want uses the machine with the tunnel as it’s default route. Once this is done your use:

ip rule add from ip route flush cache

table vpn on the machine with the tunnel on it. This creates a rule which makes the requested machine use a different routing table to all other traffic.

Disaster recovery

So the last 24hrs has been spent mostly recovering from disasters. The electricity was switched off recently at my flat which managed to take down my little arm server. For some reason it didn’t come back up when the power was restored so had to be manually rebooted last night. This turned out to be an exercise in futility as for some reason icedove (debian version of thunderbird) wasn’t showing any mail folders on my mail server. I ended up having to delete the server resync everything and recreate my mail filters which wasn’t fun.
After this I’m kind of toying with the idea of building a backup power system for it. It should be relatively simple as I can just float charge a SLA battery and use switch mode regulators to provide 12V and 5V outputs for my NAS and home server. I can also use the unregulated 24V from the battery to supply power for my next version of my tube time displaying clock next to my bed.
Of course this wasn’t the only fun to be had as I also had a flat tyre on the Brompton coming into Kings X. I ended up sitting on the floor by the doors on the train with a dismantled back wheel of a bike. The back wheel on my bike is especially bad as to remove it you have to take off the chain tensioner and disconnect the hub gear cable (which then needs to be readjusted or you can’t change gears properly). I did better though then last time I had to change the tire and my tirelever combined with spanner thingy saved the day again as I only needed one tool and it’s a metal tire lever so doesn’t snap (though it is coated in plastic).