1.7 PRIME 1.4 Service Modem
The PRIME 1.4 Service Modem application implements the full PRIME 1.4 protocol stack and provides access to the PRIME API through a serial interface. Serial messages are sent and received using the USI service, which lets an external host operate the device as a PRIME 1.4 Service Node with modem capabilities.
| Name | Path | Boards |
|---|---|---|
| PRIME 1.4 Service Modem | \smartenergy_prime_apps\apps\prime_apps\prime_service_14_modem | SAMD20 Xplained Pro + PL460-EK + FLASH 2 Click (SST26VF064B Serial Flash) + ATMBUSADAPTER-XPRO |
Functionally, this application is the same as the PRIME Service Dual Modem. It redirects requests and callbacks between the PRIME stack and an external host over the USI serial interface. The main differences in the SAMD20 build are:
- It links the PRIME 1.4 Service Node
library variant for the Arm® Cortex®-M0+ (
prime14_lib_sn_m0), a reducedfunctionalbuild for the constrained SAMD20. Compared with the full Service Node library, it:- does not include MAC security (security profiles SP1 and SP2)
- does not enable RF
- does not support direct connections
- keeps only the resources needed to maintain one IEC 61334-4-32 (4-32) connection and one management connection
- Buffers are reduced to save RAM on the SAMD20, which
lowers the maximum message sizes:
- the USI serial read and write buffers are 300 bytes each (versus 1024 bytes in the Dual Modem), which limits the serialized PRIME API messages exchanged with the host over the serial interface
- the IEC 61334-4-32 (4-32) maximum data length is 253 bytes (256 minus the 3-byte LPDU header), versus 1021 bytes (1024 minus 3) in the Dual Modem
- It is a PLC-only modem (PL460), the Dual Modem is a PLC-RF hybrid, so the RF215 driver and its components are not present
- The PL460 PHY binary is not embedded in the application image, it is loaded at start-up from an external serial Flash managed by the external memory bootloader (see PRIME Bootloader (External Memory))
- It is a monolithic project, the firmware upgrade is installed by that external memory bootloader on the next reset
Application Example
The PRIME 1.4 Service Modem exposes the PRIME API over a serial interface. Serial messages are sent and received using the USI service, so an external device (MCU, MPU, or PC) that implements the USI protocol and the PRIME API serialization can operate the board as a PRIME 1.4 Service Node. Microchip offers the PRIME Serialized Python library to develop custom scripts, contact the Microchip Smart Energy support team to obtain it.
The serial port settings are 115200 bps (see Hardware Configuration SAMD20 Xplained Pro), 8 data bits, no parity and 1 stop bit.
Application Functionality
APP_Initialize sets up the modem application and enables the
watchdog, APP_Tasks then runs a two-state machine
(APP_STATE_INIT to APP_STATE_SERVICE_TASKS).
Initialization opens the PRIME stack, registers the callbacks that bridge the PRIME
stack and the USI, and starts the status LED. The request and callback handling are
the same as in the PRIME Service Dual Modem.
What is specific to this build is that the application can force a reset into the bootloader serial recovery in two ways (see UART Recovery Mode for all the entry paths):
- By writing the USER PIB
0xF010, the host requests recovery, and the application resets into it - By holding the SW0 button, the application writes the UART Recovery Boot mode and resets after a debounce period, without requiring PRIME network access
The SW0 handling is implemented in lAPP_HandleSw0:
static void lAPP_HandleSw0(void) { SRV_FU_BOOT_MODE_STATUS status; if (appSw0State == APP_SW0_IDLE) { if (BSP_USER_BUTTON0_Get() == BSP_USER_BUTTON0_STATE_PRESSED) { if (++appSw0LowCount >= APP_SW0_DEBOUNCE_TICKS) { appSw0LowCount = 0U; /* Request the UART-recovery boot mode; reset once written */ if (SRV_FU_AsyncUpdateBootMode(SRV_FU_BOOT_MODE_UART_PENDING, 0U, SRV_FU_BOOT_STEP_PRISTINE) == true) { appSw0State = APP_SW0_WAIT_BOOT_MODE_OK; } } } else { appSw0LowCount = 0U; } } else /* APP_SW0_WAIT_BOOT_MODE_OK */ { status = SRV_FU_UpdateBootModeStatus(); if (status == SRV_FU_BOOT_MODE_STATUS_OK) { NVIC_SystemReset(); } else if (status == SRV_FU_BOOT_MODE_STATUS_ERROR) { appSw0State = APP_SW0_IDLE; } } }
