stm32-vserprog/README.md

130 lines
6.2 KiB
Markdown
Raw Permalink Normal View History

2015-12-26 08:42:29 +01:00
# stm32-vserprog:
2016-01-22 09:18:33 +01:00
## flashrom serprog programmer based on STM32 MCU & USB CDC protocol.
2017-05-23 08:59:51 +02:00
**This project deprecates previous [`serprog-stm32vcp`](https://github.com/dword1511/serprog-stm32vcp) project,
which uses STMicro's proprietary firmware library. Most functions are the same.**
2015-12-26 08:42:29 +01:00
* * *
### Features
2017-05-23 08:59:51 +02:00
* Fully open-source: now with [`libopencm3`](https://github.com/libopencm3/libopencm3) instead of STMicro's proprietary firmware library.
2015-12-26 08:42:29 +01:00
* Affordable and simple hardware:
2017-05-23 08:59:51 +02:00
* An _STM32F103C8T6_ MCU, an 8MHz crystal, a 3.3V _1117_ LDO, some _0805_ capacitors, resistors and LEDs
along with dedicated PCB available on OSH Park ([V2](https://oshpark.com/shared_projects/08Rj6sSm)
or [V3](https://oshpark.com/shared_projects/vKn08YZG))
* Or some general-purpose _STM32_ development boards,
just add a new header file under "boards" folder to assign correct GPIO for USB D+ pull-up (_STM32F1_ only) and LEDs.
* Hardware USB 2.0 Full-Speed and efficient virtual COM port with USB CDC protocol operates at any baud rates,
eliminates the need of USB-to-UART bridges and the headache that comes with them.
2017-05-23 09:02:08 +02:00
* **Ironically, you will still have to buy or borrow a USB-to-UART bridge (not RS-232 but TTL level) to program the programmer itself,**
2017-05-23 08:59:51 +02:00
unless you are using an _STM32F0x2_ device (which has USB ISP capability) or boards with embedded _ST-Link_ (see @FabianInostroza's fork).
2017-05-23 09:02:08 +02:00
* Hardware full-duplex SPI with DMA, multiple clock speeds available (default at the one closest to but under 10MHz), _e.g._ on STM32F103 targets:
2016-01-22 09:18:33 +01:00
* 36MHz
2015-12-26 08:42:29 +01:00
* 18MHz
2017-05-23 08:59:51 +02:00
* 9MHz *(Default)*
2015-12-26 08:42:29 +01:00
* 4.5MHz
* 2.25MHz
* 1.125MHz
* 562.5kHz
* 281.25kHz
* 2 status LEDs (controlled with 1 GPIO):
2017-05-23 08:59:51 +02:00
* Busy is lit during operation (inverse for boards with only one LED).
* Different operations cause different patterns of blinking:
mostly busy = reading, both on = writing, flashing alternatively = erasing.
* Busy blinks alone if a hard fault or NMI is detected. Please unplug and replug the programmer.
If the situation persists, please consider [opening a new ticket](https://github.com/dword1511/stm32-vserprog/issues).
* `flashrom` "serprog" protocol:
* Operates on all major platforms (see [`flashrom` wiki](http://www.flashrom.org/Flashrom)).
* Driver-free on Linux. On Windows may require ST's VCP driver
(or just hack the `.inf` file of other CDC drivers, not confirmed).
* Firmware is interrupt-free except for low-level USB handling -- robust, easy to debug and modify.
2015-12-26 08:42:29 +01:00
* Fast:
* Read speed up to 850KiB/s @ 36MHz SPI operation.
2017-05-23 08:59:51 +02:00
* Dumps an _EN25Q64_ in 11 seconds and programs in 85 seconds (including `flashrom`'s calibration time).
* Way faster than many commercial _CH341_-based USB programmers, especially for reading.
* Supports 25 and 26 series SPI flash chips.
**45 series flash chips have different pinouts. Thus for the V2 PCB mentioned above, you will need an adapter.**
2015-12-26 08:42:29 +01:00
* * *
### Installation
2017-05-23 08:59:51 +02:00
1. Install `stm32flash` and the `gcc-arm-none-eabi` toolchain.
2015-12-26 08:42:29 +01:00
On Debian, simply do the following:
```bash
sudo apt-get install stm32flash gcc-arm-none-eabi
```
2018-11-19 22:50:10 +01:00
NOTE: some systems may require installing `newlib` (_e.g._ `libnewlib-arm-none-eabi`) manually. See [#27](https://github.com/dword1511/stm32-vserprog/issues/27).
2015-12-26 08:42:29 +01:00
1. Clone and compile.
2017-05-23 08:59:51 +02:00
Simply type (change the board name accordingly, for details see the header of the `Makefile` or just type `make`):
2015-12-26 08:42:29 +01:00
```bash
git clone --recurse-submodules https://github.com/dword1511/stm32-vserprog.git
2016-01-22 09:18:33 +01:00
make BOARD=stm32-vserprog-v2
2015-12-26 08:42:29 +01:00
```
1. Program.
2017-05-23 08:59:51 +02:00
Connect the USB-to-UART bridge to your computer first. Then connect _TXD_ and _RXD_ lines to your _STM32_ board with wires.
On V2 or V3 boards mentioned above, connect _BOOT0_ (labeled _BT0_ on boards) to the 3.3V output of the USB-to-UART bridge.
For other boards, find the _BOOT0_ jumper or ISP switch, put it into high or enabled.
On some boards, you will also need to ensure _BOOT1_ is pulled low.
Then, connect your _STM32_ board to your computer via USB to power it up.
Finally, type:
2015-12-26 08:42:29 +01:00
```bash
make BOARD=stm32-vserprog-v2 flash-uart
2015-12-26 08:42:29 +01:00
```
1. Done!
2017-05-23 08:59:51 +02:00
Throw the USB-to-UART bridge away and enjoy.
Do not forget to pull _BOOT0_ low before resetting or replugging the board.
2015-12-26 08:42:29 +01:00
* * *
### Usage
2017-05-23 08:59:51 +02:00
The following assumes Linux platform, and that the programmer appears as `/dev/ttyACM0`.
2015-12-26 08:42:29 +01:00
1. To read a flash chip:
2017-05-23 08:59:51 +02:00
* Connect a 25 type SPI Flash to the board's DIP-8 slot or according to the schematics.
2015-12-26 08:42:29 +01:00
* Connect your board to your PC via USB.
* Type:
```bash
flashrom -p serprog:dev=/dev/ttyACM0:4000000 -r file-to-save.bin
```
2017-05-23 08:59:51 +02:00
* Sometimes `flashrom` will ask you to choose a chip, add something like:
2015-12-26 08:42:29 +01:00
```bash
-c SST25VF040B
```
2017-05-23 08:59:51 +02:00
This is because sometimes different devices with distinct timing requirements can only be distinguished by the device code,
however currently `flashrom` will not read it as it is not returned by the `RDID` command.
2015-12-26 08:42:29 +01:00
1. To erase a flash chip:
* Erase is automatically done during writing. However, if you simply want an empty chip, you will need to erase manually.
* Type:
```bash
flashrom -p serprog:dev=/dev/ttyACM0:4000000 -E
```
2017-05-23 08:59:51 +02:00
* For certain chips like _MX25L6445E_, the first pass could fail with some old `flashrom` version,
but if you try a second pass, everything will be alright. Seems that the first block needs more delay to be erased.
* Flash contents are verified to be empty automatically.
2015-12-26 08:42:29 +01:00
* The whole process can take a few minutes.
1. To write a flash chip:
* Type:
```bash
flashrom -p serprog:dev=/dev/ttyACM0:4000000 -w file-to-load.bin
```
* Flash chips are checked and blocks that are not empty are automatically erased.
* Images are verified after writing automatically.
* The whole process can take a few minutes.
* * *
### Problems?
2017-05-23 08:59:51 +02:00
1. If you encountered something like "`Error: Cannot open serial port: Device or resource busy`", please try to stop or remove `ModemManager`.
1. Check your wirings and `flashrom` version. Do not forget to power the flash chip itself if operating on a breadboard or prototype board.
1. If you are sure it is caused by bugs in the programmer's firmware,
please [open a new ticket](https://github.com/dword1511/stm32-vserprog/issues) and provide details,
_e.g._ the board you are using and `flashrom`'s output. I appreciate your feedback.