Thursday, November 17, 2016

STM32F042 USB quirks with libopencm3

Needed a simple microntroller for an RF project, so picked the STM32F042F6P6 from ST.  It's cheap, comes in a 20-pin package, and has a built-in full speed USB device interface. It has an internal oscillator that can be synced to the USB signals from the host, so it doesn't even need a crystal.
It has a built-in DFU bootloader (among other programming options), so it requires no additional hardware to load the program.
After getting a simple LED blinker program to run, I decided to run some USB demo programs from the LIBOPENCM3 package. None of the demos are for this exact chip, but some are for the STM32F072, which is similar. Tried the tests/gadget-zero sample and ... No Go. The program loads and the LED's blink, but the USB device does not show up.
Turns out, there are a couple of subtle differences between this chip and the ones in bigger packages
  • The USB interface pins are shared with two other pins, and by default the USB pins are not connected to the outside world. Need to set a configuration bit so they can be used.
  • The peripheral clock needs to be turned on for the SYSCFG subsystem. I'm not sure whether that's a difference in the chips, or a quirk in libopencm3, but it's needed.
The setup calls at the beginning of the program for crystal-less USB operation are:
rcc_clock_setup_in_hsi48_out_48mhz();
rcc_periph_clock_enable(RCC_SYSCFG_COMP);
SYSCFG_CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP;
crs_autotrim_usb_enable()
rcc_set_usbclk_source(RCC_HSI48)
where the highlighted lines had to be added. With those two lines, gadget-zero shows up as a USB device in Linux. I was also able to the a cdc_acm demo working.

Acknowledgments

Several websites mention the pin-remapping issue, but the IFUSB project (github.com/julbouln/ifusb) was where I found the clock-enable issue and solution. IFUSB looks like a nice little peripheral, by the way.
Libopencm3 is at github.com/libopencm3/libopencm3
For programming, I use dfu-util: dfu-util.sourceforge.net. It's already included in Debian and probably other distributions.

Wednesday, September 28, 2016

Offtopic: phone scam

NOTE: the phone number below is what they said on the message. It might be fake, so whoever has that number might be totally innocent.

This was interesting. I got a scam phone call this morning. My best attempt at a transcription as follows:
Hi, my name is Keith Jordan, and this message is intended to contact you regarding an enforcement action executed by the United States Treasury,
intending your serious attention.
 
Ignoring this will be an intentional second attempt to avoid initial appearance before a magistrate judge or a grand jury for a federal criminal offense.
My number is 817 533 9843
I repeat  it's 817 533 9843
I invite you to cooperate with us and help us to help you.
Thank you.
I recorded this to my computer by holding the phone in front of the microphone while playing back the message, and then merging the audio with a photo of the caller id using:
ffmpeg -i /tmp/x.jpg -i scam.wav -acodec copy /tmp/simple.mov
I can display and play the result using mplayer on Debian Linux, not sure how it works anywhere else.

Us Treasury says to report this sort of thing:
www.treasury.gov/services/report-fwa/Pages/Report-Email-Scams.aspx
We'll see what happens.

Monday, August 22, 2016

Presentation: Codecs for Land Mobile Radio

Marina in front of Wentworth on the Sea.
On August 19 2016 I presented a talk to the "Enhanced Digital LMR Seminar" at Wentworth on the Sea, New Castle, NH (near Portsmouth).

The talk is an overview of speech codecs and their application in digital Land Mobile Radio systems. It's intended for an audience of radio system users and specialists rather than voice codec experts.

Slides for the presentation are online at:
joe1505.github.io/talks/index.html

Tuesday, February 23, 2016

Mobile-friendly web page

Decided it's time to make my websites mobile-friendly, since Google seems to consider that important these days. So I ran the tester at
which identified about 30 errors, including "Links too close together" and "Text too small to read" on multiple items. The latter error is particularly interesting because I typically use not-too-fancy html+css, and I don't set the font size anywhere. One of the main features of html is the separation of content and presentation, so decently written html should not require much tweaking for different displays. The html markup tells what things are, and the browser should be able to figure out a reasonable way of displaying those things.

After a little digging, I found the first step in mobilifying a web page is to add the magic incantation:
  •  <meta name=viewport content="width=device-width, initial-scale=1">
to the <head> section of the html file.

As it turns out, that's the last step as well: All the other error messages went away when I added that one line. As I understand it, that line basically tells the browser "just use html the way it's intended to be used" and then everything is fine.

Reorganizing this blog.

I decided it's time to reorganize the domain name setup for this blog. Previously, it was accessible via two web addresses:
 One side effect of this setup is that the blog's cookies are set up under my sensicomm.com domain. I decided that I don't like the idea of scripts that I didn't write and don't control running under  the identity of a domain that I do control.

So in the new setup this blog is still accessible and will appear unchanged using the blogspot address. The sensicomm address contains static copies of all previous postings, but not any comments made on those postings.

If you have a web site containing a like to an old blog post, you might want to update the link. For example,
  1. http://blog.sensicomm.com/2015/09/pebble-watch-programming.html
  2. http://sensicomm.blogspot.com/2015/09/pebble-watch-programming.html
The old address of this post[1] now points to the static copy of that post, while the new address[2] contains both the post and any comments.