Introduction: Hack a CFA735/CFA835

About: Crystalfontz is a supplier of LCDs, TFTs, OLEDs, and ePaper. We offer support for all our products.

Do you have a project that needs a display, a key pad, and some memory, but the preloaded firmware on the Crystalfontz CFA735 or CFA835 module isn't quite what you're looking for? You're in luck - you can hack these modules to load custom firmware.

The CFA735 and CFA835 are versatile intelligent LCD modules. Both the Crystalfontz CFA735 and CFA835 are based on the CFA10052 hardware module, so during this tutorial the CFA735 and/or CFA835 will be referred to as the CFA10052. The CFA10052 can be reprogrammed to run your own custom firmware.

  • STMicroelectronics STM32F401 microcontroller
  • ARM 32-bit Cortex™-M4 CPU @ 84 MHz
  • 256K Flash, 64K RAM
  • 244 x 68 pixel backlit LCD
  • Sitronix ST7529 32 grayscale graphic LCD controller
  • Buck-boost switching supply allows wide supply voltage range
  • Separate switching LED brightness controllers for keypad and LCD backlights
  • 6 button backlit keypad
  • 4x bi-color (red/green) LEDs
  • USB2 interface
  • microSD card slot
  • 5 general purpose IO pins (GPIO's)
  • Multiple serial/SPI/I2C/CAN interfaces (depending on GPIO use).

This tutorial will show you how to replace the firmware that ships on a CFA10052 with new firmware that will:

  1. Display on the LCD an alternating grid, with current backlights, LCD contrast and keypad status information;
  2. Control the backlights and LCD contrast using the keypad.
  3. Change the color of the four LEDs from red to green in sequence.
  4. Enable the USART serial port on Header-1 pins 1 & 2 (115200 baud), and echo any received data.
  5. Enable the USB virtual serial port, and echo any received data back to the host.
  6. Includes, but does not demonstrate, uSD read/write file access.

Of course, you can write your own firmware and load it using these steps.

IMPORTANT NOTE:

The Crystalfontz CFA10052 hardware module ships programmed with a bootloader and CFA735/CFA835 firmware. The bootloader and CFA735/CFA835 firmware are not open-source, and cannot be copied off of the CFA10052 by the user, nor can they be programmed onto the CFA10052 by the user. If you end up wanting to revert to the CFA735/CFA835 firmware, you'll have to ship it back to Crystalfontz to have it reprogrammed.

Supplies

Step 1: Collect/Create Supplies

We recommend using the STM32CubeIDE to load and use this example firmware project. STM32CubeIDE is a free IDE based on Eclipse that has been modified by STMicroelectronics to include STM32 specific tools. The IDE can be downloaded on the STM32CubeIDE webpage.

To maintain the correct operation of the STM device configuration tool, you must only edit the device configuration tool created source-code between the matching "USER CODE BEGIN xxx" and "USER CODE END xxx" comment blocks.

Next, decide whether to contact us for a CFA10052 programming cable or to make your own. We're not going to go over making the cable in detail in this tutorial, but if you want to make your own CFA10052 programming cable, you can find the connections on the GitHub page, the best way to do this is to start with a sixteen pin ribbon cable and splice it to the cable for the ST Link.

Step 2: Erase Existing Firmware

If your CFA10052 module is loaded with the supplied CFA735 or CFA835 firmware you'll need to first erase the exiting firmware before installing new firmware. The flash memory is read and write protected and must be removed before custom firmware can be loaded.

There are two methods for removing the installed firmware:

  1. Disconnect the USB cable (or power supply) from the CFA10052 module.
  2. Connect the CFA10052 to the ST-LINK using the programming cable (see above), and the ST-LINK to the host PC.
  3. Hold the up & down keys on the CFA10052 while plugging the USB cable into the CFA10052 (or power supply).The CFA10052 should now show the Crystalfontz Bootloader screen.
  4. Run the STM32 ST-LINK Utility. In the "Target" menu, open the "Option Bytes" window. In the "Read Out Protection" box, select "Level 0". Click Apply.The Crystalfontz firmware has now been removed and any custom firmware may now be programmed.

Alternative method (if you cannot enter the Crystalfontz Bootloader by holding keys):

  1. Disconnect the USB cable (or power supply) from the CFA10052 module.
  2. Connect the BOOT0 test-point (a small pad on the back of the CFA10052 module, near the H1 connector) to 3.3V or 5V.
  3. Connect the CFA10052 to the ST-LINK using the programming cable (see above), and the ST-LINK to the host PC.
  4. Power on the CFA10052 (or connect it to USB power). The display should be blank.
  5. Run the STM32 ST-LINK Utility.In the "Target" menu, open the "Option Bytes" window.In the "Read Out Protection" box, select "Level 0". Click Apply.The Crystalfontz firmware has now been removed and any custom firmware may now be programmed.
  6. Connection of the BOOT0 pin to 3.3V/5V is no longer needed.

Step 3: Compile and Load Your Firmware Onto the CFA10052

Once the Crystalfontz supplied firmware has been removed, you're ready to compile and load your own firmware. For the purposes of this tutorial, we have supplied some alternative firmware that gives keypad control of the backlight brightness and display contrast.

To compile the firmware:

  1. Open the STM32CubeIDE

  2. In the File menu, choose Import, then "Import Existing Projects Into Workspace".

  3. In the root directory box, select the directory of this example firmware.

  4. Click the Finish button.

  5. In the Project Explorer, select the cfa10052_example project, then open the Src, and "main.c" file.

  6. In the Project menu, select "Build Project".

To program and run the firmware on the CFA10052:

  1. Disconnect the USB cable (or power supply) from the CFA10052 module.

  2. Connect the CFA10052 to the ST-LINK using the programming cable (see above), and the ST-LINK to the host PC.

  3. Connect the USB cable (or power supply) to the CFA10052.

  4. Make sure the firmware project has been built (see steps above), and "Binaries" appears under "cfa10052_example" in the Project Explorer.

  5. If "Binaries" isn't visible, right-click the "cfa10052_example" project and select Refresh.

  6. Select the Run menu, then "Debug Configurations".

  7. In the debug target types selection box on the left, Right-Click "STM32 Cortex-M Application", and select "New Configuration".

  8. A configuration window will be shown. The default settings are OK. Click the Apply then the Close button.

  9. In the Run menu, select "Debug As", then "STM32 Cortex Application". STM32CubeIDE should now connect to the ST-LINK, and upload and run the firmware on the CFA10052.

The above steps are only required on loading the project for the first time in STM32CubeIDE. After firmware source-code changes have been made, only re-building the project (Ctrl-B shortcut) and programming the CFA10052 (F11 key shortcut) are needed.

Firmware can also be loaded via any of the normal STM32 bootloader methods (debugging is only available using the SWD interface and a ST-LINK). For example, if using serial connection, USART1 may be used (RX=H1-Pin1 and TX=H1-Pin2).For more detailed information about the STM32 bootloader and interfaces, see the PDF here.

Step 4: Licences

Crystalfontz-supplied source-code is provided using The Unlicense, a license with no conditions whatsoever which dedicates works to the public domain. Unlicensed works, modifications, and larger works may be distributed under different terms and without source code.See the UNLICENCE file, or unlicense.org for details.

STM32CubeIDE created source-code and STMicroelectronics libraries are Copyright (c) 2019 STMicroelectronics. All rights reserved. The software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use these files except in compliance with the License. You may obtain a copy of the License at opensource.org/licenses/BSD-3-Clause.