SchmalzHaus logoUBW32 FAQ
By: Brian Schmalz
Back to UBW32

What is J2 and what part mates with it?

J2 is an extra power connector. So is J1. You can use either to apply 7.6V to 15V DC to the UBW32 to power it. The mating connector is any of the JST connectors that SparkFun sells, like this one or this one. (There are lots of others.) Note that it can be VERY hard to remove these connectors the first couple times you insert them. Make sure to pry with a screwdriver around the edges rather than pull on the wires.

Can I program and debug the UBW32 with a PICKit2?

Yes and no. You can program your UBW32 with a PICKit2 by using the stand-alone PICKit 2 v2.61 application that you can find here. However, the PICKit2 can NOT be used under MPLAB as a programmer or debugger with the PIC32 family, including the UBW32. If you want a cheap way to do real debugging, use the PICKit3, which works quite well. I did almost all UBW32 software development by using the PICKit2 and the stand-alone application, so it does work.

So then how do you debug during development if you only use a PICKit2?

Well, once I got the bootloader running, I didn't need the PICKit2 anymore. I just used the bootloader to get code onto the UBW32. And once I got USB running, I re-directed printf() to the USB serial port, and so I could just use printf() debugging in my code. This works well, but has some limitations. For more serious debugging, I used spare I/O and a logic analyzer (which works very well for ISR timing.) And if things get REALLY scary, I break out the PICKit3 from within MPLAB (and then rebuild without bootloader support) do step through code and examine variables.

How do I use a battery to supply power to the UBW32?

Well, the UBW32 is not very power efficient. The PIC32 itself can be very low power, but the UBW32 was not made with battery power in mind. Thus, you'll see a pretty large current draw just from the UBW32 itself. At 5V input (to the 5V net, or through USB) the UBW32 draws about 75mA. This is primarily because the 3.3V regulator wastes a lot of current as heat.

Anyway - you can power the UBW32 with a battery. The easiest way is to get a battery between 7.6V and 15V and connect it to either J1 or J2.

I just built one of Microchip's examples and programed it into the UBW32 with my PICKit2, but it doesn't work at ALL!!! Help!

It turns out that the Microchip example code has the config bit DEBUG set to ON. For whatever reason, when you use the PICKit2 to program the UBW32 with a HEX file that has this bit ON, your program won't run at all. There are two solutions:

  1. Leave the code alone, and use a PICKit3, ICD3 or RealIce from within MPLAB to program your UBW32. Then it will work
  2. Change it so that the line reads #pragma config DEBUG = OFF, recompile, program with PICKit2, and then it will work.

I am building my own firmware for UBW32, and I can program it using the HID Bootloader but after I reset the board, the bootloader always runs, never my firmware. What is wrong?

It my have to do with the linker script file called procdefs.ld. See the "UBW32 Linker File and HID Bootloader" section of this page.

I'm not understanding what software/firmware comes on the UBW32, and how it interacts. Could you describe it in more detail?

Sure! There are two separate applications that come on the UBW32 as it is shipped from SparkFun. They reside in separate parts of Flash. The first one is the USB HID bootloader. This application runs right when the UBW32 boots (or is reset) and it looks for the PRG button being pushed down. If the PRG button is not pushed down, then it jumps to the second application, which is the UBW32 firmware. This firmware is the code that tries to connect over USB to your PC and act as a serial port. It is the code that listens to your commands and then calls the function that set pins high or low or change their direction, etc. 

Both application's source code is available from the UBW32 website. The HID Bootloader is just the stock Microchip USB HID bootloader with a few minor modifications. The UBW32 firmware is something that I wrote for the UBW32, and it is based on the CDC demo code that comes from Microchip.

If you use the bootloader to re-program your UBW32, you will (Normally) be erasing and re-programming the firmware application (the UBW32 firmware). So if you write your own code and use the bootloader to put it on the UBW32, you've replaced the firmware that came from the factory. You can also simply modify the firmware and then re-program your UBW32 with the updated firmware.

Tell me more about the config bits. They are confusing!

It is true. They are confusing. Microchip calls them config bits, other people call them fuses. When the PIC32 first boots, it looks at a special part of Flash memory (the config bits) to set up its internal hardware. These config bits can set all sorts of things (what type of oscillator to use in order to clock the part, if the watchdog is enabled, what areas of Flash to write-protect, etc.). The way the UBW32 is set up is that the USB HID Bootloader project contains all of the definitions of the config bits - i.e. what they are set to. This bootloader is programmed at the factory. If you ever want to know how your UBW32's config bits are set, you can always look in the bootloader project. The firmware projects that I publish on the UBW32 website do NOT contain any config bit definitions. Why? Because that way it's a little harder to 'brick' your UBW32 if you're just updating the firmware using the bootloader. If the config bits were included in the UBW32 firmware projects, then it would be pretty easy to change them to a state that doesn't allow the UBW32 to boot, because they would be re-programmed every time you download new firmware using the bootloader. But since they're contained in the bootloader project file, that's the only HEX file that will contain config bits, and you should be safe. See the next question.

I think I've bricked my UBW32. How could this happen, and what do I do about it?

If you can't get your UBW32 into bootloader mode, and all you see is the blue LED lit and nothing else going on (when it's connected to a PC over USB when you reset it into bootloader mode) then you've messed up your UBW32 somehow (or if came from the factory that way - rare). You will need an ICSP programmer like the PICKit2 or PICKit3 to re-program the bootloader in order to get it working again. How could it happen? Several ways - you could have accidentally included some config bit settings in the firmware HEX file you downloaded over the bootloader that prevented USB from running on boot. Or you could have over-written the whole flash (and thus nuked the bootloader) if you didn't use the right linker script file when you built your firmware project. (See above link to UBW32 Linker File and Bootloader for more information).

Questions? E-mail me at my e-mail address

Creative Commons License
UBW32 USB Bit Whacker by Brian Schmalz is licensed under a Creative Commons Attribution 3.0 United States License.
Based on a work at
Permissions beyond the scope of this license may be available at