.. index:: c-api-2-forth,usb,ble,middleware,cubeide, hal, cubemx,cmsis-rtos thread .. _c-api-2-forth: .. Created c-api-2-forth.rst: Sun 16 Jan 2022 15:02:37 AEDT .. Full Path: /home/tp/mecrisp-unofficial-doc/c-api-2-forth.rst .. Author Copyright 2022 by t.j.porter .. Made by /home/tp/projects/scripts/makerst.sh -->/usr/local/bin/makerst .. license: MIT, please see COPYING MecrispCube =========== https://spyr.ch/twiki/bin/view/MecrispCube by Peter Schmid Peter Schmid Intro ------------------ STM32WB Forth without BLE, USB, Filesystems and RTOS etc, is not complete. To build this in Forth by myself from the scratch overwhelms me. .. note:: everyone else as well - Terry P I would like to go the reverse way and use the STM tools like CubeIDE, HAL, CubeMX and integrate the Mecrips Forth into it. Forth as an interactive extension for the STM32 ecosystem. **Mecrisp Forth running as a CMSIS-RTOS thread**. Already done ^^^^^^^^^^^^ :: Integrated in STM32 Cube ecosystem. Create C code from CubeMX for internal peripherals and use it in Forth. Forth as CMSIS-RTOS thread. CMSIS-RTOS API to use FreeRTOS from Forth. Buffered terminal I/O (5 KiB buffer for UART Rx). Interrupt driven and RTOS aware, key and emit block the calling thread. USB-CDC for serial communication via USB. Redirect console I/O like cdc-emit, cdc-key microSD and internal Flash mass storage for blocks and FAT filesystem. Internal Flash drive 384 KiB Filesystem API UNIX like Shell commands Calling C Functions from Forth and vice versa vi Editor origin in BusyBox tiny vi. Workflow development: begin Edit EVALUATE while SaveFile repeat Board Support Package BSP (for other boards see Adafruit Feather STM32F405, STM32WB5MM Discovery Kit, and STM32WB Feather development board) LEDs: LED1 (blue), LED2 (green), LED3 (red) Switches: SW1, SW2, SW3 (dongle: SW1) Digital port pins: D0 to D15 (Dongle: D0, D1, D6, D10 to D15) Analog port pins: A0 to A5 (Dongle: A2, A3) PWM: D3, D6, D9 (Dongle: D6) Input capture: A2 Output compare: D0, D1, D5 (Dongle: D0, D1) SPI: D11 MOSI, D12 MISO, D13 SCK (e.g. for display, memory) I2C: D14 SDA, D15 SCL (external peripherals e.g. pressure) BLE 5.0 GAP Peripheral Role DIS Device Information Service HRS Heart Rate Service (heart rate depends on A0 for Nucleo and A2 for Dongle) CRS Cable Replacement Server service (proprietary service from STM, similar to Classic Bluetooth SPP). Redirect console I/O like crs-emit, crs-key. Real Time Clock (32 bit UNIX time stamp, valid times are from 1.1.2000 to 31.12.2099 because of the STM32WB RTC peripheral) time!, time@, and .time (YYYY-MM-DDTHH:MM:SS ISO 8601). Watchdog Assertation and Logging OLED Display 128x32, 128x64, I2C NeoPixel Markdown manual pages Planned TODO ^^^^^^^^^^^^ :: USB-MSC to read and write blocks or files from a host computer UsbCompositeMscCdc. Command line editing like Gforth Arrow right no longer needed, see EditorVi BLE 5.0 GAP Peripheral Role BLE Event driven programming like LAIRD's smartBASIC, WAITEVENT ONEVENT. BLE GATT (Characteristics, Services, Profiles) Current Time Service BLE 5.0 GAP Central Role Scan, Pairing Cable Replacement Client CRC HID profile (keyboard) E-Ink FeatherWing Low power Integration of FFL - Forth Foundation Library http://irdvo.nl/FFL/index.html https://github.com/irdvo/ffl Support for the floating point unit, CMSIS-DSP VIS: VOCs, ITEMs and STICKY Words (Forth Namespaces and Context Switching based on VOCs, ITEMs and STICKY Words) UML state machine (extended state machine, hierarchically nested states), see Finite State Machine module in the ffl Thread (network protocol) SQLite https://en.wikipedia.org/wiki/SQLite SSH https://www.oryx-embedded.com/pdf/CycloneSSH_Datasheet.pdf https://stackoverflow.com/questions/8422287/how-to-call-c-functions-from-arm-assembly https://static.docs.arm.com/ihi0042/g/aapcs32.pdf Getting Started --------------- These instructions will get you a copy of the project up and running on your local machine (STM32 Nucleo board) for development and testing purposes. Prerequisites ^^^^^^^^^^^^^ * STM32WB Nucleo Board - The highly affordable STM32 Nucleo boards allow anyone to try out new ideas and to quickly create prototypes with any STM32 MCU. The STM32 Nucleo boards integrate an ST-Link debugger/programmer, so there is no need for a separate probe. * :ref:`Terminal emulator` application for PC, e.g.: * PuTTY - Windows and Linux * Tera Term - Windows * Realterm - Windows * minicom, microcom, screen - Linux * Use the built in Eclipse console (but no LF) Flash the Mecrisp-Cube binary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Or the FS binary with local filesystem and some tools to the Nucleo Board. :: Connect the Nucleo Board USB ST-LINK to the PC Copy binary (MecrispCube.bin) to the USB mass storage NODE_WB55RG Start the terminal emulator application on the PC. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Check for the serial communication port (e.g. for Linux /dev/ttyACM0) and set the speed to 115200 baud. I set the putty terminal configuration to :: Implicit CR in every LF Local echo: Auto Local line editing: Auto Keyboard Backspace: Control-H Keyboard Function: Keys VT100 Remote character set: CP850 For Unix terminal emulator configs please see :ref:`this link` Mecrisp-Stellaris RA 2.5.4 by Matthias Koch. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mecrisp-Cube 1.4.1 for STM32WB55, 63/128 KiB RAM/FLASH dictionary (C) 2020 peter@spyr.ch * Firmware Package STM32Cube FW_WB V1.10.0, USB-CDC, BLE Stack 5.0 (C) 2020 STMicroelectronics * CMSIS-RTOS V2 FreeRTOS wrapper, FreeRTOS Kernel V10.2.1 (C) 2017 Amazon.com * FatFs for internal flash and microSD - Generic FAT fs module R0.12c (C) 2017 ChaN * tiny vi - part of BusyBox (C) 2000, 2001 Sterling Huxley :: 23 5 / .[CR] 4 ok. : hello ." World" ;[CR] ok. hello[CR] World ok. Installing ~~~~~~~~~~ A step by step series of examples that tell you how to get a development env running Install the IDE STM32CubeIDE, it is Eclipse and GCC based. STM32CubeMX is included in the IDE, you need a stand alone installation only if you do not want to use the STM32CubeIDE. Get the sources from github: :: psi@homer:~> git clone https://github.com/spyren/Mecrisp-Cube Klone nach 'Mecrisp-Cube' ... remote: Enumerating objects: 106, done. remote: Counting objects: 100% (106/106), done. remote: Compressing objects: 100% (71/71), done. remote: Total 106 (delta 33), reused 106 (delta 33), pack-reused 0 Empfange Objekte: 100% (106/106), 938.96 KiB | 2.39 MiB/s, Fertig. Löse Unterschiede auf: 100% (33/33), Fertig. Import the project into the IDE: File -> Import -> General -> Existing Projects into Workspace -> Select root directory Copy project into workspace Browse to Mecrisp-Cube directory Generate code from the STM32CubeMX MecrispCube.ioc file: Project -> Generate Code Restore changed source files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :: $ git status {list of changed files} $ git restore {files to restore} Select the Build Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (Debug if you want to debug the project) and Build the project: :: Project -> Build Configurations -> Set Active -> Debug/Reelease Project -> Build Project Copyright --------- Authors ^^^^^^^ :: Matthias Koch - Forth on ARM Cortex M0/M4 - Mecrisp Stellaris Peter Schmid - Initial work - Mecrisp-Cube License ^^^^^^^ This project Mecrsip-Cube 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. Mecrsip-Cube 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 Mecrsip-Cube. If not, see http://www.gnu.org/licenses/. Acknowledgments ~~~~~~~~~~~~~~~ :: http://mecrisp.sourceforge.net/ Original Mecrisp project, Matthias Koch https://mecrisp-stellaris-folkdoc.sourceforge.io/ Mecrisp Stellaris Unofficial UserDoc, Terry Porter https://jeelabs.org/article/1612b/ Forth in 7 easy steps, Jean-Claude Wippler https://forth-ev.de/ Forth-Gesellschaft e.V. https://forth-ev.de/wiki/res/lib/exe/fetch.php/vd-archiv:4d2015-arm.pdf ARM-Sonderheft