Features
Calculator
- RPN
- Keyboard layout similar to HP 42
- Stack 64 elements
- 10 registers
- 3 top elements (x, y, and z) are displayed
- Floating-point
- Single precision floating-point IEEE.754
- Elementary arithmetic
- trigometric and exponential functions
- Display modes: fixed, scientific, engineering (metric unit prefix)
- Integer
- Hex, decimal, octal, and binary number base
- Signed (2's complement) and unsigned numbers
- Elementary arithmetic
- logical and shift operations
- Forth programmable
Standard Mecrisp-Cube Forth Features
- 63 KiB RAM dictionary
- 128 KiB Flash Forth dictionary
- 50 KiB for C code
- Serial console USB CDC / BLE Terminal-IO
- Filesystem (FAT), Internal Flash drive 0:, 384 KiB
- Integration in STM32 Cube Ecosystem.
- Create C code from CubeMX for internal peripherals and use it in Forth
- Calling C Functions from Forth and vice versa
- RTOS
- 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
- USB-CDC for serial communication via USB, redirect console I/O like cdc-emit, cdc-key
- USB-MSC Device: The USB mass storage device class (also known as USB MSC or UMS). You can use your Forth system as a flash drive (also thumb drive [US], memory stick [UK], and pen drive/pendrive elsewhere)
- BLE 5.0 GAP Peripheral Role (STM32WB)
- 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.
- Floating-Point Unit FPU
- Support for the floating-point unit FPU, single precision for M4F MPUs and double precision for M7 MPUs
- CMSIS-DSP
- vi editor
- Real Time Clock RTC
- Watchdog
- Assertion and Logging
How to Use the Calculator
There are a few differences in operation compared to HP calculators.
This applies in particular to entering numbers.
Floating-point numbers must have an exponent e.g. 100e
, 3.14e
, 2.72e0
, -10e-12
,
or end in a metric unit prefix like 10k
, 270n
, 3.3u
.
ENTER reads the number and push it onto the stack. An ENTER without a number do not duplicate the x register (top of stack). If you want to duplicate, you have to use DUP. A stack element is always 32 bit, the content can be float or integer. You have to convert float to integer F→S if you want to use a float number in the integer mode or vice versa S→F.
Warning! If you enter a number with a . but without an exponent e.g.12.34
Forth interprets this as a double cell integer and put0
to the x register and1234
to the y register.
R↓ is actually the Forth word rot
, z→y, y→x, x→z.
STO and RCL takes x as register index 0..9.
Caution! If there is an error, the entire stack will be erased. No error message is showed on display, but you can see the error message in the terminal.
How it Works
The idea behind this is to use as much of the Forth interpreter as possible.
There is already a data stack, but with 64 elements and not only x, y, z, and t registers.
The calculator keyboard acts as an ordinary keyboard (terminal), but one key can send several characters (string),
e.g. the key COS sends a string " fcos\n"
. The interpreter executes the float cosinus on the top of the stack.
After the successful execution of a line, the stack content is then shown on the display.
Digits (0..9, A..F) are forwarded to the display and are interpreted after hitting the ENTER key.
If you connect a terminal and hit the TERM key, you can see how the interpreter works.
For implementation details see
About Forth
Forth is an interactive and extensible language, with built-in lexical analysis (tokenizer, parser) and interpreter/compiler, needs less than 20 KiB Flash and 4 KiB RAM, unbelievable for a self-contained (self-hosted) system.
Forth is perfect for embedded systems where some sort of user interactivity like CLI and extensibility (at runtime)...
Read more »
Excellent, excellent work!
Consider an eink display. If my HP42 has a failing, it is that the display is rather dim. Eink is both readable, and has a better absolute reflectivity than (say) sharp memory LCD, as well as zero standby current.
I would use decimal maths. There is simply no need for speed in a calculator, but on the other hand the binary/decimal errors are annoying. (I use Free42 in decimal mode).
I would also like my HP42 to be a numeric / calculator keypad for my computer. I day dream of getting the new Framework laptop, and having an HP42 numeric keypad in it.