Quick jump:  What's new

 
Go to:
 
Weblog: STM32   
in Dobrica Pavlinušić's random unstructured stuff
Blue Pill
The-Generic-STM32F103-Pinout-Diagram.pdf



stm32f103 board

arduino boot loader

triple usb serial

pill_serial

Function Pin and Port
USART3 TX PB10
USART3 RX PB11
USART2 TX PA2
USART2 RX PA3
USART1 TX PA9
USART1 RX PA10

USART TX pin RX pin special speed sensor linux
3 PB10 PB11   9600 MH-Z19B /dev/ttyACM1
2 PA2 PA3   9600    
1 PA9 PA10 BOOT=0 9600    

dpavlin@nuc:/nuc/stm32/pill_serial$ cat flash.sh
sudo ../stlink/build/Release/st-flash write src/pill_serial.bin 0x08000000

lower serial speed to 9600 so we can use slow sensors on it: serial-speed.diff

bluepill-serial-monster

https://github.com/r2axz/bluepill-serial-monster

openocd with raspberry pi

http://git.rot13.org/?p=openocd-rpi2-stm32;a=blob;f=openocd-rpi.txt

clones

https://github.com/thanks4opensource/buck50/issues/2

https://github.com/keirf/Greaseweazle/wiki/STM32-Fakes

dpavlin@nuc:/nuc/stm32/Greaseweazle$ wget https://github.com/keirf/Greaseweazle/releases/download/v0.22/Greaseweazle-v0.22.zip

dpavlin@nuc:/nuc/stm32/Greaseweazle$ unzip Greaseweazle-v0.22.zip Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex
Archive:  Greaseweazle-v0.22.zip
  inflating: Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex

write it to flash using openocd

> flash write_image erase /nuc/stm32/Greaseweazle/Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex 0 ihex
auto erase enabled
wrote 5120 bytes from file /nuc/stm32/Greaseweazle/Greaseweazle-v0.22/alt/Blinky_Test-v0.22.hex in 0.299529s (16.693 KiB/s)

serial output is on the programming interface at pins A9/TX and A10/RX: Not via the USB port!

pi@pihdmi:/nuc/stm32/buck50 $ microcom -p /dev/ttyUSB1
connected to /dev/ttyUSB1
Escape character: Ctrl-\
Type the escape character to get to the prompt.

** Blinky
** Blinky Test **
** Keir Fraser <keir.xen@gmail.com>
** https://github.com/keirf/Greaseweazle
Serial = ff48:0670:8967:5655:4740:6706
Flash Size  = 128kB
Device ID = 0x0000
Revision  = 0x0000
Testing I2C1... OK
Testing I2C2... OK
Testing SPI1... OK
Testing SPI2... OK
Testing TIM1... OK
Testing TIM2... OK
Testing TIM3... OK
Testing TIM4... OK
DMA Test #1... OK
DMA Test #2... OK
DMA Test #3... OK
DMA Test #4... OK
Testing 64kB Flash... OK
Enable TIM4 IRQ... .OK
Testing 20kB SRAM (endless loop)................................................................

After flashing this test, you will not be able to address blue pill using openocd.

To work-around this problem, I switched boot0 jumper, used stm32loader (after pressing reset button) to load alternative binary.

permalink
Maple r5

https://github.com/leaflabs/maple/blob/master/maple-r5/maple-r5-schematic.pdf



specification

STM32 F103RB: a 32-bit ARM Cortex M3 microprocessor
Clock Speed: 72 MHz
Operating Voltage: 3.3V
Input Voltage (recommended): 3.0V-12V
39 Digital I/O Pins (GPIO)
16 Analog Input Pins
12-bit ADC resolution (ADC)
15 PWM pins at 16-bit resolution (PWM)
Dedicated USB port for programming and communications (USB)
External JTAG interface (USB)
128 Flash and 20KB SRAM
64 Channel nested vector interrupt handler (including external interrupt on GPIO’s)
Integrated SPI (SPI)
Integrated I2C (I2C)
7 Channels of Direct Memory Access (DMA)
3 USART devices
Four 4-channel Timers (Timers)
Supplies up to 500mA @ 3.3v
Support for low power and sleep modes (<500uA)

serial flash

Press boot 0, press reset, release reset, release boot 0

dpavlin@nuc:/nuc/stm32$ git clone https://github.com/jsnyder/stm32loader

dpavlin@nuc:/nuc/stm32/stm32loader$ ./stm32loader.py -p /dev/ttyUSB0 
Bootloader version 22
Chip id: 0x410 (STM32 Medium-density)

dpavlin@nuc:/nuc/stm32/stm32loader$ ./stm32loader.py -p /dev/ttyUSB0 -e -w -v maple_rev5_boot20.bin
Bootloader version 22
Chip id: 0x410 (STM32 Medium-density)
Write 256 bytes at 0x8000000
Write 256 bytes at 0x8000100
...

maple boot loader

dpavlin@nuc:/nuc/stm32/stm32loader$ wget http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-bootloader/maple_boot.bin

dpavlin@nuc:/nuc/stm32/stm32loader$ ./stm32loader.py -p /dev/ttyUSB0 -e -w -v maple_boot.bin


STM32 Arduino upgrade

bootloader


dpavlin@nuc:/nuc/stm32/stm32loader$ wget https://github.com/rogerclarkmelbourne/STM32duino-bootloader/raw/master/STM32F1/binaries/maple_rev5_boot20.bin


maple r5 is not reported with dfu-util

https://github.com/rogerclarkmelbourne/STM32duino-bootloader/pull/20

build

dpavlin@nuc:/nuc/stm32/STM32duino-bootloader$ make maple-rev5

...

Copying to binaries folder

cp build/maple_boot.bin bootloader_only_binaries/maple_rev5_boot20.bin

permalink
FST-01

update vid and pid in compiled binary

since version 1.2.8 you need to insert vid and pid into the binary by running

make build/gnuk-vidpid.elf

and than flash the resulting gnuk-vidpid.bin binary into your FST-01

SWD flashing using ST Link v2

usb 1-1.6.4: new full-speed USB device number 16 using ehci-pci
usb 1-1.6.4: New USB device found, idVendor=0483, idProduct=3748
usb 1-1.6.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.6.4: Product: STM32 STLink
usb 1-1.6.4: Manufacturer: STMicroelectronics
usb 1-1.6.4: SerialNumber: Qÿl^FH<85>PH'Q^C<87>

Problem:

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk/tool$ ./stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -> 0001
CORE: 0de01477, CHIP_ID: 00000000
Flash ROM read protection: off
Option bytes: 00000000
Core does not halt, try API V2 halt.
ValueError('Status of core is not halt.', 128)

after several re-runs:

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk/tool$ ./stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -> 0001
CORE: 1ba01477, CHIP_ID: a0036410
Flash ROM read protection: off
Option bytes: a0036410
Core does not halt, try API V2 halt.
ValueError('Status of core is not halt.', 128)

after a bit of fiddling with cables (it's always cables, right?)

Lovro contributed that if you are getting continous output like this

ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -> 0001
Core does not halt, try API V2 halt.
ValueError('Status of core is not halt.', 128)

then run this while holding reset active (hold tweezers on both side of C3)
that should hand the uC in a mode that will enable stlinkv2.py script to turn off the flash rom protection and erase the flash while doing that

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -> 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: ON
Option bytes: 03fffffe
The MCU is now stopped.
SUCCESS

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -u
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0002 -> 0001
Status is 0081
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: ON
Option bytes: 03fffffe
Flash ROM read protection disabled.  Reset the board, now.
SUCCESS

# plugin, plugout st-link/v2

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0100 -> 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: off
Option bytes: ffff5aa5
Flash ROM blank check: True
SUCCESS

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -b ../binaries/gnuk/gnuk.bin 
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0001 -> 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: off
Option bytes: ffff5aa5
Flash ROM blank check: True
SPI Flash ROM ID: bf254a
WRITE
VERIFY
PROTECT
Flash ROM read protection enabled.  Reset the board to enable protection.
SUCCESS

# power cycle

dpavlin@blue:/blue-zfs/STM32/FST-01/gnuk$ sudo ./tool/stlinkv2.py -s
ST-Link/V2 version info: 2 17 4
Change ST-Link/V2 mode 0100 -> 0001
CORE: 1ba01477, CHIP_ID: 20036410
Flash ROM read protection: ON
Option bytes: 03fffffe
The MCU is now stopped.
SUCCESS

plugin just FST-01:

[ 9890.019368] usb 1-1.6.4: New USB device found, idVendor=234b, idProduct=0000
[ 9890.019372] usb 1-1.6.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9890.019374] usb 1-1.6.4: Product: Gnuk Token
[ 9890.019375] usb 1-1.6.4: Manufacturer: Free Software Initiative of Japan
[ 9890.019377] usb 1-1.6.4: SerialNumber: FSIJ-1.0.4-50FF7006
permalink
Black Magic Probe
Bluepillpinout.gif



Black Magic Probe

https://github.com/blacksphere/blackmagic

links

blue pill

http://wiki.stm32duino.com/index.php?title=Blue_Pill

dpavlin@klin:/rest/cvs/blackmagic/src$ make PROBE_HOST=stli

  LD      blackmagic
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: address 0x8010dd0 of blackmagic section `.text' is not within region `rom'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: blackmagic section `.data' will not fit in region `rom'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: address 0x8010dd0 of blackmagic section `.text' is not within region `rom'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: region `rom' overflowed by 3768 bytes
collect2: error: ld returned 1 exit status
Makefile:66: recipe for target 'blackmagic' failed
make: *** [blackmagic] Error 1

git remote add mubes https://github.com/mubes/blackmagic
git fetch mubes
git checkout -b bluepill mubes/bluepill

make clean

# gcc 5 generates too big binaries!
export PATH=/opt/DesignLab-1.0.8/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/:$PATH

make PROBE_HOST=bluepill

/nuc/stm32/stlink/build/Release/st-flash erase

/nuc/stm32/stlink/build/Release/st-flash write blackmagic_dfu.bin 0x8000000

/nuc/stm32/stlink/build/Release/st-flash write blackmagic.bin 0x8002000

# power cycle blue pill

dpavlin@nuc:/nuc/stm32/blackmagic/src$ dmesg | tail -8 | cut -c18-
usb 2-4.4: new full-speed USB device number 12 using xhci_hcd
usb 2-4.4: New USB device found, idVendor=1d50, idProduct=6018
usb 2-4.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-4.4: Product: Black Magic Probe (Bluepill), (Firmware v1.6-rc0-274-g39197b7)
usb 2-4.4: Manufacturer: Black Sphere Technologies
usb 2-4.4: SerialNumber: BED69CDC
cdc_acm 2-4.4:1.0: ttyACM0: USB ACM device
cdc_acm 2-4.4:1.2: ttyACM1: USB ACM device



st-link

https://github.com/texane/stlink


dpavlin@nuc:/nuc/stm32$ git clone https://github.com/texane/stlink

dpavlin@nuc:/nuc/stm32/stlink$ ./build/Release/st-info --probe
Found 1 stlink programmers
 serial: 533f6a06483f55532144033f
openocd: "\x53\x3f\x6a\x06\x48\x3f\x55\x53\x21\x44\x03\x3f"
  flash: 65536 (pagesize: 1024)
   sram: 20480
 chipid: 0x0410
  descr: F1 Medium-density device
dpavlin@nuc:/nuc/stm32/stlink$ 


dpavlin@nuc:/nuc/stm32/stlink$ ./build/Release/st-flash erase
st-flash 1.3.1-14-geb03b7c
2017-04-07T17:37:27 INFO src/common.c: Loading device parameters....
2017-04-07T17:37:27 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2017-04-07T17:37:27 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
Mass erasing


dpavlin@nuc:/nuc/stm32/blackmagic/src$ make HOST_PROBE=stlink

dpavlin@nuc:/nuc/stm32/blackmagic/src$ ../../stlink/build/Release/st-flash write blackmagic_dfu.bin 0x8000000
st-flash 1.3.1-14-geb03b7c
2017-04-07T17:41:59 INFO src/common.c: Loading device parameters....
2017-04-07T17:41:59 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2017-04-07T17:41:59 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2017-04-07T17:41:59 INFO src/common.c: Attempting to write 6780 (0x1a7c) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08001800 erased
2017-04-07T17:41:59 INFO src/common.c: Finished erasing 7 pages of 1024 (0x400) bytes
2017-04-07T17:41:59 INFO src/common.c: Starting Flash write for VL/F0/F3 core id
2017-04-07T17:41:59 INFO src/flash_loader.c: Successfully loaded flash loader in sram
  6/6 pages written
2017-04-07T17:41:59 INFO src/common.c: Starting verification of write complete
2017-04-07T17:41:59 INFO src/common.c: Flash written and verified! jolly good!



dpavlin@nuc:/nuc/stm32/blackmagic/src$ ../../stlink/build/Release/st-flash --reset --flash=128k write blackmagic.bin 0x8002000
st-flash 1.3.1-14-geb03b7c
2017-04-07T17:45:52 INFO src/common.c: Loading device parameters....
2017-04-07T17:45:52 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2017-04-07T17:45:52 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
Forcing flash size: --flash=0x00020000
2017-04-07T17:45:52 INFO src/common.c: Attempting to write 77076 (0x12d14) bytes to stm32 address: 134225920 (0x8002000)
Flash page at addr: 0x08014c00 erased
2017-04-07T17:45:54 INFO src/common.c: Finished erasing 76 pages of 1024 (0x400) bytes
2017-04-07T17:45:54 INFO src/common.c: Starting Flash write for VL/F0/F3 core id
2017-04-07T17:45:54 INFO src/flash_loader.c: Successfully loaded flash loader in sram
 75/75 pages written
2017-04-07T17:45:58 INFO src/common.c: Starting verification of write complete
2017-04-07T17:45:59 INFO src/common.c: Flash written and verified! jolly good!


this flash instructions doesn't work, recepie above for blue pill is more recent

permalink
STM32discovery


STM32F100RBT6B

dpavlin@blue:~$ lsusb | grep ST
Bus 003 Device 006: ID 0483:3744 SGS Thomson Microelectronics STLINK Pseudo disk

Install toolchain

dpkg --add-architecture i386
apt-get install libc6-i386
#wget https://launchpad.net/gcc-arm-embedded/4.7/4.7-2012-q4-major/+download/gcc-arm-none-eabi-4_7-2012q4-20121208-linux.tar.bz2
wget https://sourcery.mentor.com/GNUToolchain/package4463/public/arm-none-eabi/arm-2009q1-161-arm-none-eabi-i686-pc-linux-gnu.tar.bz2


Install openocd

dpavlin@blue:~$ sudo apt-get install openocd
dpavlin@blue:~$ dpkg -l openocd
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                    Version          Architecture     Description
+++-=======================-================-================-====================================================
ii  openocd                 0.6.1-1          amd64            Open on-chip JTAG debug solution for ARM and MIPS sy

start openocd

Disable STLINKv1 SCSI emulation, see https://github.com/texane/stlink

root@blue:~# modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:i

root@blue:~# sudo openocd -f /usr/share/openocd/scripts/board/stm32vldiscovery.cfg
Open On-Chip Debugger 0.6.1 (2012-12-05-01:32)
Licensed under GNU GPL v2
For bug reports, read
       http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

Open another window and connect with telnet:

dpavlin@blue:~$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset init
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000b4c msp: 0x20000400

summon toolchain

openocd

dpavlin@blue:~/sat$ sudo openocd -f /usr/share/openocd/scripts/board/stm32vldiscovery.cfg
[sudo] password for dpavlin: 
Open On-Chip Debugger 0.6.1 (2012-12-05-01:32)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'telnet' connection from 4444
Warn : target was in unknown state when halt was requested
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x080001ce msp: 0x20001ff0

From different terminal

dpavlin@blue:~/sat$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
target was in unknown state when halt was requested
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x080001ce msp: 0x20001ff0
> 

> flash write_image erase /virtual/stm32discovery/libopencm3/examples/stm32/f1/stm32vl-discovery/fancyblink/fancyblink.hex
auto erase enabled
device id = 0x10016420
flash size = 128kbytes
target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20001ff0
wrote 2048 bytes from file /virtual/stm32discovery/libopencm3/examples/stm32/f1/stm32vl-discovery/fancyblink/fancyblink.hex in 0.192207s (10.405 KiB/s)


Using Arduino IDE

http://forums.leaflabs.com/topic.php?id=630

permalink
Weblog Navigation
Loading...
Weblog Archives
  • Loading...