Could not believe I could be so happy with som blinking LED's. Run today two test for GPIO out and PWM. I compiled a very simple version of the card, just a few GPIO out (located next to a GND pin for easy connection) and a single PWM. The configuration file for the board can be found
here
1. GPIO out - blinking a LED
Code:
# This file assumes that the firmware located in ../firmware/5a-75e-hello-gpio/ is loaded
# to the FPGA. The corresponding json-configuration is loacted in the ../../examples
# folder. Modify paths as required for your setup!
#
# USAGE:
# halrun -I test_gpio_blink.hal
loadrt litexcnc
loadrt litexcnc_eth config_file="/home/pi/5a-75e-hello-gpio.json"
loadrt threads name1=test-thread period1=50000000
addf test_PWM_GPIO.write test-thread
loadrt siggen
addf siggen.0.update test-thread
net blink siggen.0.clock => test_PWM_GPIO.gpio.j1:1.out
start
From this code I found out that I had to do a little bug-fixing. My driver assumed the address of all RW-registers started at 0x00, but by accident they started at 0x04 because I put the GPIO in at the wrong location. Solved this in the firmware by switching some statements in the MMIO. Note to my self: always double check whether the registers in the firmware and the driver are in exactly the same order.
The way I found this bug was the fact that I could blink the LED by using
litex_server and
litex_client on the PC. This takes the actual register addresses into account. This showed that in principle there was nothing wrong with the FPGA, bu there was an communication issue between the firmware and the driver. From there the problem was readily spotted.
2. PWM - Knight rider
Code:
# This file assumes that the firmware located in ../firmware/5a-75e-hello-gpio/ is loaded
# to the FPGA. The corresponding json-configuration is loacted in the ../../examples
# folder. Modify paths as required for your setup!
#
# USAGE:
# halrun -I test_pwm_knight_rider.hal
loadrt litexcnc
loadrt litexcnc_eth config_file="/home/pi/5a-75e-hello-gpio.json"
loadrt threads name1=test-thread period1=50000000
addf test_PWM_GPIO.write test-thread
loadrt siggen
addf siggen.0.update test-thread
# The siggen function run from -1 to 1, we scale the PWM. NOTE: we could
# also scale siggen, but the goal is here to test PWM, not siggen.
# The formula is duty_cycle = (value / scale) + offset
setp test_PWM_GPIO.pwm.j1:2.scale 2
setp test_PWM_GPIO.pwm.j1:2.offset 0.5
net pwm-out siggen.0.sawtooth => test_PWM_GPIO.pwm.j1:2.value
start
Also in the PWM there was a small bug. The control registers were created two times, making it impossible to change them. Also fixed in the firmware and the LED was happily blinking.
Reading data
I've noted one bug in the driver. As soon as the
write-function is added to a thread, the driver breaks down. Somewhere in the process there is a mistake, making the driver to panic. Want to fix this issue this evening...
Edit: The board name is now part of the pin and function names. Was promised to
@cncwhacko. Updated the examples to correspond with current code.