Using the TKM32F499GT MCU


Last Update: Feb 26, 2021 @ 10:57

This is an Application Note that investigates how to use the TKM32F499 (a.k.a TK499) MCU on a “Smart LCD with WiFi” board.

News: 26-Feb-2021 We have ported and greatly extended the sample app code to a generic ARM toolchain IDE. We can now build apps using a TK499 Template project files set . Sample apps for GPIO, ADC, LCD display with multiple fonts and graphic primitives set, Capacitive Touch (see snapshot below), and FreeRTOS (V9.0.0rc2). The USB CDC-UART and USB HID are now both working.

We have source code to set up the Wi-Fi communications via the ESP8266 device using the UART2 port. Some minor code porting issues were handled. Now getting to know the EXP8266 ‘AT’ command set.

Here’s some snapshots of the CDC-UART app (Endpoints changed), Backlight PWM app, USB-HID app progress, and the FreeRTOS demo.

Here’s the current status Virtual MSD that assigns a chunk of SDRAM for a storage disk.
The main benefit is the creation of the USB MSD initialization code. This can be used to provide possible future support for the SD Card.
Original configuration was EP1, EP2 and EP3. We can build either configuration as needed.
The intent is to create a USB Composite HID-CDC device. HID development is in progress.
This is the second screen that echoes the characters entered on the CDC
terminal window. For demonstration purposes the character hex is displayed
plus the x-coordinate for that character. The backspace key is supported.
The LCD backlight can be toggled on or off via the APP switch on the back of the board.
Touch regions set a percentage brightness, or variable by sliding left (reduce) or right (increase)
The USB- HID support identifies itself to the Windows, but there is still some work to do.
Once these issues are solved we will be able to write control and graphics to the board using PiXCL 20 apps.
Supported fonts are Normal and Bold 10,12,14,16,18 20 and 40 points.
Graphics include lines, and geometric shapes outlined and filled.
More graphics will be added in the next few days.
Here’s a snapshot of the Capacitive Touch demo app.
The screen supports one to five points, and display in
red, green, blue, yellow and cyan respectively.

We located this interesting 2020-manufacture board from a Chinese supplier, and ordered two to evaluate. We have obtained the board schematic and a quantity of technical documents, mostly in Chinese with some English added. We have translated relevent portions of the 455 page TK499 mcu User Manual and compiled it into a CHM file.

The module consists of an 800×480 LCD, and a controller board with a 240MHz MCU, substantial memory, plus an ESP8266-12F WiFi module.

The module controller circuit board, with the ESP8266 WiFi module top left.
There is a QSPI 16MB Flash chip right of the TK499 chip.
Our intention for the 800×480 LCD display is something like this.

Why is this module interesting?

The module has an adequately high resolution LCD, Capacitive touch (rather than the obsolescent Resistive), a fast MCU, plenty of memory, and most importantly, the WiFi module. This makes the module suitable for Internet of Things (IoT) applications. The WiFi module (with appropriate firmware loaded) appears as a LAN node with a module-unique MAC, and an IPv4 DHCP address set by the LAN router. It presents a server with user definable web pages. The server could also include MQTT (a.k.a “mosquito”) secure communications.

The module hardware is inexpensive, but it certainly requires substantial work to make it a commercial product. See below for more on this.

Technical Details, Issues and Questions

The TK499 is made by a Chinese company, Haojurun Technology in Shenzhen, that produces products for badge-engineering OEMs. The 168MHz STM32F429 chip is similar in some respects, but there many differences too.

The TK499 is based on the ARM Cortext-M4 core, built in an LQFP128 package. Noted differences:

  • 240MHz HSI system clock, derived from a 12MHz crystal oscillator.
  • 32.768 kHz LSI clock is built-in, not external like ST chips.
  • 16MB of QSPI Flash rather than Flash within the MCU.
  • 8MB of SDRAM within the MCU package. See below.
  • The TK80 block that provides high speed 24-bit (RGB888) access to the LCD hardware.

A set of Keil MDK projects for the board have been successfully ported into the generic ARM toolchain.

Where is the SDRAM?

In the TK499 User Manual and other documents, it’s stated that the 8MB of SDRAM is built into the chip. This is uncommon but also technically feasible, because in silicon SDRAM is physically smaller SRAM. The confusion lies in the a block diagram that shows SDRAM as external memory. See the image below.

A TK499 Data Sheet states “8M bytes 32-bit SDRAM  (Built-in using stacked seal method)” which is assumed to mean the MCU ceramic package contains two silicon chips i.e. the SDRAM is the second chip, and hence considered as “external” to the MCU. The board also has an external 16MB Flash chip connected to the MCU QSPI.

What is SDIO1 usable for?

SDIO2 is used for the SD Card interface and is repeated on the module P1 edge pads. SDIO1 signals are also present on module P4 edge pads, as shown below.

Section of the TK499 schematic showing SDIO1 pins, and alternate functions.

Adding an external second SD device is, well, an odd idea. It may be that this can be configured as an interface for I2S devices. SPI4 pins are present, and can also be used for external devices.

Making a Commercial Product

Software / Firmware Issues

  1. Conversion of Keil code base. This code base is somewhat minimal, but most of the necessary CMSIS code for the TK499 is present.
  2. LCD initialization firmware. Example code exists.
  3. USB-FS Device configuration.
  4. ESP8266 firmware loading.
  5. How much Flash is in the ESP8266-12F?
  6. TK499 module DFU loading.
  7. How is the flash_download.exe utility used?

Partial Software / Firmware Answers

Soon after starting the board firmware evaluation we created a USB virtual serial port kit using supplied 4-wire kits to connect to the USART1 and UART2 ports. Most of the simple sample apps write information to USART1. The port connectors are surface mount, 1.50mm pitch, and require care to insert the header into the housing.

Do NOT try to push the header into the housing: SQUEEZE from both sides.
When the header is fully inserted into the housing it appears as shown.

SW Issue #1: The linker script has to be editted with the various FLASH and RAM sizes and other objects present in startup_tkm32f499.s. The FLASH and RAM start addresses and SIZE values in the MEMORY section have been identified.

For the TK499, a few changes are necessary
_estack = 0x70220000 + 0x5DFFFF /* end of ram */
...
MEMORY
{
  RAM (xrw) : ORIGIN =  0x70020000, LENGTH = 0x200000
  FLASH (rx) : ORIGIN = 0x70220000,  LENGTH = 0x5DFFFF
}

The LENGTH values are the 16MB QSPI Flash, and the 8MB SDRAM. The numbers above may refer to an earlier TKM evaluation board. The latest result is that the project now builds with no errors, creates a .elf and a .bin file.

SW Issue #2: The TK499 contains a LCD-TFT controller and is connected directly to the LCD via a 45 way flat-flex cable i.e. the LCD module does not contain a parallel interface chip like earlier Decaf boards. The LCD-TFT controller outputs RGB24 plus all necessary control signals including HSYNC, VSYNC and PCLK to drive the display. The controller is included in the TK80 + DMA. Sample code to configure TK80 / LCD-TFT is available. The LCD hardware is initialized by a stream of around 150 SPI Command/Data bytes. Thereafter pixel data is updated via the TK80 24-bit data path.

SW Issue #3: The board has to appear as a HID that supports the Decaf IOC sensor / control / graphics command set. If the SD card is to be supported as well, then the USB becomes a composite HID / MSD. The MSD could appear to the host as a disk drive which can have file I/O. The board firmware would have the capability to read these files (e.g. images, icons, command scripts) and process them.

Related to the HID sensor / control / graphics command set, the WiFi connection would also handle the sensor / control / graphics commands from a networked source e,g, a MQTT publisher or subscriber node.

SW Issue #4: The ESP8266 module is preloaded with the industry standard AT command set. A networking app loads sequences of AT commands via the UART2 Rx and Tx ports.

SW Issue #5: The ESP8266-12F has 4MB of flash.

SW Issue #6: Using a push button sequence, the board is configured to Boot Loader mode which presents the USB as a Mass Storage Device. Files are copied to the MSD, and the boards ROM firmware copies it into the 16 MB Flash memory. The board then resets automatically and the new app is executed.

SW Issue #7: The utility flash_download.exe is obsolete and is no longer useful. It can be deleted.

There is a bug in this demo app that immediately overwrites the center icons, as follows.

The EMwin sample code for the TK043F1569 LCD includes a TK499.bin binary that loads, but the LCD display is not functional. This is NOT the app for the boards received. There is another EMwin sample for the TK043F1168 LCD that has a TK499.bin that does start the display correctly. Examination of the two code bases has identified the difference.

OEM Capacitive Touch Demo. We have now built an updated version.

Another sample app demonstrates the multi-capacitive touch capabilities of the board. For touches 1-4 the last touch becomes Red, Green, Blue and Yellow. Five touch (not shown) draws in Cyan.

More to add

Hardware Issues

  1. External 5Vdc PSU. External VBAT location if required. Edge connector is required.
  2. Setup for DFU mode, or alternatives. Is SWD supported?
  3. Possible external 32kHz crystal if needed.
  4. Address of Cortex-M4 unique serial number, expected to be the same as ST chips.
  5. Adding, for example, surface-mount connectors to the module edge pads.
  6. Identify the module edge connectors, and create test / support hardware wiring and components.
  7. Is a secondary I/O board needed? How is this to be connected?
  8. What does the USB port need to work?
  9. How many ADC channels are supported?
  10. How many usable GPIO ports (sensors and controls) are available?
  11. Plastic or metal enclosure.
  12. Where is the Power On LED2? Any other schematic changes?
  13. More to add.

Partial hardware answers

HW Issue 1: There are three pairs of edge pads (0.10″ pitch) for GND, 3V3 and 5V. The preferred solution is a surface mount connector.

HW Issue #2: Boot Loader setup.

There are three buttons: BOOT, RESET and APP. The BOOT button state is used to set the boot address, aliased to ROM or SDRAM.

RESET + BOOT, release RESET then BOOT. This causes the board to switch the USB-FS port to a STMicroelectronics vendorID / productID of 0x0483 / 0x5720 which is a Mass Storage Device. The board is now in Boot Loader mode. The reported available capacity is 8MB. This is NOT the SD card or the 8MB SDRAM, rather it is 8MB of the QSPI 16MB external chip. When the board enters Boot Loader mode the Flash memory is cleared, which is why the Demo app no longer works. The Windows Device Manager lists the MSD as “TK499 QSPI”. This was verified by copying a file to the device. When the power is cycled, this file has disappeared. The board blue LED is lit, which indicates that the MSD is active.

HW Issue #3: According to the TK499 User Manual, the 32.768kHz oscillator is built into the chip. Examining the boards here indicated no need at present to add external clock circuits.

HW Issue #4: Serial Number. The manufacturer advises that no serial number is present in the TKM32F499GT. There is a unique serial number (the MAC address) in the ESP8255 and another in the 16MB QSPI Flash chip.

HW Issue #8: USB. The connector (USB-2 Micro-B) uses VCC, USB_DM (PA12), USB_DP (PA11) and GND. USB_DM (usually) requires a 5V pull-up resistor for a device to be recognized by a host. The board provides an internal pull-up that requires no firmware control. Tests indicate this is the case, as we have CDC, HID and MSD apps running.

HW Issue #9: ADC Ports. The TK499 MCU supports one ADC with six multiplexed input channels (#0-5). The circuit board design and schematic list two ports only, ADC4 and ADC5 on edge connector P10. The other ports, ADC0 – ADC3, are used by the TouchPad controller built into the TK499 chip.

HW Issue #12: The schematic shows a LED is powered by the 3V3 supply voltage. No LED can be identified on the board. Resistors R29 and R30 are listed as 10K, but are actually 5K1.

Development Steps

1: Verify the module hardware with the schematic

The various module edge pads are mostly known, and now the modules have arrived they have been fully verified and documented. All known GPIO pin assignments have been documented.

Identify the various devices and blocks in the TK499 memory map. DONE!

2: Board Support Package

The BSP contains all the code and functions to configure the TK499 core with the 240MHz clock and peripheral devices. This is the RCC, RTC, UART/USART, GPIO, USB and the LCD/TK80 initialization. Most of this code is present in the basic Keil projects. Three exceptions are that

  • UART1 only code is present, so USART2 and USART3 have to be written.
  • Another is that the LCD backlight control is currently ON/OFF only. Code for TIM2–>Ch2 PWM frequency to enable variable backlight levels has been located. A Backlight PWM sample app is in development, and uses touch control.
  • Activating the USB port is now completed with a USB CDC demo running. The next step is to implement a HID with graphics support. We may make this a composite HID-CDC. We also have a USB MSD sample app that creates a USB disk in the SDRAM.

This BSP code base will be used for all subsequent development.

3: Simple GPIO Tests

Using the sample code base as updated, simple tests of the GPIO (e.g. flashing the board LED) tests that the MCU is running, data can be written to the UART1 and display on a terminal app, and that the LCD is initialized and can display simple graphics.

4: Advanced Peripheral Tests

Testing of the USART2 I/O that connects to the ESP8266 is possible as the RX/TX data lines are available on board P6 connector.

5: Initial USB-FS Configuration

Assign an HID VID/PID and set up the TK499 USB port with the basic Decaf-compatible support (e.g. returning chip serial number, memory size, LCD dimensions)

6: ESP8266 Operations

The TK499 schematic shows USART2 RX/TX (also available on connector P6) as the communications method between the MCU and the ESP8266. Sample app code uses the USART2 to load control using the industry standard AT command set.

Still being investigated is how to integrate the necessary server pages.

7: Specification and Development of Utilities

Decaf USB sensor/control/graphics command set, Server page uploading, MQTT support.

more to add


Interested in this project and the documents we’ve created? Contact us and ask for a copy.