Standalone USB firmware Jun 1, 2016

Announcement: As of today, the JeeLabs weblog is switching into lower gear, as we move towards the Northern hemisphere’s summer recess. Instead of a weekly post plus several articles, there will be just one single post (on Wednesdays, as always).

This week continues where I left off the last time. The USB driver is now good enough to run stand-alone on a board like the HyTiny:

No more serial USB interface adapters, this now talks serial directly over built-in USB.

This does not mean you should throw away your serial FTDI BUB or Black Magic Probe, however. They will still be needed to get the firmware onto the board in the first place. We’re still dealing with chickens-and-eggs!

And since there is a small but nevertheless real risk of losing console access in Mecrisp (by messing up flash memory or defining an incorrect init word), you also need to keep it around for such last-resort recoveries.

Then again: a working “Mecrisp w/ USB” setup can easily be turned into a serial port interface similar to those FTDI / Prolific / CH340 / etc units. So another option is to keep a spare Mecrisp w/ USB board around.

For convenience, I’ve created a couple of hex firmware snapshots of the entire setup, i.e. the exact same code as can be compiled on top of a “clean Mecrisp core”. Pick the proper image for your board and upload it:

The code definitions corresponding to these boards are as follows, respectively:

: usb-pulse OMODE-OD PA12 io-mode!  PA12 ioc!  1 ms  PA12 ios! ;
: usb-pulse OMODE-PP PA0 io-mode!  PA0 ios!  1 ms  PA0 ioc! ;
: usb-pulse OMODE-PP PC12 io-mode!  PC12 ios!  1 ms  PC12 ioc! ;

The generic build also works on the Blue Pill, one of the cheapest µC boards around.

More boards could easily be supported, it’s just a matter of tweaking the code for the USB 1.5 kΩ pull-up enable to match each specific board. See the examples on GitHub.

After you’ve uploaded the image, don’t forget to reset the BOOT0 jumper to low if you used the ROM serial boot loader. Then disconnect all cables, and plug it into USB. You should see a new COM<N>, /dev/cu.*, or /dev/tty* serial port. You can connect to it using Folie or any other terminal emulator - the actual baud rate will be as high as the USB link and µC load allows.

There are bound to be some differences with a serial-connected Mecrisp setup. The main one to be aware of is that calling reset also resets the USB connection (just as with an Arduino Leonardo, by the way). Maybe there is a way to re-implement reset and keep the USB connection intact - I haven’t figured out a good solution for this yet.

Note that these builds are still proof-of-concept at the moment, they will be updated on GitHub once the issues mentioned in the previous article have been ironed out.

Weblog © Jean-Claude Wippler. Generated by Hugo.