0 votes
by Alex Caledin (120 points)
- as I read various forums, I stumble over people complaining about difficulties with I/O control when using Forth on the Raspberry! So please do reassure me so I could (hopefully!) use the VFX Forth rather than Assembler for the control.

2 Answers

0 votes
by Stephen Pelc (3k points)
Once the file Examples/Lin32/rpi-gpio.fth has been compiled by a root (sudo) user, you can access the GPIO registers directly.

In my "ample spare time" or when I get back to it, I/we will write a higher level GPIO pin driver such as the one we provide with the cross compiler.
0 votes
by Bart Nelson (380 points)

The 'correct' answer is to write a Linux kernel device driver for the GPIO/I2C/SPI/.. peripheral and access it through userspace. However, this is hard work.

The approach taken below (and also libbcm2835 https://www.airspayce.com/mikem/bcm2835/) is to access the memory device /dev/mem directly - is a bit of a hack but quick and easy. See the comment about libbcm2835 in the Buildroot Config:

WARNING: the opinion of the Buildroot developers is that such library is a complete abomination as it entirely works around the standard Linux interfaces to access GPIOs, I2C, SPI busses or other IOs. The library directly remaps the hardware registers in user-space, completely bypassing what the kernel drivers are doing, and potentially conflicting with them.

You takes your choice!