Skip to content

Programming the C2C 64

jsanpe edited this page Feb 20, 2024 · 8 revisions

Introduction

The C2C-64 uses a MCU to setup the Video transcoding pipeline and to manage the UI through buttons, OLED screen and UART port. All this control code is part of the C2C firmware. This pages discusses the process to upload a new firmware to the C2C board.

MCUs in the C2C

Given the auxiliary nature of the MCU in this board, the project is not set on a specific MCU and will likely evolve in the future. So far, only two MCUs have been used, ATMega328P and ATMega328PB. Both are very similar and the main difference for the purpose of the C2C board is that the former greatly benefits from using an external crystal while the latter is in most circumstances ok running with the internal oscillator. In the future, it is likely that the C2C will start using the new generation of attiny MCUs, which feature similar capabilities but are considerably more affordable.

ICSP header

The ATMega family of MCUs can be easily programmed using the ICSP header. For space purposes, the C2C does NOT include the typical 2x3 header, but a 1x4 alternative that excludes Vcc and Gnd pins. It is important to note that the C2C works at 3.3V, so the ICSP programming device used needs to work at this voltage. I have found the Arduino DUE to be a fantastic way to program the C2C using the ICSP header using the ArduinoISP sketch included with the Arduino IDE. Remember to uncomment the #define USE_OLD_STYLE_WIRING directive and follow the connection diagram shown in the figure below:

Programming through the ICSP header

In a nutshell, pins 10 to 13 are connected to Rst, Mosi, Miso and Sck in that order. Gnd on the DUE should be connected to either the UART Gnd pin or the Oled Gnd pin. Vcc (3.3v) is not needed, the C2C can be directly powered from the Power jack. Alternatively, the 3.3v pin of the DUE can be connected to the Oled Vcc pin (in this case, do not power the C2C through the jack).

In general, ICSP programming is only needed to burn the fuses and the bootloader. There is a specific environment in the provided platformio configuration file to this end. Once fuses and bootloader are transferred to the MCU, the recommended procedure to upload a new firmware is through the use of the UART port.

Use an ESP8266 / ESP32 as ISP (guide written by ezcGman)

Arduino provides a sketch that you can load (basically) onto every device that runs the the Arduino framework, so not only an Arduino DUE, but also the famous Espressif MCUs. You just need to change a few pins, depending on the board you use. You can use whatever "version" of the ESP out there you want (the famous NodeMCUs or D1 Minis, or any other ESP you have with an USB-To-Serial interface connected to it):

  1. Download, install and open Arduino IDE
  2. Open Arduino IDE and navigate to File -> Examples -> ArduinoISP
  3. First: The sketch uses the default SPI pins for the board you compile it for, so we don't even need to touch those. But we need to select different pins for the LEDs it's trying to access on the Arduino boards. Those pins are not accessible on an ESP, so the sketch will crash. It doesn't really matter what you change them to, as long as it's an accessible GPIO. But let's do that together: So go and find the macros "LED_HB", "LED_ERR" & "LED_PMODE". Let's change them to 16, 5 & 4. And to have the wiring a bit more convenient (at least on the NodeMCUs), let's change the "RESET" macro/pin to 15.
  4. Now, get your ESP, connect it via USB and flash the sketch to it (remember to select the correct board under Tools -> Board!). It should just flash nicely!
  5. Disconnect your ESP from USB again, and hook up the c2c to it (c2c -> ESP):
    • RST goes to GPIO 15 (or D8)
    • MOSI goes to GPIO 13 (or D7)
    • MISO goes to GPIO 12 (or D6)
    • SCK goes to GPIO 14 (or D5)
    • GND goes to any GND pin (important, don't forget!)
  6. Re-connect the ESP via USB, power up the c2c (it's advised to NOT do that through the ESP. You can, but the ESP is not designed for that. Rather use an external PSU for the c2c).
  7. Open the c2c repo in VS.Code and make sure you have platformio installed inside VS.Code. Open the "platformio.ini" file and find the [env:fuses_1R3]. Change the USB port there (The -P option), if necessary (e.g., if you're on Windows change it to whatever COM-Port the ESP is connected to, e.g. "COM4" (all caps letters!).
  8. Open platformio from the left hand menu. Find the "fuses_1R3" task and run the "Set Fuses" and "Burn Bootloader" under "Platform".

You're done :)

Note: You can even use other Arduino based MCUs, you just need to set the correct pins. More info here (the article only covers Arduino board, but not the ESP; hence I wrote it down here): https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP/

UART port

The C2C project uses the MiniCore bootloader in combination with both ATMega328P/PB. The bootloader is executed when the MCU first resets, and given the right signals in the UART port during the first seconds after reboot, it is able to accept a bitstream and flash the MCU with new firmware.

Similarly to the ICSP programming method, the repository includes a platform.io project that includes an environment to program the MCU with minimal supervision. For this method to work you will need a FTDI (or similar) USB to Serial dongle able to work at 3.3V. The UART port is accessible on one of the sides of the board, even with the case fully closed. The accessible pins are, from left to right: Gnd, RTS, Rx, Tx. The connection between the C2C and the dongle is the same described to access the menu system: Gnd<->Gnd, RTS<->RTS, Tx<->Rx, Rx<->Tx.

Note that RTS signal is required to reset the MCU in programming mode. I have noticed that many USB to serial dongles lack the RTS signal, which makes the programming procedure not as straightforward. In this case, you would need to manually short RTS to ground momentarilly to reset the MCU and send the programming bitstream in the ~1.5s following the reset event.

Clone this wiki locally