STM32F051K8-SWDCOM¶
### Project: STM32F051K8-SWDCOM #### File Name: STM32F051K8-SWDCOM.md #### Started: Sat 12 Sep 2020 16:46:55 AEST
<pre> Copyright 2019 Terry Porter terry@tjporter.com.au
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the this copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS’’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. </pre>
#### This project: A STM32 technology demonstrator showcasing the advantages of using the SWD (Serial Wire Debugging) interface as a Forth Terminal instead of the legacy serial USART. This is made to use a STMicro STM32F0 Discovery board but can use a SWD-USB Programmer and a STM32F0xx mcu instead.
#### Credits: - SWDcom Demo written by Terry Porter <terry@tjporter.com.au> - SWDcom by Jan Bramkamp <https://github.com/Crest/swdcom> - Mecrisp-Stellaris by Matthias Koch https://sourceforge.net/projects/mecrisp/
#### Serial communications. Forth is one of the oldest programming languages in existence having been developed in the early 70’s. In those days a computer running Forth usually communicated with a serial device, perhaps a Teletype or later a Wyse dedicated electronic terminal to allow interactive development and program uploading.
The availability of the IBM PC in the early 80’s (and other readily available portable computers) allowed the use of terminal emulators such as Picocom, Minicom etc running on the PC itself instead of dedicated terminals.
#### Developer unfriendly Usart based Forth legacy serial communications issues. - Slow, most Forths don’t go above 115200 Baud. - No serial flow control. This requires ‘end of line delays’ to prevent the Forth compiler ‘choking’ on uploaded source code. These can be as large as 200 milliseconds (depending on the speed of the Forth mcu) making source uploads glacial. - Changing the mcu clock speed is tedious as the usart Baudrate is derived from it. - An external ‘USB to 3.3v Serial Dongle’ is required for most ‘development boards’ and stand alone mcus to talk to the PC. - Resetting the mcu requires entering ‘reset’ into the Forth console
#### Making Forth developer friendly in 2020. Swdcom, provides a SWD based usart replacement along with a PC based terminal client that works with Linux and FreeBSD plus offers upload times equal to or faster than the equivalent GCC with Stlink on the same PC. Forth realtime interactivity also further reduces project development time.
#### Swdcom advantages - Works across a range of the same class of mcu free from usart/pin dependencies. - Fast, faster than a equivalent 460800 Baud serial terminal. - Inbuilt ACK flow control, no compiler ‘choking’ issues. - Clock speed agnostic as long as the MCU clock is running the swd2 terminal functions perfectly. - Uses a single USB cable from the PC to most development boards or a usb/swd programmer for standalone mcus. - Resetting the mcu is easily done by hitting CTRL+C on the PC keyboard.
#### Running this Demo This demo has been tested under Debian-10.6-xfce and FreeBSD so it should work for you on those platforms.
##### FreeBSD Needs the following:
xorg
xterm
git
##### Debian-10.6-xfce Needs the following items and you will need to be root to access the USB devices unless you have those permissions organised on your system:
git
cmake
pkg-config
libusb-1.0-0-dev
bc
####Runing this demo on a STM32F0 Discovery board 1. Connect a STM32F0 Discovery board to the PC with a USB cable.
Unzip the contents, it will create the “STM32F051K8-SWDCOM” directory.
Cd to the STM32F051K8-SWDCOM directory and open a Xterm.
Compile Swdcom: in the Xterm type “make swdcom” this will build SWD2, the PC terminal client for your system. Swdcom with stlink will be downloaded by Git and built in the demo directory only, nothing is installed outside this directory on your system. It will not interfere with stlink if you have it on your system already.
Flash the Mecrisp-Stellaris binary to the board: in the Xterm type “make flash”. This uses the stlink built in step 4. stlink does not need to be installed on your system.
6. Open a SWD2 FORTH TERMINAL to the STM32F0 Discovery Board: in the Xterm enter “make term”, this will open a new window which will talk to the Board.The SWD2 FORTH TERMINAL window will have this text in the banner “SWD2 FORTH TERMINAL”. Expand this window until it is about half of your screen, with the other half being used by the Xterm window. This is the Forth command line, to test it hit enter a few times and you will get the “ok” acknowledgement, enter “words” and see all the programs already in the system. KEEP the “SWD2 FORTH TERMINAL” OPEN or uploads will FAIL. Watch this window to see the source being uploaded. Although there wont be any errors in the demo, any errors will be displayed in RED text and RING the terminal bell, and ABORT the source code upload.
Upload the library programs: in the Xterm enter either “make lib” or “make 8mhz-lib” and you should see a lot of source scrolling quickly upwards in the “SWD2 FORTH TERMINAL”.
Near the end you will see the following upload statistic showing the Swdcom can upload speed. There are two clock speed options 1. 48 Mhz selected by “make lib” 2. 8 Mhz selected by “make 8mhz-lib” Use this one if “make lib” fails on your board.
<pre> Number of uploaded Words: 317 Source upload time : 32,69 seconds Source upload/compile rate: 9,6 Words per second Hardware: STM32F051 @ 8 MHz
Number of uploaded Words: 299 Source upload time : 6,85 seconds Source upload/compile rate: 43,5 Words per second Hardware: STM32F051 @ 48 mhz </pre>
In the SWD2 FORTH TERMINAL try entering “words4” and you will see a long list of programs.
Finally, in the Xterm enter “make” and you will see project source being rapidly uploaded. Once it has finished it will display a menu.
This concludes the important parts of this demo, namely
“make lib” or “make 8mhz-lib” - Rapidly uploading of Forth libraries in their correct sequence to FLASH MEMORY, ending with upload/compile speed statistics.
“make” - Rapid upload of Forth project development files to RAM MEMORY for iterative testing/debugging and development.
The SWD2 FORTH TERMINAL menu below lists a few interesting programs to demonstrate project development speed using swdcom on Forth.