Robobo
Quick start guide for the SAM PMC module

This is the quick start guide for the PMC module, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

PMC use cases

Basic use case - Switch Main Clock sources

In this use case, the PMC module is configured for a variety of system clock sources and speeds. A LED is used to visually indicate the current clock speed as the source is switched.

Setup

Prerequisites

  1. General Purpose I/O Management (gpio)

Code

The following function needs to be added to the user application, to flash a board LED a variable number of times at a rate given in CPU ticks.

#define FLASH_TICK_COUNT 0x00012345
void flash_led(uint32_t tick_count, uint8_t flash_count)
{
SysTick->LOAD = tick_count;
while (flash_count--)
{
gpio_toggle_pin(LED0_GPIO);
while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
gpio_toggle_pin(LED0_GPIO);
while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
}
}

Use case

Example code

Add to application C-file:

for (;;)
{
flash_led(FLASH_TICK_COUNT, 5);
flash_led(FLASH_TICK_COUNT, 5);
flash_led(FLASH_TICK_COUNT, 5);
flash_led(FLASH_TICK_COUNT, 5);
}

Workflow

  1. Wrap the code in an infinite loop:
    for (;;)
  2. Switch the Master CPU frequency to the internal 12MHz RC oscillator, flash a LED on the board several times:
    flash_led(FLASH_TICK_COUNT, 5);
  3. Switch the Master CPU frequency to the internal 8MHz RC oscillator, flash a LED on the board several times:
    flash_led(FLASH_TICK_COUNT, 5);
  4. Switch the Master CPU frequency to the internal 4MHz RC oscillator, flash a LED on the board several times:
    flash_led(FLASH_TICK_COUNT, 5);
  5. Switch the Master CPU frequency to the external crystal oscillator, flash a LED on the board several times:
    flash_led(FLASH_TICK_COUNT, 5);