Upgrading to a new microcontroller (MCU) can provide benefits like better performance, more memory, and new features. However, it often requires porting existing peripheral drivers like LCD controllers to work with the new MCU. This article provides guidance on porting LCD drivers to new Cortex M0+ based MCUs.
Overview of the Cortex M0+ Architecture
The Cortex M0+ architecture is ARM’s most compact and energy efficient 32-bit MCU. It has a 32-bit ARM Cortex M0+ processor core, with features like:
- 32-bit ARMv6-M Thumb instruction set
- Up to 256KB flash memory
- Up to 32KB SRAM
- Single-cycle 32-bit multiplier
- Low power sleep modes
- Integrated Nested Vectored Interrupt Controller (NVIC)
The Cortex M0+ core is paired with various peripherals like general purpose I/O, timers, ADCs, and communication interfaces like I2C, SPI, UART, etc. There are many Cortex M0+ based MCUs from vendors like STMicroelectronics, NXP, Microchip, Renesas, etc.
Understanding Existing LCD Drivers
Before beginning the porting process, you need to thoroughly understand how the existing LCD driver works on the older MCU. This includes aspects like:
- How is the LCD controller interfaced – parallel, SPI, I2C etc.
- Which peripherals like GPIO, timers, DMA etc. are used by the driver
- Important settings like bus timing, pin mappings, interrupts, buffers etc.
- How LCD commands and data are sent
- Graphics operations like updating regions, pixel manipulation etc.
Having a clear understanding of these elements will make it easier to replicate the behavior on the new MCU.
Selecting the Right Cortex M0+ MCU
Picking the right Cortex M0+ MCU is important for easily porting the LCD driver. Important factors include:
- Interface support – I2C, SPI or parallel bus for connecting the LCD
- Number of GPIO pins to match LCD data and control signals
- Timers – for generating LCD control signals like EN, RD/WR etc.
- Availability of DMA, RAM, and other features used by original driver
- Package – should support integrating the LCD display
- Memory space for holding framebuffer and code
Vendors like NXP, STM32 and Microchip have Cortex M0+ MCU lines with LCD-specific drivers and hardened peripherals that can ease porting of some LCD interfaces.
Mapping Hardware Resources
Once the new MCU is chosen, next step is mapping the peripherals used by the LCD driver to resources on the Cortex M0+ device. Key mappings include:
- LCD interface pins to appropriate GPIO pins
- Timers, DMA channels, GPIO for generating control signals
- Interrupts for events like frame sync
- Memory allocation for framebuffer, graphics assets etc.
Some care must be taken to map resources that have the same capabilities. For example, map a 16-bit timer to a 16-bit timer, allocate enough memory for framebuffer etc.
Porting the LCD Initialization
The LCD initialization code handles the startup tasks of configuring the interface and getting the LCD controller ready. Key tasks here include:
- Enabling associated GPIO, timers, DMA in the MCU’s system/clock configuration.
- Setting up GPIO directions as per pin mappings.
- Enabling peripheral clocks.
- Configuring LCD protocol specific settings like SPI baud rate.
- Sending appropriate init commands to LCD controller.
- Setting graphics related information like resolution, color depth etc.
The MCU’s data sheet and reference manual will be very helpful for finding correct settings and replacement functions for the new device.
Porting the Display Update Process
The display update process has code for updating the framebuffer and transmitting pixels/commands to the LCD controller. These are key aspects in this process:
- Using DMA for fast framebuffer memory transfers.
- Generating LCD control signals like Chip Select.
- Sending LCD commands like setting column and page addresses.
- Transmitting pixel data.
- Optimizing performance with techniques like double buffering.
Try to reuse as much of the existing logic as possible. The hardware abstraction layer concept can help separate hardware specific code from generic driver logic.
Testing the Ported LCD Driver
Thoroughly test the ported LCD driver on the new MCU development board to validate correct working. Some key test cases are:
- Static graphics like shapes, lines – to verify basic LCD operation.
- Dynamic screen updates – animations, pixel manipulations etc.
- Different screen orientations – portrait, landscape etc.
- Power modes – check LCD works on wake up from sleep.
- Error conditions – incorrect init sequences, missing commands etc.
Compare results to expected behavior on older system. This will help catch any functional gaps or issues in the porting process.
Optimizing System Performance
With the basic porting complete, there are several areas that can be optimized for better performance:
- Utilizing the Cortex M0+ SysTick timer for scheduling screen updates.
- Using DMA capabilities for memory transfers.
- Enabling caches if available.
- Configuring LCD in asynchronous mode and using double buffering.
- Streamlining slow paths using newer instructions like hardware divide.
Profiling tools can provide insights on hotspots to focus optimization efforts. The Cortex M0+ idles efficiently when waits idle, helping reduce power consumption.
Conclusion
Porting LCD drivers to new MCUs while challenging, can be systematically achieved by thoroughly understanding current drivers, selecting optimal new hardware, mapping resources correctly, reusing proven code and testing exhaustively for full validation. Optimizations then can exploit new capabilities to further improve performance and user experience.