.. index:: stm32f103c8:diagnostics,stm32f103c8: hidden extra 64kB flash .. _stm32f103c8-diags: STM32F103C8 Diagnostics ======================= This is the older **obsolete** version of :ref:`STM32F103XX-DIAGNOSTICS` which has many improvements as regards MCU type detection. This is the recommended binary to use with the Blue Pill etc. .. image:: pics/stm32f103c8-diags.jpg **STM32F103C8** datasheets specify the on board Flash memory as being 64kB, and this is corroborated by the on chip "Flash Size Register" having a value of 65536 Bytes, however it seems these chips actually have a "hidden" second 64kB Block, making a total of **128kB of Flash onboard!** Many theories abound, did STM simply use the same die for both the more expensive 128kB Flash STM32F103CB and the cheaper STM32F103C8 to save costs, but configure the STM32F103C8 to show only 64kB ? Perhaps STM ran out of STM32F103C8's and simply used modified STM32F103CB units instead ? Or maybe STM32F103CB units with a faulty memory location in the second Flash block were sold as STM32F103C8's and the"Flash Size Register" set to 65536 Bytes ? The STM32F103C8 MCU is found in many cheap Chinese boards including the very popular :ref:`Bluepill Board` which means that many owners may not be aware they actually have *DOUBLE the Flash* they thought they had. This Project ------------ This is a bootable diagnostic program test kit. The size is under 64kB so that it can be flashed by OpenOCD. The purpose of this kit is to physically test the "hidden" 64kB second Flash block present on many of these chips and determine if it exists and if it is reliable. It does this by flashing all the bits from one to zero and back again. .. _download-STM32F103C8-DIAGNOSTICS.bin: Download the **OBSOLETE** *STM32F103C8-DIAGNOSTICS.bin* here: https://sourceforge.net/projects/mecrisp-stellaris-folkdoc/files/STM32F103C8-DIAGNOSTICS.bin/download .. note:: STM32F103C8-DIAGNOSTICS.bin has been replaced by :ref:`STM32F103XX-DIAGNOSTICS` which has many improvements as regards MCU type detection. This is the recommended binary to use with the Blue Pill etc. Usage ----- 1. Flash the STM32F103C8-DIAGNOSTICS.bin image to your board with OpenOCD or whatever you normally use. See :ref:`Flashing Methods`, but basically you flash this binary exactly as you would flash any STM32Fxx binary. .i.e a. "st-flash erase" b. "st-flash write STM32F103C8-DIAGNOSTICS.bin 0x08000000" 2. Plug in a USB cable to the "Blue Pill" board and run a :ref:`serial terminal program` on your PC. This will also power the board. 3. Connect the terminal to the '"Mecrisp STM32F10x Forth Serial Port' USB device now created on your PC. Any speed is ok, I use 460800 Baud myself. 4. Enter "?" at the prompt to obtain the menu. 5. The "t" key runs the all important Flash test, but there are other menu functions available as listed below. .. note:: The first few versions had a garbled USB device ID string, this was corrected in V1.2 and should look something like this. :: umodem1: on usbus0 Menu ---- Enter ? for the menu :: m - Menu: STM32F103R8 Test Kit v1.2 24Dec2019 i - Device ID, unique for every chip b - Device Reported Flash Size in Bytes t - TEST second 64kB Flash Memory block: 0x10000 - 0x1FFFF d - View second 64kB Flash Memory block: 0x10000 - 0x1FFFF e - View first 64kB Flash Memory block: 0x00000 - 0x10000 f - FAQ c - Credits l - License q - Quit i ^^^^ :: stm32id Die xy coords: 108003155 Wafer Number: 80 Lot_num ascii encoded [23:0]: 0x00555071 | U P q Lot_num ascii encoded [55:24]: 0x87042957 | . . ) W b ^^^^ :: Flash Size Register = 65536 Bytes t ^^^^ This tests every bit of the *'hidden'* flash block at 0x10000 - 0x1FFFF by writing alternating ones and zero's, checking they have been saved and then erasing them. If you don't see this result, or see error messages instead, then the *'hidden'* flash block at 0x10000 - 0x1FFFF has a problem and probably is not available for use. A successful test looks like this. Note: there are only three Block erasures and two block flashes when this test is run, so the Flash wear is negligible. :: Testing 64kB Flash block: 0x10000 - 0x1FFFF Erasing Flash with 1010101010101010 (0xAA) Testing for 0xAA - OK Erasing Flash with 0101010101010101 (0x55) Testing for 0x55 - OK Erasing ~~~~~ ALL TESTS PASSED ~~~~~ If test *"b"* shows 65536 Bytes yet this test passes as above, then you have a "hidden" extra 64kB of Flash which cannot be flashed by OpenOCD unless it is modified. .. Note:: If you try to flash a binary image of OVER 64kB into a STM32F103C8 for which the MCU *"Flash Size Register"* = 65536 Bytes, a standard OpenOCD will ONLY flash the first 64kB of your image. See below for how to utilise the full 128kB. .. _128kb_stm32f103c8_mod: Sample OpenOCD modification to allow flashing the "hidden" extra 64kB of Flash ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ stm32f1x.cfg Modification :: # flash size will be probed set _FLASHNAME $_CHIPNAME.flash # flash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME <---- comment this line out, add the line below: flash bank $_FLASHNAME stm32f1x 0x08000000 0x20000 0 0 $_TARGETNAME .. note:: Forth doesn't care about the Flash Size Register value and will use all 128kB of flash in this case. d ^^^^ This dumps the entire 64kB Flash block: 0x10000 - 0x1FFFF showing the binary and ascii contents. e ^^^^ This dumps the entire 64kB Flash block: 0x00000 - 0x10000 showing the binary and ascii contents. f ^^^^ * Will this work with non STM32F103R8 chips << Not guaranteed * How many times can the 't' test be safely run << 1000 times at least * The Flash Data View is too fast << Use your terminal loging facility & capture it * Will this test harm my chip << No * How can I view the current chip memory status << Quit the Menu and enter 'free' * What was the Test Kit made with << The Forth Programming Language * How do I find other programs I can run << Quit the Menu and enter 'words4'. (Some of these Words can erase the Flash) * Can I write other programs, blink a LED << Yes, quit the Menu and enter 'gpioc.' (This is a demo of the built in register read/write facility.) * Learn more << https://mecrisp-stellaris-folkdoc.sourceforge.io/quickstart.html c ^^^^ Credits :: This diagnostic program written by Terry Porter https://mecrisp-stellaris-folkdoc.sourceforge.io/stm32f103c8-diags.html Get Mecrisp-Stellaris Forth: https://mecrisp-stellaris-folkdoc.sourceforge.io Mecrisp-Stellaris created by Matthias Koch l ^^^^ License :: Mecrisp-Stellaris is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . q ^^^^ Quit the menu. .. warning:: This is a full Cortex-M3 Forth and can be used from the terminal command line. If your chip fails test *"t"* don't use more than 64kB of your flash with the on-board Forth or it will crash. Developed on a STM32F103C8 board (with the "hidden" second 64kB Flash block present) which is identical to a "Blue Pill", so it should work on all such boards. STM32F103 Spec Sheet -------------------- .. image:: pics/STM32F103Cx-memspec.jpg How does this all work? ----------------------- The fact that my 10 tested STM32F103C8's had a second hidden 64kB block doesn't alter the STM spec above because any flashing software must check the MCU internal "Flash Size Register" first, will read that the STM32F103C8 has only 64kB and ignore that second block, it doesn't have any other choice. Reading the MCU "Flash Size Register" first is essential for a few reasons one of which is the MCU will throw an exception if a program attempts to do anything to Flash that's not actually there. My St-Link would program any size image up to 64kB on the STM32F103C8. If the Image was 100kB, it stopped at 64kB and threw an error as expected. St-Link reads the MCU "Flash Size Register" and acts accordingly as it must. It can be :ref:`reconfigured so it thinks the STM32F103C8 has 128kB of Flash<128kb_stm32f103c8_mod>`, which is what I had to do to flash binaries over 64kB but under 128kB on a STM32F103C8 which actually had the 'hidden second 64kB Flash Block". My Olimex-P103 has a STM32F103CB with 128kB as shown in the Factory Datasheet above, so St-Link would program a 100kB image without complaint because the STM32F103CB MCU "Flash Size Register" indicates the chip has 128kB of Flash. This is how it all works This "STM32F103C8 Diagnostics" bootable binary is designed to run on any STM32F103Cx as it is under 64kB and reveal all the above. Chip ID Data ------------ Can we tell from the chip ID data if a chip is a fake ? I think so as genuine STM chip Lot Numbers are in DECIMAL, CS32F103C8T6 chip Lot Numbers are in Hexadecimal. ==================== =========== ============== =================================================== Chip Lot Numbers Example Description ==================== =========== ============== =================================================== Genuine STM decimal 0x00565283 Only contains digits 0 - 9 CS32F103C8T6 hexadecimal 0x004D3512 Contains digits 0 - 9 AND characters A,B,C,D,E,F GD32F103C8T6 ? I have no data yet ==================== =========== ============== =================================================== Good Chip Reports ----------------- 107741012/72 ^^^^^^^^^^^^ :: stm32id Die xy coords: 107741012 Wafer Number: 72 Lot_num ascii encoded [23:0]: 0x00565283 | V R . Lot_num ascii encoded [55:24]: 0x87242040 | . $ @ Flash Size Register = 65536 Bytes ~~~~~ ALL TESTS PASSED ~~~~~ 107872085/72 ^^^^^^^^^^^^ :: stm32id Die xy coords: 107872085 Wafer Number: 72 Lot_num ascii encoded [23:0]: 0x00555787 | U W . Lot_num ascii encoded [55:24]: 0x87061320 | . . . Flash Size Register = 65536 Bytes ~~~~~ ALL TESTS PASSED ~~~~~ Bad Chip Reports ---------------- CKS CS32F103C8T6 ^^^^^^^^^^^^^^^^ Rhodges from EEVblog reports a CKS CS32F103C8T6 that an ebay seller sold as a ST part (oops!) failed the test with 0x10000 - 0x1FFFF appearing to be a read-only mirror of 0x00000 - 0x10000 :: stm32id Die xy coords: 16917299 Wafer Number: 50 Lot_num ascii encoded [23:0]: 0x004D3712 | M 7 . Lot_num ascii encoded [55:24]: 0x004E4B43 | . N K C Flash Size Register = 65536 Bytes Testing 64kB Flash block: 0x10000 - 0x1FFFF Erasing FAILTEST: $10000 Data = $8C FAILTEST: $10001 Data = $03 ... all the way to FAILTEST: $1CDE5 Data = $BD FAILTEST: $1CDE6 Data = $00 FAILTEST: $1CDE7 Data = $00 blank check FAILTEST