embello

Embedded software from JeeLabs

Embello Home Page
Hardware Documentation
Forth Library Documentation

HAL for STM32L0

The Hardware Abstraction Layer for STM32L0 microcontrollers defines utilities to make code more portable across several architecture variations.

API

: 32MHz ( -- )  \ set the main clock to 32 MHz, using the PLL
: 16MHz ( -- )  \ set the main clock to 16 MHz (HSI)
: 2.1MHz ( -- )  \ set the main clock to 2.1 MHz (MSI)
: 65KHz ( -- )  \ set main clock to 65 KHz, assuming it was set to 2.1 MHz
: hsi-on ( -- )  \ turn on internal 16 MHz clock, needed by ADC
: hsi-wakeup ( -- )  \ wake up using the 16 MHz clock
: only-msi ( -- )  \ turn off HSI16, this disables the console UART
: systick-hz ( u -- )  \ enable systick interrupt at given frequency
: micros ( -- u )  \ return elapsed microseconds, this wraps after some 2000s
: millis ( -- u )  \ return elapsed milliseconds, this wraps after 49 days
: us ( n -- )  \ microsecond delay using a busy loop, this won't switch tasks
: ms ( n -- )  \ millisecond delay, multi-tasker aware (may switch tasks!)
: baud ( u -- u )  \ calculate baud rate divider, based on current clock rate
: list ( -- )  \ list all words in dictionary, short form
: chipid ( -- u1 u2 u3 3 )  \ unique chip ID as N values on the stack
: hwid ( -- u )  \ a "fairly unique" hardware ID as single 32-bit int
: flash-kb ( -- u )  \ return size of flash memory in KB
: flash-pagesize ( addr - u )  \ return size of flash page at given address

Variables

16000000  variable clock-hz  \ the system clock is 16 MHz after reset