I recently implemented the ability to handle HEX strings (it stores them as a 32-bit binary value) and now it's much easier to work with hardware.
As an example, I demonstrate how to turn on the blue LED on GPIOA pin 2:
: blue_led 0x40010800 @ 0xFFFFF0FF and 0x00000300 or 0x40010800 ! ; blue_led
This is a very simple and inelegant solution, but it works!
There's some documentation on how/why it works here, but essentially it boils down to:
- read the current GPIOA port config
- apply a mask to clear the 4 bits for pin 2
- apply the new pin 2 config
- store the new GPIOA port config
- execute the new word to turn on the blue LED
I think this shows the merits of Forth. It's possible to easily define more robust functions (words) which for example might take some arguments from the stack (ex: GPIO port, pin number, status), and then perform calculations on those values to set the new config - which could then be used to toggle any pin, etc. As long as you know the HEX address of the memory-mapped devices, pretty much all the hardware can be controlled and configured interactively.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.