.. index:: bluepill, blinky, diagnostic .. _bluepill-blinky: Bluepill Blinky =============== And a gentle introduction to Forth. If you use the :ref:`STM32F103C8 DIAGNOSTICS` image and have wondered about what Forth is and what it can do (apart from make cool standalone binary diagnostcs programs for Blue Pills) this page may be for you. This blinky runs on the :ref:`STM32F103C8 DIAGNOSTICS` image. The Bluepill LED is connected to GPIOC-13. Download -------- https://sourceforge.net/projects/mecrisp-stellaris-folkdoc/files/f103-diagnostics-image-blinky.fs/download The :ref:`STM32F103C8 DIAGNOSTICS` image was made to test Blue Pill boards for hidden extra 64kB Flash plus read chip ID etc, but it's also a complete working Forth which can do all kinds of cool things. Blinking a LED is one of the simpler things this image can do. All you have to do is load the f103-diagnostics-image-blinky.fs file into your Blue Pill and the LED should begin flashing. From your serial terminal select f103-diagnostics-image-blinky.fs and upload it to the Blue Pill. When the file finishes uploading the LED should begin flashing and after 10 flashes, you will be returned to the terminal prompt. Some common issues ------------------ Lockups ^^^^^^^ Symptom: The f103-diagnostics-image-blinky.fs upload only goes as far as a few characters and then appears to lock up. Only pressing the Blue Pill reset button fixes it. See :ref:`this page`. .. note:: For the 75Mhz STM32F103C8 DIAGNOSTICS image you are running on your Blue Pill, 100ms EOL delay should be plenty. LED does not blink ^^^^^^^^^^^^^^^^^^ Symptom: The program runs and then after 10 seconds it stops and control is returned to the terminal, but the LED doesn't blink ? Why? On your board, the LED may not be connected to GPIOC-13. Find out where it is and edit the f103-diagnostics-image-blinky.fs source code or connect a external LED with 510 Ohm Resistor between 3.3V and GPIOC-13. Source Code ----------- .. raw:: html :make :file: bluepill/code/f103-diagnostics-image-blinky.fs.html Fun Stuff --------- Interactivity ^^^^^^^^^^^^^ Now you have your blinky working, try this: :: led.on The LED should turn on ? :: led.off The LED should have turned off ? This is the *INTERACTIVE* nature of Forth, instant real world feedback. No need to compile and flash as is so common with programming languages like C, because with Forth you can obtain instant hardware feedback from the terminal. Register Pretty Printing ^^^^^^^^^^^^^^^^^^^^^^^^ Now try this: :: gpioc. .. note:: the period "." at the end of the command You should have a list of the *CURRENT STATE* of EVERY GPIOC REGISTER displayed ? The idea is to view this in conjunction with the STM32F103 ST Micro Reference Manual RM0008 Rev 20 open on page 171/1134. GPIOC_ODR --------- Enter this into the terminal: :: led.on The GPIOC OUTPUT DATA REGISTER (ODR) is the one which is telling the LED to light via BIT 13. To view it, enter: :: GPIOC_ODR. .. note:: the period "." at the end of the command It should look like this: :: gpioc_odr. GPIOC_ODR $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 No bits are HIGH, the LED is ON because BIT 13 is LOW, due to the Open Drain wiring. Now enter: :: led.off And again enter : :: GPIOC_ODR. See what has changed ? BIT 13 is now HIGH. :: gpioc_odr. GPIOC_ODR $00002000 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 Real Time Views ^^^^^^^^^^^^^^^ You can view IN REAL TIME the contents of all registers that have support Words loaded into your chip. To view all the support Words in your chip right now, type the following and you will see that there are about 760 support programs (Words) in your chip ready to be used ! :: Words4 The :ref:`STM32F103C8 DIAGNOSTICS` image only has a small subset of programs because it had to be smaller than 64kB to fit any Blue Pill chip, but you can get and even make images with EVERY STM32F103 register Word ready to use.