Swiss Army knife of hardware hacking
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


BMII is an open source general-purpose board controlled by USB and fully programmable with Migen.

It is based on an Altera Max V CPLD and a Cypress FX2LP.

Example: a Pulse-Width Modulation module

Define the RTL

from bmii import *

class PWMIOModule(IOModule):
    def __init__(self):
        IOModule.__init__(self, "PWM")

        self.cregs += CtrlReg("WIDTH", CtrlRegDir.RDWR)
        self.cregs += CtrlReg("COUNTER", CtrlRegDir.RDONLY)

        self.sync += self.cregs.COUNTER.eq(self.cregs.COUNTER + 1)

        self.iosignals += IOSignal("OUT", IOSignalDir.OUT)
        self.iosignals += IOSignal("NOUT", IOSignalDir.OUT)
        self.comb += self.iosignals.OUT.eq(self.cregs.COUNTER < self.cregs.WIDTH)
        self.comb += self.iosignals.NOUT.eq(~self.iosignals.OUT)

Define RTL testbench (optional)

from bmii.ioctl.testbench import *

class PWMTestCase(IOModuleTestCase(PWMIOModule())):
    def test_basic(self):
        def gen():
            yield self.tb.iomodule.cregs.WIDTH.eq(42)

            for i in range(41):
                self.assertEqual((yield self.tb.iomodule.iosignals.OUT), 1)

            for i in range(214):
                self.assertEqual((yield self.tb.iomodule.iosignals.OUT), 0)

            self.assertEqual((yield self.tb.iomodule.iosignals.OUT), 1)


Connect the PWM to physical pins

class PWM(BMIIModule):
    def __init__(self):
        BMIIModule.__init__(self, PWMIOModule(), PWMTestCase)

    def default(cls, bmii):
        pwm = cls()
        bmii.add_module(pwm) += pwm.iomodule.iosignals.OUT += pwm.iomodule.iosignals.NOUT += pwm.iomodule.iosignals.OUT

        return pwm

bmii_modules = [PWM]

Build the design

$ bmii -v -m build all
[INFO] USB JTAG firmware built
[INFO] USB controller firmware built
[INFO] IO controller design built

Program the board

$ bmii -v -m program all
[INFO] [STAGE 1] Loading CPLD programmer firmware
[INFO] USB JTAG firmware loaded
[INFO] [STAGE 2] Loading CPLD design
[INFO] Probe: USB-JTAG-BM [2-2]
[INFO] Model: 5M570Z/EPM570Z
[INFO] IO Controller configured
[INFO] [STAGE 3] Flashing EEPROM
[INFO] USB controller firmware flashed
[INFO] [STAGE 4] Loading USB firmware
[INFO] USB controller firmware loaded
[INFO] Found device (002:017)
[INFO] Device fully tested

Set pulse width

$ bmii -v -m set PWM WIDTH 100

Simulate the PWM module

$ bmii -v -m simulate PWM
[INFO] Simulating PWM
Ran 2 tests in 0.156s



Getting a BMII

For now, this board is handmade and therefore not yet distributed. However, If you are interested in getting your own BMII but are not brave enough to solder it yourself, just sent me a short email.

If enough people manifest their interests to order a board, a small batch will be manufactured. The estimated cost would be approximately 50 euros per unit.