Bluepill Diagnostics V1.6 User Guide¶
Abstract¶
The very popular Blue Pill Board has suffered at the hands of unscrupulous factories which supply cheaper Chinese clones instead of the original STM32F103C8T6 microprocessor. The replacement microprocessor usually has the (ARM licensed) original Chinese FAB markings removed and fraudulently replaced with the STMicro part number and logo.
Bluepill Diagnostics attempts to discover the make and model of microprocessor installed in a Blue Pill Board, regardless of chip model number markings.
It does this via a simple user menu accessed via a USB serial terminal running on any PC and OS.
The Bluepill Diags was also featured on Hackaday in June 2021.
Download Url¶
https://sourceforge.net/projects/mecrisp-stellaris-folkdoc/files/bluepill-diagnostics-v1.6.zip
Testing Methodology¶
Four tests determine if a MCU is a genuine STM32F103C8.
A silicon bug in genuine STM32F1xx chips is exploited, namely the BGMCU_IDCODE cannot be read from within the MCU without a SWD or JTAG interface connected.
Verify the Flash Size Register = 64KB
Verify that the MCU has a hidden second 64KB flash block. Most STM32F103C8 chips have this.
Verify that the MCU Jdec manufacturer ID is STMicroelectronics.
Results¶
Based on the results of these tests, Blue Pill Diagnostics will announce whether the MCU appears to be a genuine STM32F103C8T6 or not.
Usage Guide¶
Download https://sourceforge.net/projects/mecrisp-stellaris-folkdoc/files/bluepill-diagnostics-v1.6.zip
Flash the bluepill-diagnostics-v1.6xx.bin inside the above zipfile to your Bluepill/Maple board, see FLASHING below.
Plug in a USB cable to the “Blue Pill” board and run a serial terminal program on your PC. This will also power the board.
Connect the serial terminal program to the “Mecrisp STM32F10x Forth Serial Port” USB device now created on your PC. Any speed is ok as the system will run as fast as possible anyway, I use 460800 Baud myself.
Press the “m” key on your keyboard to bring up the bluepill-diagnostics user menu.
MCU Information¶
128KB Flash¶
Genuine STM32F103C8T6 microprocessors almost always contain a extra HIDDEN 64KB of flash. No one knows why this is and many theories abound, but Menu Item [h] comprehensively writes and reads every location of this hidden second 64KB flash block and will print any failed memory locations.
My MCU passed all the tests can the full 128KB flash be used ?
Forth¶
Yes, Forth can use all the flash, see “Forth User Guide” below. In fact Forth has to be able to reach the hidden second 64KB flash block to test it in the Bluepill Diagnostics.
Non Forth Programs like C¶
Only if you tell your flashing program explicitly, because the job of the Flash Size Register is to tell all programs how much flash the chip has and the STM32F103C8T6 says I only have 64KB flash!. Even if it has the hidden extra 64KB flash as well.
ST-Link¶
My version v1.5.0 reports only 64KB flash and ignores the hidden second block. 0x10000 is 64KB.
% st-info --flash
0x10000
However the full 128KB can be flashed with:
st-flash erase --flash=128k
st-flash --flash=128k write random.bin 0x08000000
OpenOCD¶
OpenOCD needs a special config file ‘stm32f103c8-128kb.cfg’ which is included in the OpenOcd subdirectory in this release. This tells OpenOCD that the chip has 128KB flash.
The command for doing so with a olimex-arm-usb-tiny USB to JTAG dongle is:
openocd -f /usr/local/share/openocd/scripts/interface/ftdi/olimex-arm-usb-tiny-h.cfg \
-f ./stm32f103c8-128kb.cfg \
-c " program ./<your binary> verify reset exit 0x08000000"
If you don’t use this cfg file OpenOCD will interrogate the flash size register declaration at 0x1FFFF7E0 (read with Menu item [f]) and refuse to flash the extra 64KB of flash.
Bluepill MCU Candidates¶
The STM32F103C8T6 should be the MCU fitted in the Bluepill Board.
Device |
DEV-ID |
RevID |
Flash (KB) |
2nd 64KB Hidden ? |
Ram (KB) |
Manufacturer |
SWD? |
Notes |
---|---|---|---|---|---|---|---|---|
CH32F103C8T6 |
0x410 |
0x2000 |
64 |
n/a |
20 |
WCH |
? |
2x USB |
STM32F103C8T6 |
0x410 |
0x2003 |
2x 64 |
YES |
20 |
STMicroelectronics |
Y |
|
STM32F103RBT6 |
0x410 |
0x2003 |
128 |
NO |
20 |
STMicroelectronics |
Y |
|
CKS32F103C8T6 |
0x410 |
0x2003 |
64 |
NO |
20 |
China Key System |
N |
Fails H test |
CKS32F103CBT6 |
0x410 |
0x2003 |
128 |
NO |
20 |
China Key System |
N |
|
APM32F103CBT6 |
0x410 |
0x2003 |
128 |
NO |
20 |
Geehy |
N |
48MHz USB, FPU |
APM32F103xC |
? |
? |
256 |
NO |
64 |
Geehy |
? |
|
GD32F130C8 |
0x410 |
0x1303 |
64 |
n/a |
8 |
Gigadevice |
? |
|
GD32F150C8 |
0x410 |
0x1303 |
64 |
n/a |
8 |
Gigadevice |
? |
|
STM32F103VET6 |
0x414 |
0x1001 |
512 |
n/a 512kb |
64 |
STMicroelectronics |
Y |
|
GD32F103VE |
0x414 |
0x1309 |
512 |
n/a 512kb |
64 |
Gigadevice |
? |
|
GD32F103VK |
0x430 |
0x1309 |
3072 |
n/a 3MB |
96 |
Gigadevice |
? |
|
GD32F103C8T6 |
0x436 ? |
0x1038 ? |
? |
? |
? |
Gigadevice |
? |
SWD? Does this MCU require an active SWD connection before the DBGMCU_IDCODE can be read INTERNALLY (Using my Diagnostics Binary) ?
Manufacturer JDEC Codes¶
Manufacturer |
Chip Example |
identity (hex) |
continuation (hex) |
---|---|---|---|
STMicro |
STM32F103C8 |
20 |
00 |
GigaDevice Semiconductor |
GD32F103C8 |
C8 |
07 |
GigaDevice Semiconductor (Beijing) |
GD32F103C8 |
51 |
07 |
HK32 |
HK32F103CBT6 |
55 |
05 |
CS32 |
CS32F103C8T6 |
3B |
04 |
APM32 |
APM32F103C8T6 |
3B |
04 |
WCH |
CH32F103C8T6 |
3B |
04 |
MCU DBGMCU_IDCODE¶
The DBGMCU_IDCODE, CPU-ID and RevID values in this table may help you determine the actual MCU in your Blue Pill. If St-link or OpenOCD don’t work, try using the serial bootloader or even DFU via the Blue Pill USB connector to flash my V 1.6 Diags binary to your MCU.
DBGMCU_IDCODE is at 0xE0042000
Bits 11:0 DEV_ID: Device identifier
Bits 15:12 Reserved
Bits 31:16 REV_ID: Revision identifier
|3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|
|-----------REV_ID--------------|rsrvd|---------DEV_ID----------|
Changelog¶
V1.640¶
Features the latest Mecrisp-Stellaris-2.6.2 kernel, New PDF Userguide, bugfixes, more tech doc and the full Forth source (as usual). A workaround for a “42 init” bug was implemented while the cause is being investigated.
Contents¶
COPYING
bluepill-diagnostics-user-guide.pdf
bluepill-diagnostics-v1.640.bin
bluepill-diagnostics-v1.640.source.fs
openocd
stm32f103c8-128kb.cfg
V1.631¶
V1.631 was a major rewrite when I realised that attempting to collect and analyse the Device electronic signature is pointless as the same codes are used by genuine and clone MCU’s alike.
Mecrisp-Stellaris-2.5.5 kernel.
“42 init” bug discovered.
V1.0¶
V1.0 was released in November 2019 and it took two years to collate and study user clone/fake information because not a lot was known about these chips (in the West) which are usually relabelled Chinese (licensed) ARM Cortex-M clones.
History¶
My Blue Pill Diagnostics project grew from an interest to create a self contained binary that would boot on a Blue Pill board and access internal MCU information to determine the model of MCU.
This interest was kindled by various articles from Blue Pill owners who owned a BluePill that didn’t work properly and needed help. They had no way to tell what MCU was in their board and buying one was a real lottery in the Wild West Chinese and eBAY marketplaces.
I now consider this project complete as of 14 April 2021 at version V1.631 excepting bugfixes and improvements/updates.
Clones¶
Even if the MCU is not a genuine STM32F103C8 this doesn’t mean your Bluepill board is junk, it may work perfectly, it may even be BETTER. Many clones have fixed the silicon bugs in the original, some are FASTER with a 104 v/s 72 MHz maximum clock.
Even if the clone MCU USB doesn’t work at first, it may only need a clock change as is the case with some APM units which are a lot faster than the original MCU.
In August 2020, with the continuing chip shortage, many are looking at the wide range of Chinese clones and actively seeking them out. Sellers such as lcsc.com have a wide range in stock, and as they are the parts arm of jlcpcb.com, they can even solder them to your new PCB for you.
https://lcsc.com/search?q=gd32f103¶
note¶
I have no association with either LCSC or JLCPCB and receive no payment or free product from them.
LATEST NEWS¶
August 2022¶
I have received a Bluepill Diags report of a MCU which appears to counterfit the JDEC ID of STMicro. It’s still a mystery as to what the chip is and I’m working on some tests for it at the moment. Yes, the owner definitely removed the SWD/JTAG flashing gear and reset the chip before running the Diags.
Chip Marking¶
STM32
F103C8T6
991KA 93
MYS 808
Diags Report¶
STM32F103C8 authentication FAILED one or more tests:
----------------------------------------------------
FAIL - Declared flash not 65536
FAIL - DBGMCU_IDCODE is readable with no SWD/Jtag connected
PASS - Second 64KB flash block verified
PASS - JDEC manufacturer id IS STMicroelectronics
131072 flash is declared in the Flash size register at 0x1FFFF7E0
DBGMCU_IDCODE [@ 0xE0042000] = 0x20036410
Jdec Continuation Code: 0x00
Jdec Identity Code: 0x20
JDEC manufacturer id: STMicroelectronics
UNIQUE DEVICE ID:
-----------------
BITS-95:64 | 0x41373936 | A796
BITS-63:32 | 0x31303904 | 109.
BITS-31:0 | 0x001D001E | ....
Unique Serial Number = 0x701A002C
Flashing¶
There are two methods commonly used:
SWD
Serial Bootloader
Note
DFU is not available on the USB of a STM32F103
See also
More general Cortex-M flashing information not Bluepill specific.
SWD¶
Uses a USB/SWD interface dongle (stlink v2 clone) that connects between your PC USB port and the four header pins on the end of the Bluepill. These are cheap and everywhere for $5 to $10 ea. Advanced users can make a ST-LINK-V2 from a Bluepill. They have also been made using RPI’s and PICO’s.
Connecting the ST-LINK V2 to the Blue Pill
ST-LINK V2 |
Blue Pill 4 pin header |
---|---|
PIN 2 SWCLK |
SWCLK |
PIN 4 SWDIO |
SWDIO |
PIN 6 GND |
GND |
PIN 8 3.3V |
3.3V |
Software: This depends on your OS.
Linux/Unix : ST-link or Openocd. Both will be in the package manager repositories.
Install Stlink
Connect your USB/SWD interface dongle to your PC using a usb cable, a led should light.
Note: Root or sudo will be required for the erase and write steps below
Erase the flash on the board by running
st-flash erase It's advised to press the reset button on the board before the next step.
Now flash the board
st-flash write bluepill-diagnostics-v1.6xx.bin 0x08000000
Serial Bootloader¶
Instructions are for Unix.
Hook up a 3.3v USB Serial Dongle to the USART 1 (only USART-1 supports the serial bootloader on a STM32F103xx (PA9-TX, PA10-RX). You can usually power the board from the dongle.
Set the boot pin jumpers. Boot 0 to HIGH or 1. BOOT 1 will stay LOW or 0.
Boot Pin Functions¶
Pins BOOT0 & BOOT1 select how the BluePill starts |
||
---|---|---|
BOOT 1 |
BOOT 0 |
Boot mode |
X |
0 |
User Flash memory (application) |
0 |
1 |
Serial Bootloader |
1 |
1 |
Embedded SRAM |
Run something like this command
python ./stm32loader.py -p /dev/cuaU0 -evw bluepill-diagnostics-v1.6xx.bin
Set both boot pins to LOW, reset the power to the target
Fire up your serial terminal and you should see the bluepill-diagnostics-v1.6 User menu.
A Unix friendly Bootloader: stm32loader.py¶
Author: Ivan A-R <ivan@tuxotronic.org>
With hacky error recovery by Gordon Williams <gw@pur3.co.uk>
Project page: http://tuxotronic.org/wiki/projects/stm32loader
The version here
stm32loader.py
was kindly cleaned up by McKinnon Ryall vatrat.dev@gmail.com.
# python ./stm32loader.py -h
Usage: ./stm32loader.py [-hqVewvrX] [-l length] [-p port] [-b baud] [-a addr] [file.bin]
-h This help
-q Quiet
-V Verbose
-e Erase
-w Write
-v Verify
-X Reset after
-r Read
-l length Length of read
-p port Serial port (default: first USB-like port in /dev)
-b baud Baud speed (default: 115200)
-a addr Target address
-s n Skip writing N bytes from beginning of the binary (does not affect start address)
-k Change PCLK frequency to make USB stable on Espruino 1v43 bootloaders
stm32loader.py -p /dev/cuaU16 -evw bluepill-diagnostics-v1.6xx.bin
Forth User Guide¶
Blue Pill Diagnostics V1.640 is also a self contained Forth Programming Development Environment with many tools such as peripheral register real time printing, memory dumping, a ARM Cortex-M Thumb disassembler and hundreds more. In fact this release of the Bluepill Diagnostics has 777 programs pre-installed for you to use.
What Makes Forth Special ?¶
Forth is interactive and allows me to examine/change memory in real time and observe the effects instantly as there is no edit, compile, flash, test cycle such as you have with the C programming language. Because Mecrisp-Stellaris Forth is only 20KB in size, it easily fits in the limited 64KB flash advertised by the Cortex-M3 STM32F103C8 MCU.
How To Access The Forth Terminal ?¶
The Forth terminal console may be accessed by quitting the Diagnostics Menu [q]. This will expose the Forth prompt.
No Need to Flash Anymore!¶
You can write a program and add it to the list of programs (Dictionary) in ram or flash on the microprocessor without leaving the serial terminal. You can also erase the programs yous add in exactly the same way.
A Complete IDE on the Bluepill¶
Interactive programs may be typed at the terminal or written on your favorite editor then uploaded to the Bluepill via your serial terminal, to ram or flash.
The Binary is only 60,704 Bytes¶
Several hundred programs which Forthers call Words are available while still keeping the binary size under 64KB so the Bluepill Diagnostics can be flashed using unmodified st-link or OpenOcd etc.
This leaves 65535 - 60704 = 4831 bytes in the lower 64KB flash block for your programs, plus the whole 64KB hidden flash block!
That’s 65535 + 4831 = 70366 bytes free for your user programs, more than the entire Bluepill Diags uses.
This can be found the easy way by running “free”. Ok, my calculation is six bytes out, I hope you won’t hold it against me :)
free
Memory stats in bytes:
Flash Total:131072 Used:60700 Free:70372
Ram Total:20480 Used:1920 Free:1856
Forth Information¶
Mecrisp-Stellaris: https://mecrisp-stellaris-folkdoc.sourceforge.io/index.html
Kernel Options¶
This kernel has the following options enabled: 1,2,3,4,5,7,8
Kernel Options |
Description |
---|---|
1 |
context sensitive color prompt |
2 |
all errors in red and beep terminal bell. Enter “;” at the terminal to test them. |
3 |
“redefine” warning in orange |
4 |
Halts source file uploads on (or about) the first error, all errors in red and sound bell. Swdcom uploads are too fast to see! |
5 |
Simplified stack print. “.s Stack: [0 ] 42 ok.” |
6 |
Swdcom instead of usart user terminal |
7 |
catchflashpointers.s/bl uart_init transposition. Essential for swdcom to work properly. |
8 |
add ‘carriage return’ to ‘newline’ for Windows to prevent ‘stair stepping’ |
Peripheral Pretty Print Words¶
This release can print the current real-time values of the following peripherals along with all their sub registers. Just enter one of the Words listed below (don’t forget the trailing period “.”).
RCC.
GPIOA.
GPIOB.
GPIOC.
EXTI.
TIM2.
I2C1.
SPI1.
ADC1.
DBG.
NVIC.
Complete Peripheral Print¶
gpioa.
gpioa_crl. RW $44444448
3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0
0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0
gpioa_crh. RW $88864444
3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0
1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0
gpioa_idr. RO $0000FFFD
3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
gpioa_odr. RW $0000B000
3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
$40010810 write-only
$40010814 write-only
gpioa_lckr. RW $00000000
3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Single Register Print¶
Or you can print the individual registers, such as “gpioa_odr.”.
gpioa_odr.
gpioa_odr. RW $0000B000
3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|
1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
Tips¶
Add the register print command to your development words when debugging peripherals.
Dictionary¶
These are inbuilt user programs.
i.e. ‘2+’ is a program that adds 2. Forth uses the RPN mathmatical system.
2 2+ . 4 ok.
Word Listing¶
Many of these default programs (Words), at least the ones listed before “— Flash Dictionary —” are elaborated here in detail. The Words listed after “— Flash Dictionary –” are those used in the BluePill Diags and their full source (bluepill-diagnostics-v1.640.source.fs) is in the release.
2dup 2drop 2swap 2nip
2over 2tuck 2rot 2-rot
2>r 2r> 2r@ 2rdrop
d2/ d2* dshr dshl
dabs dnegate d- d+
s>d um* m* ud*
udm* */ */mod u*/
u*/mod um/mod m/mod ud/mod
d/mod d/ f* f/
2! 2@ du< du>
d< d> d0< d0=
d<> d= sp@ sp!
rp@ rp! dup drop
?dup swap nip over
tuck rot -rot pick
depth rdepth >r r>
r@ rdrop rpick roll
-roll and bic or
xor * clz ror
rol arshift rshift lshift
0= 0<> 0< true
false >= <= <
> u>= u<= u<
u> <> = min
max umax umin move
fill @ ! +!
h@ h! h+! c@
c! c+! bis! bic!
xor! bit@ hbis! hbic!
hxor! hbit@ cbis! cbic!
cxor! cbit@ hflash! flashpageerase
eraseflash eraseflashfrom + -
1- 1+ 2- 2+
cell+ negate not shr
shl 2* cells 2/
abs u/mod /mod mod
/ even base binary
decimal hex swd swd-init
swd-key? swd-emit? swd-key swd-emit
hook-emit hook-key hook-emit? hook-key?
hook-pause emit key emit?
key? pause cexpect accept
tib >in current-source setsource
source query compare cr
bl space spaces [char]
char ( \ ."
c" s" count ctype
type hex. h.s u.s
.s words unused 12bitencoding
registerliteral, movwmovt, call, literal,
create does> <builds [']
' postpone inline, ret,
exit recurse state ]
[ : ; execute
immediate inline compileonly 0-foldable
1-foldable 2-foldable 3-foldable 4-foldable
5-foldable 6-foldable 7-foldable constant
2constant smudge setflags aligned
align h, , ><,
string, allot forgetram compiletoram?
compiletoram compiletoflash (create) variable
2variable nvariable buffer: dictionarystart
dictionarynext skipstring find hook-find
(find) cjump, jump, here
flashvar-here then else if
ahead repeat while until
again begin k j
i leave unloop +loop
loop do ?do case
?of of endof endcase
token parse digit number
.digit hold hold< sign
#> f#S f# #S
# <# f. f.n
ud. d. u. .
evaluate interpret hook-quit quit
eint? eint dint ipsr
nop unhandled reset irq-systick
irq-fault irq-collection irq-rtc irq-exti0
irq-exti1 irq-exti2 irq-exti3 irq-exti4
irq-adc irq-exti5 irq-tim1brk irq-tim1up
irq-tim1trg irq-tim1cc irq-tim2 irq-tim3
irq-tim4 irq-i2c1ev irq-i2c1er irq-i2c2ev
irq-i2c2er irq-spi1 irq-spi2 irq-usart1
irq-usart2 irq-usart3 irq-exti10 irq-rtcalarm
irq-usbwkup irq-tim5 irq-spi3 irq-uart4
irq-uart5 irq-tim6 irq-tim7 irq-usbfs
--- Flash Dictionary ---
72mhz u.1 u.2 u.3
u.4 u.8 h.1 h.2
h.3 h.4 h.8 hex.1
hex.2 hex.3 hex.4 u.ns
const. addr. .decimal bit
b8loop. b16loop. b16loop-a. b32loop.
b32sloop. bin. bin1. bin2.
bin4. bin4l. bin4h. bin16.
WRITEONLY RCC RCC_CR RCC_CFGR
RCC_CIR RCC_APB2RSTR RCC_APB1RSTR RCC_AHBENR
RCC_APB2ENR RCC_APB1ENR RCC_BDCR RCC_CSR
RCC_CR. RCC_CFGR. RCC_CIR. RCC_APB2RSTR.
RCC_APB1RSTR. RCC_AHBENR. RCC_APB2ENR. RCC_APB1ENR.
RCC_BDCR. RCC_CSR. RCC. GPIOA
GPIOA_CRL GPIOA_CRH GPIOA_IDR GPIOA_ODR
GPIOA_BSRR GPIOA_BRR GPIOA_LCKR GPIOA_CRL.
GPIOA_CRH. GPIOA_IDR. GPIOA_ODR. GPIOA_BSRR.
GPIOA_BRR. GPIOA_LCKR. GPIOA. GPIOB
GPIOB_CRL GPIOB_CRH GPIOB_IDR GPIOB_ODR
GPIOB_BSRR GPIOB_BRR GPIOB_LCKR GPIOB_CRL.
GPIOB_CRH. GPIOB_IDR. GPIOB_ODR. GPIOB_BSRR.
GPIOB_BRR. GPIOB_LCKR. GPIOB. GPIOC
GPIOC_CRL GPIOC_CRH GPIOC_IDR GPIOC_ODR
GPIOC_BSRR GPIOC_BRR GPIOC_LCKR GPIOC_CRL.
GPIOC_CRH. GPIOC_IDR. GPIOC_ODR. GPIOC_BSRR.
GPIOC_BRR. GPIOC_LCKR. GPIOC. EXTI
EXTI_IMR EXTI_EMR EXTI_RTSR EXTI_FTSR
EXTI_SWIER EXTI_PR EXTI_IMR. EXTI_EMR.
EXTI_RTSR. EXTI_FTSR. EXTI_SWIER. EXTI_PR.
EXTI. TIM2 TIM2_CR1 TIM2_CR2
TIM2_SMCR TIM2_DIER TIM2_SR TIM2_EGR
TIM2_CCMR1_Output TIM2_CCMR1_Input TIM2_CCMR2_Output TIM2_CCMR2_Input
TIM2_CCER TIM2_CNT TIM2_PSC TIM2_ARR
TIM2_CCR1 TIM2_CCR2 TIM2_CCR3 TIM2_CCR4
TIM2_DCR TIM2_DMAR TIM2_CR1. TIM2_CR2.
TIM2_SMCR. TIM2_DIER. TIM2_SR. TIM2_EGR.
TIM2_CCMR1_Output. TIM2_CCMR1_Input. TIM2_CCMR2_Output. TIM2_CCMR2_Input.
TIM2_CCER. TIM2_CNT. TIM2_PSC. TIM2_ARR.
TIM2_CCR1. TIM2_CCR2. TIM2_CCR3. TIM2_CCR4.
TIM2_DCR. TIM2_DMAR. TIM2. I2C1
I2C1_CR1 I2C1_CR2 I2C1_OAR1 I2C1_OAR2
I2C1_DR I2C1_SR1 I2C1_SR2 I2C1_CCR
I2C1_TRISE I2C1_CR1. I2C1_CR2. I2C1_OAR1.
I2C1_OAR2. I2C1_DR. I2C1_SR1. I2C1_SR2.
I2C1_CCR. I2C1_TRISE. I2C1. SPI1
SPI1_CR1 SPI1_CR2 SPI1_SR SPI1_DR
SPI1_CRCPR SPI1_RXCRCR SPI1_TXCRCR SPI1_I2SCFGR
SPI1_I2SPR SPI1_CR1. SPI1_CR2. SPI1_SR.
SPI1_DR. SPI1_CRCPR. SPI1_RXCRCR. SPI1_TXCRCR.
SPI1_I2SCFGR. SPI1_I2SPR. SPI1. ADC1
ADC1_SR ADC1_CR1 ADC1_CR2 ADC1_SMPR1
ADC1_SMPR2 ADC1_JOFR1 ADC1_JOFR2 ADC1_JOFR3
ADC1_JOFR4 ADC1_HTR ADC1_LTR ADC1_SQR1
ADC1_SQR2 ADC1_SQR3 ADC1_JSQR ADC1_JDR1
ADC1_JDR2 ADC1_JDR3 ADC1_JDR4 ADC1_DR
ADC1_SR. ADC1_CR1. ADC1_CR2. ADC1_SMPR1.
ADC1_SMPR2. ADC1_JOFR1. ADC1_JOFR2. ADC1_JOFR3.
ADC1_JOFR4. ADC1_HTR. ADC1_LTR. ADC1_SQR1.
ADC1_SQR2. ADC1_SQR3. ADC1_JSQR. ADC1_JDR1.
ADC1_JDR2. ADC1_JDR3. ADC1_JDR4. ADC1_DR.
ADC1. DBG DBG_IDCODE DBG_CR
DBG_IDCODE. DBG_CR. DBG. NVIC
NVIC_ICTR NVIC_STIR NVIC_ISER0 NVIC_ISER1
NVIC_ICER0 NVIC_ICER1 NVIC_ISPR0 NVIC_ISPR1
NVIC_ICPR0 NVIC_ICPR1 NVIC_IABR0 NVIC_IABR1
NVIC_IPR0 NVIC_IPR1 NVIC_IPR2 NVIC_IPR3
NVIC_IPR4 NVIC_IPR5 NVIC_IPR6 NVIC_IPR7
NVIC_IPR8 NVIC_IPR9 NVIC_IPR10 NVIC_IPR11
NVIC_IPR12 NVIC_IPR13 NVIC_IPR14 NVIC_ICTR.
NVIC_STIR. NVIC_ISER0. NVIC_ISER1. NVIC_ICER0.
NVIC_ICER1. NVIC_ISPR0. NVIC_ISPR1. NVIC_ICPR0.
NVIC_ICPR1. NVIC_IABR0. NVIC_IABR1. NVIC_IPR0.
NVIC_IPR1. NVIC_IPR2. NVIC_IPR3. NVIC_IPR4.
NVIC_IPR5. NVIC_IPR6. NVIC_IPR7. NVIC_IPR8.
NVIC_IPR9. NVIC_IPR10. NVIC_IPR11. NVIC_IPR12.
NVIC_IPR13. NVIC_IPR14. NVIC. input.analog
output.pp input.floating output.od input.pullx
output.af.pp output.af.od gpio? SCB_CPUID
SCB_ICSR SCB_VTOR SCB_AIRCR SCB_SCR
SCB_CCR SCB_SHPR1 SCB_SHPR2 SCB_SHPR3
SCB_SHCSR SCB_CFSR SCB_HFSR SCB_MMFAR
SCB_BFAR STK_CSR STK_RVR STK_CVR
STK_CALIB STK_CTRL STK_LOAD STK_VAL
dump16 dump words4 chipid
hwid c,collection c, calign
flash-kb flash-pagesize init-ring c++@
ring-step ring# ring? >ring
ring> usb:dev usb:conf usb:langid
usb:vendor usb:product usb:line usb:init
USB USB_EP0R USB_CNTR USB_ISTR
USB-FNR USB_DADDR USB_BTABLE USBMEM
usb-pma usb-pma@ usb-pma! ep-addr
ep-reg rxstat! txstat! ep-reset-rx#
rxclear txclear usb-pend usb-serial
set-serial send-data send-next send-desc
usb-reset zero usb-in-ring usb-out-ring
ep-setup tx.pend usb.ticks usb-pma-c!
usb-fill ep-out ep-in usb-ctr
usb-flush usb-poll usb-key? usb-key
usb-emit? usb-emit usb-io init.usb
deinit.usb +usb -usb flashfree
ramfree flashfree. ramfree. memstats
word.start word.end disasm-$ disasm-fetch
disasm-string name. register. opcode?
reg. reg16. reg16split. registerlist.
imm3. imm5. imm8. imm3<<1.
imm5<<1. imm8<<1. imm3<<2. imm5<<2.
imm7<<2. imm8<<2. condition. rotateleft
rotateright imm12. destination-r0 disasm-thumb-2
disasm memstamp disasm-step seec
see free ticktime tickint
systick-handler init.systick ticktime. zero-ticktime
ms.delay cornerstone --utils-- calltrace-handler
init.calltrace RCC_APB2ENR_IOPAEN RCC_APB2ENR_IOPBEN RCC_APB2ENR_IOPCEN
JUMPER-ON? GPIOA_CRL_MODE0<< GPIOC_CRH_MODE13<< GPIOC_BSRR_BS13
GPIOC_BSRR_BR13 GPIOB_CRH_MODE9 GPIOB_CRH_CNF9 GPIOB_BSRR_BS9
GPIOB_BSRR_BR9 PB9-LOW PB9-HIGH GPIOA_CRH_MODE12
GPIOA_CRH_CNF12 GPIOA_BSRR_BS12 GPIOA_BSRR_BR12 PA12-HIGH
PA12-LOW blink pa12-init pa12-disable
pa12-pulse pb9-init pb9-disable pb9-pulse
usddp-init usbdp-pulse usbdp-disable 2nd64kb-verified-flag
test-flag pass-flag flash=65536-declared-flag
qty-flash-declared? 2nd64kb-verified-flag-test
FF? AA? 55? fillAA
fill55 erase 2nd64kb? hidden64kB?
cause-exception wait flash-declared? print-flash-declared
DBGMCU_IDCODE-UNREADABLE-FLAG
3addr duid serial is-ascii?
ascii. id scb_cpuid-bits31-0 scb_cpuid-bits31:24
scb_cpuid-bits23:20 scb_cpuid-bits19:16 scb_cpuid-bits15:4 scb_cpuid-bits3:0
scb-cpuid uuid print-dbgmcu_idcode dbgmcu_idcode?
test-status? F103C8T6-Auth? 0dump 1dump
fflag-fail! fflag-pass! ex3 flash-$55@$1FFF0
read-@$1FFF0 credits license faq
usb-faq fallthru extra-menu-print menu-a
menu-print extra-menu menu m
version-major version-minor version? option-jumper?
init
Dissasembler¶
see 2+
see 2+
0000205A: 3602 adds r6 #2
0000205C: 4770 bx lr
Bytes: 4 ok.
Optional SWDCOM Terminal¶
Because the USB virtual comms is lost every time the board is reset, and Forth project development requires the target MCU is usually reset hundreds of times, it makes development a real PITA!
So I have added a SWDCOM terminal bootup option for development use because the SWDCOM terminal is unaffected by board resets.
SWDCOM has many other advantages described in the URL below, one of which is that hitting CTRL-C at the PC keyboard will force a Bluepill reset, this is easier and faster then looking for a tiny reset button on the Bluepill pcb.
This is enabled by jumpering PA-0 to 3.3v before bootup which switches the terminal to use SWDCOM and disables the Diags menu from starting. The menu is still there and can be started by entering “m” or “menu”.
Note
When running test [d] “Print DBGMCU_IDCODE” with SWDCOM, it will work because now SWD IS connected, so a genuine STM32F103C8T6 fill fail the [a] “Authenticity Test” under these circumstances.
https://mecrisp-stellaris-folkdoc.sourceforge.io/swdcom.html
Enable SWDCOM¶
PA-0 <--> 3.3V
Bluepill SWD connections¶
SWD |
Bluepill Target Board |
---|---|
SWCLK |
PA-14 |
SWDIO |
PA-13 |
Utilities¶
Dictionary¶
There are several hundred user programs (Words) in this release. To see all the default ones and what they do, please refer to the dictionary description at https://mecrisp-stellaris-folkdoc.sourceforge.io/words.html
Here are a few of them for you to try.
Display Free Memory¶
note: Mecrisp-Stellaris will warn you if your flash or ram are running out.
“free” shows the current free flash and ram status. Flash status assumes a 128kb flash chip (including the STM32F103C8 hidden 64KB)
free
Memory stats in bytes:
Flash Total:131072 Used:61440 Free:69632
Ram Total:20480 Used:1920 Free:18560
Display Number of Programs Installed¶
defcount .
777 ok.
Free up flash for Development Programs¶
If you’re now using your Bluepill as a Forth development board and no longer require the Bluepill Diags, type the following, which will free up a lot of space. This will not affect the USB terminal or developer utils etc. You can always replace it by re-flashing bluepill-diagnostics-v1.6.bin.
--utils--
Write Your Own Programs¶
You can write your own Forth programs using this system, everything you need is supplied in the binary, except for one component, which is downlodable elsewhere.
Cycle Counter Blocking Delay¶
How about a blocking delay that takes the number of CPU cycles as the input parameter ? Just upload the following program via your terminal.
\ A 32 bit cycle counter available on most M3/M4/M7 targets
$E0001000 constant DWT_CONTROL
$E0001004 constant DWT_CYCCNT
$E0001FB0 constant DWT_LAR
$E000EDFC constant SCB_DEMCR
: init-cycles ( -- )
$C5ACCE55 DWT_LAR ! \ Unlock
$01000000 SCB_DEMCR ! \ Enable Data Watchpoint and Trace (DWT) module
0 DWT_CYCCNT ! \ Reset the counter
1 DWT_CONTROL ! \ Enable the counter
;
: cycles ( -- u ) DWT_CYCCNT @ ;
: delay-cycles ( cycles -- )
cycles ( cycles start )
begin
pause
2dup ( cycles start cycles start )
cycles ( cycles start cycles start current )
swap - ( cycles start cycles elapsed )
u<=
until
2drop
;
Usage¶
268435455 cycles ok.
Heaps More Applications¶
Download the latest Mecrisp-Stellaris release at https://sourceforge.net/projects/mecrisp/files/ and look in the contrib/ directory where you will find applications for :
Real time clock usage
Advanced Fixed Point Maths
Graphics
Daylight time calculations for any LAT/LONG and time
Cooperative Multitasking
Cordic maths, sin, cos, tan etc
Peripheral Code¶
The Mecrisp-Stellaris release also contains user supplied Forth peripheral example code for the following microprocessors.
GPIO
./mk20dx256/gpio.txt
./stm32f407-ra/gpio.fs
./stm32f411-ra/gpio.fs
./stm32f030r8-ra/gpio.fs
SPI
./stm32f407/drv_spi2.txt
./stm32f411/si4432_spi.fs
./stm32f103/si4432_spi.fs
DAC
./mk20dx256/dac.txt
./stm32f407/dac.txt
./kl25z128/dac.txt
I2C
./stm32l432-ra/drv_i2c1.txt
./stm32f051/Examples by Andrew Palm/example-nunchuk-i2c.fs
./lpc1114fn28/i2c.txt
./stm32g031j6-ra/i2c.txt
TIMER
./mk20dx256/timer.txt
./stm32f407/lib_timer.txt
./lm4f120/timer-irq.txt
NVIC
./mk20dx256/nvic.txt
./nrf52832/lib/nvic.fs
./common/nvic.txt
RCC
./stm32f407-ra/def-rcc.fs
./stm32f411-ra/rcc.fs
./common/svd2forth-v3/bitfields-rcc-screenshot.txt
./common/svd2forth-v3/equates-rcc-sample.txt
RNG
./nrf52832/lib/rng.fs
./stm32f407/rng.txt
ADC
./stm32f303k8-ra/lib_adc1.txt
./tm4c1294/ether-adc.txt
./stm32f407/lib_adc.txt
./stm32f407/adc.txt
./stm32f407/adc-1msps-stm32f4.txt
./stm32f303k8/lib_adc1.txt
./lm4f120/adc-1msps-2chan.txt
./lm4f120/adc-1msps.txt
./kl25z128/adc.txt
./stm32f051/Examples by Andrew Palm/example-adc.fs
./stm32f411/adc.txt
UART
./mk20dx256/uart.txt
USART
./stm32l432-ra/drv_usart1.txt
./stm32f303k8-ra/drv_usart1.txt
./stm32f407/drv_usart6.txt
./stm32f401cd-ra/drv_usart_DMA.txt
./stm32f303k8/drv_usart1.txt
COMP
./numworks-ra/completesources.txt
RTC
./tm4c1294/rtc.txt
./lm4f120/rtc.txt
./stm32f411/rtc.fs
./stm32f429/rtc.fs
Flash
./stm32f746-ra/clean-debug-flash-demo.txt
./stm32f411-ra/flash.fs
./stm32f407/drv_flash.txt
./stm32f407/flash.txt
Ethernet
./tm4c1294/ethernet.txt
Otg
./mk20dx256/usbotg.txt
Usb
./mk20dx256/usbdcd.txt
./mk20dx256/usbotg.txt
./stm32f407-ra/usb-f4.fs
./stm32f103-ra/usb-f1.txt
./stm32f303-ra/usb-f3.txt
Can
./stm32f407/drv_can.txt
./stm32f407/can.txt
Credits¶
Document Software¶
This document was designed on FreeBSD and would not have been possible without the following programs.
Program |
Details |
---|---|
|
by Matthias Koch, http://mecrisp.sourceforge.net/ |
|
https://www.sphinx-doc.org/en/master/usage/installation.html |
|
Data Dump Contributors¶
Those who took the time to supply MCU dumps from my earlier Bluepill Diags-V1.
JDEC Data¶
Andre for his work with the Jdec data. https://www.blaatschaap.be/32f103-comparison-part-3/
Mcu Data Contributors¶
Name |
Contribution |
---|---|
Jonathan Giles |
CH32F103C8T6 data |