# Can I use VHDL/Verilog to program a micro-controller?

I wanted to know if I can program any micro controller (not CPLDs /FPGAs) using VHDL/ Verilog? If so, what are the steps and the required tools for the same?

• Verilog/VHDL are hardware description languages. Instead on a microcontroller you must tell it what it has to do, in a "sequence" basis. (Even if there are some MCU that embed some programmable logic similar to CPLD/FPGAs). Oct 10, 2017 at 6:34
• Look into "C to HDL." Might find some stuff of interest.
– jonk
Oct 10, 2017 at 7:24
• The logical conclusion to programming a computer in VHDL is to program it in Ada. They are very similar, sharing common roots at the US Department of Defense. Nov 1, 2017 at 17:48

Not realistically, no.

These are language for describing hardware functionality, not ordinary programming languages naturally suited to a stored program computer.

In short, you could use them to make a processor or full microcontroller, but not really realistically to program one.

Strictly speaking, you can use these language to describe a memory, and that memory could contain instructions (such as for a processor also described by the code), but realistically, someone doing this would typically use a traditional assembler or compiler to generate that program, then use a tool to either convert it to initialization constants and pass that through the Verilog or VHDL compiler, or else inject those contents further downstream so that they end up in the resulting system simulation or hardware device, but without going through the first level parser of the verilog or vhdl compiler.

Although it would be extremely unusual to do so, you could potentially embody such a memory in an FPGA and use it to supply instructions to an off chip processor rather than an on chip one. Or if you wanted to be really absurd, you could write something for extracting memory contents back out to a programming format suitable for a traditionally PROM - but then why go through the Verilog or VHDL step at all?

Alternately, you can also use these languages to encode simpler models of computation, for example a state machine or even a state machine controlling an arithmatic data path - but those aren't microcontrollers in the modern usage of the word.

I guess if watching paint dry is really your thing, someone did manage to run Linux on an ATmega outfitted with a comical quantity of external RAM and simulating in software a more suitable computer architecture, and you could probably cross compile iVerilog for that simulated machine. So in theory, you could "run" some Verilog in simulation on a decent computer in turn being simulated by a lowly microcontroller - but simulation is slow even on a fast workstation grade computer.

• Instead of simulating the verilog on the MCU, a more efficient approach (both in terms of execution speed, development time, and required hardware resources) would be to use a tool that translates verilog programs to C (like this one), and compile the result for the targeted MCU. But it still probably requires writing significant pieces of code for gluing all that together.
– dim
Oct 10, 2017 at 7:28

Verilog and VHDL are hardware description languages, so they can be used to describe hardware on logic level. To "run" you HDL code you need to use a FPGA/ASIC or at least a simulator. A microcontroller (µC) is kind of a small processor, on which you can run software programs, compiled for the µC specific instructionset.

So no, you can not run Verilog or VHDL on a µC, but you can use the language to develop a hardware description of a µC. There are some free available for example the openMSP on OpenCores.

Interesting question. As others have stated, Verilog is intended for programming logic functions that are then implemented in an FPGA. However, like pretty much any language, you could write a simulator or compiler to allow Verilog to run on a microcontroller or microprocessor.

Most engineers use simulators to test their Verilog code before implementing on an FPGA. While slower and less efficient than an FPGA due to non-optimized hardware and hefty software stacks between your simulator and "bare metal," simulators are essentially "running" Verilog code as it seems you're trying to do. They probably express inputs and outputs differently (i.e. as traces on your display rather than voltages on an FPGA's pins), but that distinction is pretty trivial.

If you wanted to, you could design a library in something like C to interpret your Verilog code on the microcontroller or a compiler to translate that Verilog into machine code before flashing the microcontroller. However, this would take a significant amount of tool development work/time for no payoff. Designers use HDL's and FPGA's rather than microprocessors for very custom applications, speed, and power efficiency when it's not viable to roll their own silicon. You would lose all of those benefits if implementing Verilog code through some intermediate layer on your microcontroller.

On the other hand, this would be an incredible research/skill development project. You would emerge an expert on both the inner workings of the Verilog language and your micro of choice.