Friday, May 11, 2012

Howto flash a DSO Nano v2 bootloader (STM32)

DSO Nano is a single channel scope/signal generator. I got mine from seeedstudio.com for just $89. The problem was, I fried signal generator and as it turned out also MCU by accidentally touching +12V rail. I bought a new MCU, soldered it to the board instead of the fried one and wondered how to flash firmware into it. So after a few days I came up with the following.


But before I begin, here're just a few handy links:
Latest firmware: http://code.google.com/p/dsonano/
DSO v2 schematics: http://code.google.com/p/dsonano/downlo ... Scheme.pdf
STM32F103VBT6 Reference Manual: http://www.st.com/internet/com/TECHNICA ... 171190.pdf
STM32F103VBT6 Data Sheet: http://www.st.com/internet/com/TECHNICA ... 161566.pdf
Very similar task solved (Programming RedBoot): http://www.ecoscentric.com/ecospro/doc/ ... setup.html
Original DSO Nano V2 bootloader: http://www.seeedstudio.com/forum/viewtopic.php?p=9310#p9310

STM32F103VBT6 has different boot options, selected by pins BOOT0 and BOOT1:
Table 9. Boot modes
Boot mode selection pins Boot mode
Aliasing
BOOT1 BOOT0
x 0 Main Flash memory Main Flash memory is selected as boot space
0 1 System memory System memory is selected as boot space
1 1 Embedded SRAM Embedded SRAM is selected as boot space

If you look at the schematics you'll see that BOOT1 (also PB2) is hardware-tied to ground, so only two first options are available. There's BT0 pin broken out on the CN4 pin header. If you leave it floating (pulled down) it will jump to address 0x8000000, if you pull it to VDD, it will jump to built-in bootloader, available on USART1 (more on bootloader in section 3.4 of reference manual). The firmware itself consist of (another!) bootloader and application. The DSO (not MCU!) bootloader sits in the memory starting from address 0x8000000. The application sits in the memory starting from address ().
When you plug in the power, MCU first checks the BOOT pins and if BOOT0 is pulled up it takes you to the MCU bootloader (more on that later). Otherwise it runs to DSO bootloader that in its turn checks if DOWN key is pressed. If no -> jump to application. If yes -> go to DFU mode.
Now, we want to replace DSO bootloader. To do so, we simply need to pull BOOT0 pin up (short with a piece of wire BT0 and 3V on CN4) and feed the DSO bootloader to the MCU bootloader that is patiently waiting for bytes to come in through USART1 (also broken out in the PCB).
Now, to the step-by-step.
1. Connect BT0 (at CN4) to 3V (e.g. at CN4)
2. Connect USB-UART (TTL at 3,3V, pins GND, TX, RX) to CN5. I did not connect VDD and used 5 volts converter, but you'd better check in the datasheet that both pins are 5 volts tolerant (marked as FT)
3. (May be the hardest part) Download the Flash Loader Demonstrator from the ST website and install it on a PC running Windows
4. Start the Flash Loader Demonstrator and in the first screen select the COM port connected to the board under Port Name. Ensure that the baud rate is also set at 115200, with Even parity, Echo disabled and Flow control off. Press Next. If you are succesfully connected to the board, you should see the message "Target is readable" and "Flash Size 128 KB". Please click "Next" to proceed . Press Next and you will be prompted to select a target. Select STM32_Med-density_128K, then Next to go to the Operation choice page.
5. By now you should have downloaded the bootloader *.bin file and know it's location. Select "Download to device", browse for dsonano2-loader.bin, and choose "Global Erase" option. "@ (h)" field should automatically set to 8000000. If all is OK, hit Next and you should witness the bootloader being flashed to the MSU.
6. If all is done OK, you'll see the message "Download operation finished successfully" on a green line
7. Now plug off the power, take all the wires off the DSO and plug it back. You'll see "Firmware upgrading" message on the DSO screen. The device is in DFU mode. Now just follow the regular application update procedure.

Btw, you can also flash application and hw files the same way - just check that they go to the right address and you don't choose "Global Erase" each time.

That's about it I guess...
Post a Comment