C · Linux + remote LEDs
Reverse a moving light at each end of the board
Online version: https://fpga.labsland.com/altera/embedded-systems/lab-01/part-02/
Physical DE1-SoCYour computer
A single red light should travel to LEDR9, turn, and come back. In the starter it jumps across the board. Repair one C function, test its register writes on Linux, then run that same function on a processor inside a remote FPGA.
You can try the starter immediately with the included FPGA design and access to the LabsLand DE1-SoC Verilog Online Editor. To change it, you’ll also need a C compiler, Python 3 and a RISC-V bare-metal GCC toolchain. The physical exercise uses the board’s standard LED bank and camera. xPack RISC-V GCC · LabsLand DE1-SoC laboratory
Predict the turn
Number the lights from LEDR0 on the right to LEDR9 on the left. Write the expected ten-bit word in hexadecimal for ticks 0, 1, 8, 9, 10, 17 and 18. How many ticks separate two visits to LEDR0? Choose one LED in the middle and identify the two ticks on which you would see it.
If you have the C compiler ready, test your prediction in the terminal. You can also take your prediction straight to the board and run this trace afterwards.
cc -std=c11 -O2 -Wall -Wextra starter/sweep.c -o sweep
./sweep --trace
The left column is the tick and the right column is the register word. Compare tick 10 with your prediction. Keep the starter long enough to see the fault on the real board.
Run the starter in the FPGA
For a first board run, open the included starter FPGA design. You can paste it into the editor straight away. To generate it yourself from the supplied C, run this command.
On Windows with the Python launcher, use py -3 wherever a command starts with python3.
python3 resources/build_cpu.py starter/sweep.c sweep_cpu.v
The builder uses riscv-none-elf-gcc and riscv-none-elf-objcopy from your PATH. With another compatible command prefix, add it to the command, for example --prefix riscv64-unknown-elf-. The toolchain must support RV32I with the ILP32 ABI. Your C program is compiled to machine instructions and loaded into the FPGA design.
In the DE1-SoC Verilog Online Editor, select the Standard interface. Choose New, name the file sweep_cpu, paste the generated file, select it as the top level, and choose Synthesize → Upload to FPGA. Wait for the board camera to update. With SW9 and SW8 down, watch the light for two complete sweeps. Does it reverse at the far end?
Raise SW8 to examine one tick at a time. SW4 through SW0 select the tick in binary; SW0 has weight 1. Keep SW9 down. Try 01000, 01001 and 01010 in order. Record the lit LED at ticks 8, 9 and 10. Raising SW9 clears the LED register and resets the timer. Confirm the whole row goes dark.
Repair and repeat
Edit only led_word in starter/sweep.c. Choose a repeating sequence that visits each end once per turn. Recompile both versions using the commands above. Run the new trace, paste the regenerated Verilog into the editor and upload it again.
With SW8 up, test ticks 9, 10, 17 and 18. Lower SW8 to observe motion. Raise SW9 to stop and clear, then lower SW9 and watch where the light starts. Submit the register words for the two turns, a before-and-after observation at tick 10, the result of the clear test, and the identifier shown for your remote board.

This UW board is holding tick 10 after the repair. LEDR8, one place in from the left end, is lit.
Explain the two builds
The Linux executable prints the words from your C function. In the FPGA, a FemtoRV32 processor runs the compiled function, reads the switches and writes the physical LED register. The automatic tick advances every quarter second. A separate --board entry in the Linux source targets the DE1-SoC Computer HPS image. It needs that exact hardware system and an assigned ARM Linux console. Use --trace on your own Linux computer.
FPGAcademy exercise · Exercise notice · LabsLand source license · FemtoRV32 license
