Getting Started With MPLAB® Harmony v3 Peripheral Libraries on PIC32CM JH (Arm® Cortex®-M0+) MCUs: Step 2

Last modified by Microchip on 2025/10/03 11:33

Information

Note: This video shows an overview of the Real-Time Clock (RTC), Universal Synchronous/Asynchronous Receiver/Transmitter (USART), and Direct Memory Access (DMA) configurations using MPLAB® Code Configurator (MCC).

Configure RTC Peripheral Library

Configure RTC Peripheral Library

Under the bottom left Device Resources tab, expand Harmony > Peripherals > RTC.

Double-click or drag and drop RTC to add the RTC Peripheral Library (PLIB) to the Project Graph.

Project Graph

 

In the Clock Easy view, verify the RTC clock is set to run at 1 kHz internal ultra-low-power clock.

When a module is added to the Project Graph, MPLAB® Code Configurator (MCC) automatically enables the clock to the module. The default RTC clock source is an internal 1 kHz ultra-low-power clock (OSCULP1K).

Clock Easy view

Information

Note: On the PIC32CM JH device, the RTC can be clocked through several low-power clock sources of 1 kHz and 32 kHz as shown in the accompanying image. The 1 kHz clock source retained (OSCULP1K) is enough to generate time periods of 500 milliseconds, 1 second, 2 seconds, and 4 seconds.

Go back to the Project Graph and configure the RTC PLIB to generate a compare interrupt every 500 milliseconds.

                                                                                                        Project Graph                                                                                                  

Information

Note: The Compare Value is set as 0x200. This compare value generates an RTC compare interrupt every 500 milliseconds.

  • RTC clock = 1024 Hz
  • RTC Prescaler = 1
  • Required Interrupt rate = 500 ms

Hence, Compare Value = (500/1000) x 1024 = 512 (i.e., 0x200).

Back to Top


Configure USART Peripheral Library and USART Pins

Under the tab Device Resources tab, expand Harmony > Peripheral > SERCOM.

Double-click on SERCOM1 to add the SERCOM instance 1 to the project.

Project Graph

Select the SERCOM1 Peripheral Library in the Project Graph and verify default SERCOM Operation Mode configuration is set as USART. Configure it as shown in the following figure. Verify that the default baud rate is set to 115200 Hz.

SERCOM1 Peripheral Library 

Information

Note:

  • SERCOM1 (as USART) interrupt is disabled because DMA will be used (configured in the following steps) to transfer application buffer to the USART TX register and also receives data from USART RX register.
  • As per the board design, SERCOM1 PAD0 and SERCOM1 PAD1 are used for SERCOM1 (as USART) data transmission and reception.
  • The application will use the SERCOM1 (as USART) PLIB for printing LED toggling rate on the serial terminal.

Open the Pin Configuration tabs by clicking MCC > Project Graph > Plugins > Pin Configuration. Sort the entries by Ports, as shown in the accompanying image.

pin settings

 

Scroll down to the SERCOM1 module. Enable USART_TX (SERCOM_PAD0) on PA16 (Pin #35).

Pin Configuration PA16

 

Back to Top


Configure DMA Peripheral Library

Configure DMA by selecting the System block in the Project Graph. In Configuration Options navigate to DMA. 

DMA Configuration Options 

 

Expand DMA ​​​​​​. Enable DMA Channel 0.

DMA Channel 0                                                                      

Expand DMA Channel 0 and configure it to transmit the application buffer to the USART TX register. The DMA transfers one byte from the user buffer to the USART transmit buffer on each trigger.

DMA Channel 0

Based on the trigger source, the DMA channel configuration is automatically set by MCC.

  • Trigger Action is the action taken by the DMA when it receives a trigger.
    • Cell Transfer refers to the number of bytes transferred when a DMA channel has a transfer initiated before waiting for another event. A cell transfer consists of one or more transactions. It is generally used during a memory-to-peripheral or peripheral-to-memory transfer.
    • Block Transfer refers to the number of bytes transferred when a channel is enabled. The number of bytes is the larger of either the Source or Destination size. A block transfer consists of one or more cell transfers and is generally used during a memory-to-memory transfer that is initiated by a software trigger.
  • The Source Address Mode and Destination Address Mode settings determine whether the Source or Destination Address is incremented after every transfer. The modes are automatically set by MCC based on the trigger type. For example, if the trigger source is a USART transmit, then the Source Address is incremented and the Destination Address remains fixed. Conversely, if the trigger source is a USART receive, then the Source Address remains fixed and the Destination Address is incremented.
Information

Note:

  • USART transmit buffer empty event triggers DMA to transfer one byte of data from source (user buffer) to destination (USART Tx register). When all the requested bytes are transmitted, DMA PLIB notifies the application by calling the registered DMA callback event handler.
  • USART receive timeout event triggers DMA to transfer one byte of data from the source (USART Rx register) to the destination (user buffer). When all the requested bytes are received, DMA PLIB notifies the application by calling the registered DMA callback event handler.
  • The DMA channels can be configured using the DMA configuration option.

Launch NVIC Configuration by selecting Project Graph > Plugins > NVIC Configuration.

Plugins dropdown

                                                                                                  

Click on the NVIC settings tab. Verify DMA Channel 0 settings.

DMA Channel 0 settings

                                                                                                

Back to Top