Library¶
Maths Library¶
Feb 2018, Andrew Palm, a mathematician, has created a square root, trig, and inverse trig functions for 64bit fixed point (s31.32) numbers library that should run on any Cortex M. Tested here on a STM32F051.
Note
If you haven’t used s31.32 fixed point numbers before, the (usual floating number) decimal point is replaced with a COMMA
Examples¶
4,0 sqrt f.
2,00000000000000000000000000000000 ok.
3000,02398 sqrt 6 f.n
54,772474 ok.
90,0 sin f.
1,00000000000000000000000000000000 ok.
0,5 asin f.
29,99999998090788722038269042968750 ok.
0,0 cos f.
1,00000000000000000000000000000000 ok.
0,5 acos f.
60,00000001909211277961730957031250 ok.
90,0 tan f.
0,00000000023283064365386962890625 ok.
45,0 atan f.
88,72696999576874077320098876953125 ok.
90,0 deg2rad f.
1,57079633558169007301330566406250 ok.
1,57079633558169007301330566406250 rad2deg 6 f.n
90,000000 ok.
Read Cortex M0 chip ID¶
Reads the chip ID of a Cortex Mo
Tested on a Cortex M0, may not work with other STM32 models
Download: f0-device-electronic-signature.fs
Example¶
stm32id
Die xy coords: 2752589
Wafer Number: 14
Lot_num ascii encoded [23:0]: 0x00413657 | A 6 W
Lot_num ascii encoded [55:24]: 0x20323336 | 2 3 6
40 word dictionary pager¶
Dict just pages the Dictionary words in a 40 word high single column. Press enter or the space bar to continue.
Example¶
dict
--- Mecrisp-Stellaris Dictionary, press any key to continue ---
stack-check.fs
sc
--- Mecrisp-Stellaris Core ---
2dup
2drop
2swap
2nip
2over
2tuck
...
Stack Check¶
Checks the Data Stack for leftover items, warns you if the stack > 0, then clears the Stack. Use it at the end of loops etc.
Example¶
stackcheck
*** Stack fault: there were ** 3 ** items left on the stack
Stack cleared
ok.
Print Register Contents with Legends¶
In svd2forth-v3 (not yet ready for release) I’ve separated the register legends from the memory map to allow customised legends for any MCU model. These provide a lot more information with the autogenerated register prints. These are hand edited in a simple text file, so if you have a favorite STM32Fxx MCU, you will be able to make them yourself.
A “rcc.” snippet. You can easily see that all GPIO’s are enabled as is USART2, but not USART1.
rcc.
RCC_AHBENR $005E0000
I I I I I F
T O O O O O L S
S P P P P P C I R D
C F D C B A R T A M
E E E E E E C F M A
N N N N N N E E E E
|2| |2| |2|1|1|1| N N N N
~~~~~~~~~~~~~|4|~|2|~|0|9|8|7|~~~~~~~~~~~~~~~~~~~|6|~|4|~|2|~|0
0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RCC_APB2ENR $00000000
D T T T U S
B I I I A S T Y
G M M M R P I S
M 1 1 1 T I M A C
C 7 6 5 1 1 1 D F
E E E E E E E C G
N N N N N N N E E
|2| |1|1|1| |1| |1|1| N N
~~~~~~~~~~~~~~~~~|2|~~~~~|8|7|6|~|4|~|2|1|~|9|~~~~~~~~~~~~~~~|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
RCC_APB1ENR $00020000
U
I I A S W T
C D P 2 2 R P W I T T T
E A W C C T I D M I I I
C C R 2 1 2 2 G 1 M M M
E E E E E E E E 4 6 3 2
N N N N N N N N E E E E
|3|2|2| |2|2| |1| |1| |1| N N N N
~|0|9|8|~~~~~~~~~|2|1|~~~~~|7|~~~|4|~~~|1|~~~|8|~~~~~|4|~~~|1|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 0 0 0 0