TWR-K21D50M lowpower Patch

File uploaded by Derek Snell Employee on Mar 13, 2013Last modified by Derek Snell Employee on Aug 28, 2013
Version 2Show Document
  • View in full screen mode

Rev0.2 - 8/28/2012


NOTE: for an update to this patch for MQX v4.0.2, see TWR-K21D50M lowpower MQX Patch for v4.0.2


This patch addresses several issues with using the lowpower example in MQX on the twrk21d50m BSP. The lowpower example is provided to demonstrate the MQX Low-Power Manager (LPM) driver, and change low-power modes on the K21 board.  The BSP provided in MQX v4.0 has several issues interfering with these low-power modes, and the lowpower example.

To use this patch, copy the patch directory into the MQX v4.0 root directory.  The patch will over-write some existing files in the MQX installation.  The changes addressed by this patch include the following:

  1. User_config.h
    • MQX_ENABLE_LOW_POWER macro enabled.  Required for LPM driver and lowpower example.
  2. VLPR Clock configuration dividers
    • Updated the clock dividers in the SIM_CLKDIV1 register to set the core/system/bus clock frequencies at 2MHz as expected, instead of 1MHz.  Modified Cpu_SetClockConfiguration() in bsp_cm.c.  Fixes issue in lowpower example where characters printed to terminal are incorrect baud rate in VLPR mode.
  3. UART settings for LPM Operation modes
    • BSP has incorrect settings for UART2 (TTYC) for the LPM operation modes.  Causes UART2 to be disabled in Run mode when MQX_ENABLE_LOW_POWER is enabled, which causes a bus error exception, stopping the BSP startup before main() is entered.  Modified init_sci.c
  4. Over-writing internal oscillator trim value
    • The BSP was not using the factory trimmed settings for the internal oscillators.  The BSP is configured for a user-trim value to be stored at 0x3FE and 0x3FF.  The BSP checks these flash locations, and if not erased having 0xFF, it writes these locations to the MCG trim registers.  The issue is the vector table filled the vector location at 0x3FC, fooling the BSP into thinking user-trim value was present.  Modified vector.c to replace final vector with 0xFFFFFFFF, forcing BSP to keep the factory trim settings.  Fixes issue in lowpower example where characters printed to terminal are incorrect baud rate in VLPR mode.
  5. Disabled clock monitor when entering a stop mode
    • BSP had clock monitor enabled in BSP, and did not disable before entering a stop mode.  This prevents the lowpower example from recovering properly from LLS mode. Modified _lpm_set_cpu_operation_mode() in lpm_smc.c to clear the CME bit before entering a stop mode, and then restore CME setting after waking up.
  6. Disabled SPI0 peripheral before entering a stop mode
    • lowpower example was aborting the stop mode entry, and never entered stop mode.  The issue was caused by the SPI0 peripheral preventing the entry to LLS mode.  Modified _lpm_set_cpu_operation_mode() in lpm_smc.c to disable SPI0 clock gate before entering a stop mode, and re-enabled after waking up.  If SPI0 peripheral is required in a stop mode, register the SPI driver with the LPM driver to properly configure when LPM changes operation mode to a stop mode.  Refer to LPM documentation for details.