HardCaml Ain't Hard

Workshop

SPEAKERS

Ayush Shukla
Ayush Shukla

ABSTRACT

Workshop Overview

Hardware description languages like Verilog and VHDL have been around for decades, but the way we use them can still feel surprisingly old-school rather. They often come with limited type systems, low level abstractions, and testbenches that live separately from the hardware design itself.

This workshop takes a different approach with HardCaml, an embedded hardware description DSL built in OCaml.

The tentative slides can be viewed here. (Alternatively you can copy this link - https://drive.google.com/file/d/1HPOJTdnNCEGJLJh7pkv9usfVhQaYSNSF/view?usp=sharing)

Instead of writing RTL in the traditional way, we’ll be using OCaml’s type system and abstractions to build typed signal graphs, simulate circuits directly, generate portable Verilog, and finally run the designs on a real iCE40 HX5K FPGA using the completely open-source IceStorm toolchain.

What We'll Build

We’ll work through three practical examples:

  • LED Blinker : our introduction to clocks, signals, registers, and basic circuit structure
  • UART Echo : sending and receiving serial data while exploring state machines and reusable hardware components
  • PWM Dimmer : generating PWM signals to control LED brightness and putting our designs onto actual hardware

What We'll Cover

Along the way, we'll explore the core ideas behind HardCaml, including:

  • Signals and signal widths
  • Registers and clocked logic
  • Circuit construction
  • Native simulation
  • The Always DSL
  • Finite state machines
  • Functor-based hardware reuse
  • Expect-test based waveform regression
  • Verilog generation
  • The open-source FPGA workflow with IceStorm

You don't need previous FPGA or Verilog experience to follow along. Some OCaml experience is trivially useful.

The most important thing to understand is this:

You don't run OCaml on the FPGA. You use OCaml to design the hardware that the FPGA runs.

HardCaml essentially lets us use the tools and ideas we already value in modern software engineering with strong types, abstraction, reuse, testing, and composition, and bring them into hardware design.

By the end of the workshop, you'll have gone from a complete synthesis of ideas from hardware, and using your OCaml to leverage it to build something.