• I have accumulated lot of cheap stuff based on STMF103C8T6 chip. Before pandemic, these were typically for < 2 USD on Aliexpress/Ebay including shipping.

    They typically have 20KB RAM, 128KB Flash and USB. Some board files are still in https://github.com/espruino/Espruino/tre­e/UNMAINTAINED_BOARDS/boards

    Wanted to check whether current code still fits and how usable they are with Espruino now. Main reason was to have something to experiment with STLINK V2 dongle (see e.g. https://hackaday.io/project/162597-st-li­nk-clone-repurposing) as I wanted to port something to it so wanted to get familiar quickly with the hardware.

    I started with minimal SAVE_ON_FLASH configuration (only 128KB of Flash!) and then managed to add

    • Flash and Storage modules (including Storage.compact() and getFree())
    • tab completion
    • native calls - Inline C, compiled JS
    • loading modules from storage require("xx")
    • arrow functions (for Espruino IDE storage browsing/uploads)

    while still having 11KB flash free for persistent storage. So overall surprising success. With 20K RAM there is also ~1000 variables.

    So now I have very compact USB stick Espruino device with pin header with up to six GPIOs that can do HW UART (including console if usb is not plugged in), software SPI and I2C and other stuff. Tried e.g. to backup SPI flash (photo here https://i.ibb.co/fG3wRJf/IMG-20211119-01­2644.jpg ) and it was pretty easy to do. I can also load native C code quickly to test this platform.

    The only catch is that there is no bootloader so update is needed via SWD, but when bringing SWD pins outside, which is easy to do, reprogramming is easy and I have two more GPIOs (A13,A14) as SWD functionality can be turned off at runtime via one poke32 call. Also I am thinking about building some "bootloader" and upload it to storage (or RAM) temporarily to update it via USB or serial.

    Some photos, board file and binary build is here

  • Wow, this is super cool - thanks for sharing!

  • If you have many of them (I do, my incomplete order history :-) ) then it is good to pick the better ones. Some have two leds, some one, some have chip labelled STM32 some have CKS32 and also some have 680 ohm pullup on SWIM (as per schematics) which is easy to find and scratch off the board and some not. Also some have SWD test points that are easier to solder (bigger or with holes) or attach to, some not. With every order I got slightly different one and then when searching internet I saw plenty of different ones too. I flashed two variants (three in total) and they work fine but no guarantee it will work with yours. Also some are labelled F101 instead of F103 (F101 should not have USB functionality at all, don't have any 101 one myself but others report getting it).

    Also nowadays they are more expensive so not worth getting them now I guess. Funnily I wanted to port CMSIS-DAP debugger source to it including working UART and then checked aliexpress for these dongles again and found cheaper ones already having CMSIS-DAP preinstalled - here or here, ordered but will see what is inside. There can be something worse than STM32.

  • Just a small followup - I found aliexpress store that sells those STLink V2 dongles (board photo https://ibb.co/m4MpRhB) with Geehy APM32F103CBT6 https://www.geehy.com/apm32?id=14

    This APM32F103CBT6 is somewhat interesting STM32F103 clone that has 128KB of flash and can run at 96MHz with usb working (real STM32F103 can only do 72MHz). It even has interesting memory mapped single precision FPU that seems to work. So I made Espruino build that run on that chip at 96MHz.

    These dongles are cheap, small and versatile but the ram/flash is pretty small (20KB,128KB) so the Espruino build is stripped down but still it can be used for small USB to GPIO/SPI/I2C projects. The usb stick like form factor with metal case and pin header on the other side can be handy.

    The shop is here https://www.aliexpress.com/item/10050016­21626894.html but no guarantee you'll get same chip too. I got it twice and made third order. Anyway, it is no big deal, just small heads up.

    And btw this one is also nice because it has two LEDs, no strong pull resistors on B6/B7 and even have extra A9/A10 and BOOT0 pads available on PCB so apart from SWD can be flashed via serial bootloader and those two more GPIOs are also readily available for extra HW uart.

  • @fanoush Two years later and you're still making my day... I've had trouble getting my STlink working with OpenOCD and just wanted to write a quick/dirty SWD app in Espruino. Not only have you already done that, but you made my STlink useful! Once I get the SWD app working, I'm going to write an HTML front-end to upload firmware via the dongle.
    Turns out I have the APM32 version. I tried the CMSIS-DAP binary but that didn't work (haven't gotten it to work on my DAPlink either!) But I'm charged now, so thanks for the work!

  • As for SWD - there are official docs from ARM but recently I found very nice document that describes SWD a bit better and there is even example source code for all needed bits
    Google for "AN11553 Serial Wire Debug (SWD) programming specification" currently it is here

    as for the CMSIS-DAP binary not working, that is strange, should work in all STM32F103 based dongles that come with STM32 STLINK V2 firmware (= must have same compatible pinout). I flashed it to many such clones and so far it always worked, maybe you are not erasing flash before flashing the binary? Not sure what DAPlink is but other USB dongles from aliexpress that already come with some CMSIS-DAP firmware may have different pinout.

    the swd.js I have there is not latest version, it is a bit slow and experimental, I have other version with more code moved to native Inline C code but that needs modified Inline C compiler to recompile from source so I did not publish it there but it is here https://gist.github.com/fanoush/4a5dcf77­7503461297cedf7e21e3c6b3 I tried to call JS GPIO Pin functions from native code to have platform independent way to do GPIO (so that same Inline C binary blob would run on nrf52 and STM32). But maybe the JIT is now good enough to replace it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

build for STMF103C8T6 - STLINK V2 dongle, Blue Pill, Maple Mini

Posted by Avatar for fanoush @fanoush