RA Flexible Software Package Documentation  Release v5.6.0

 
WiFi Onchip DA16XXX Framework Driver (rm_wifi_da16xxx)

Functions

fsp_err_t RM_WIFI_DA16XXX_SntpServerIpAddressSet (uint8_t *p_server_ip_addr)
 
fsp_err_t RM_WIFI_DA16XXX_SntpEnableSet (wifi_da16xxx_sntp_enable_t enable)
 
fsp_err_t RM_WIFI_DA16XXX_SntpTimeZoneSet (int utc_offset_in_hours, uint32_t minutes, wifi_da16xxx_sntp_daylight_savings_enable_t daylightSavingsEnable)
 
fsp_err_t RM_WIFI_DA16XXX_LocalTimeGet (uint8_t *p_local_time, uint32_t size_string)
 
fsp_err_t RM_WIFI_DA16XXX_GenericAtSendRcv (char const *const at_string, char *const response_buffer, uint32_t length)
 

Detailed Description

Wifi and Socket implementation using the DA16XXX WiFi module on RA MCUs.

Overview

This Middleware module currently supplies an implementation for using the DA16XXX module in two different configurations.

The first is for the FreeRTOS WiFi interface, where the network stack is located on the MCU using a socket interface, and the DA16XXX Wi-Fi module provides a connection to the internet. This configuration requires FreeRTOS to be used.

The second configuration is for use with the DA16XXX on-chip MQTT and HTTP client modules, where the network stack is located on the DA16XXX module. In this configuration, this Middleware driver supports FreeRTOS as well as Baremetal (Microsoft Azure support expected in future release).

DA16XXX is a low power Wi-Fi networking SoC that delivers a dramatic breakthrough in battery life even for devices that are continuously connected to the Wi-Fi network. The module comes readily equipped with radio certification for Japan, North America and Europe. More information about this module can be found at the DA16XXX Web Site

The DA16XXX module supports the following modules:

Features

The WiFi Onchip da16xxx Middleware driver supplies these features:

Configuration

Build Time Configurations for rm_wifi_da16xxx

The following build time configurations are defined in fsp_cfg/rm_wifi_da16xxx_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
Enable DA16600 Support
  • Enabled
  • Disabled
Disabled Enabled if using the DA16600 module
Check Minimum SDK Version
  • Disabled
  • Enabled
Enabled Enable or disable comparing the current DA16XXX module's SDK version to the minimum required
Number of supported socket instances (not used with on-chip APIs)11 Enable number of socket instances
Size of RX buffer for socket (not used with on-chip APIs)Manual Entry8192
Size of TX buffer for CMD PortManual Entry1500
Size of RX buffer for CMD PortManual Entry3000
Enable SNTP Client
  • Enabled
  • Disabled
Disabled Should the SNTP client of the module be enabled

Configurations for Networking > WiFi DA16XXX Framework Driver (rm_wifi_da16xxx)

ConfigurationOptionsDefaultDescription
Country code in ISO 3166-1 alpha-2 standardManual EntryUS
SNTP server IPv4 addressMust be a valid IPv4 address0.0.0.0
SNTP Timezone UTC Offset in HoursRefer to the RA Configuration tool for available options.0 Value in hours from 12 to -12

Note: It is suggested that when using the DA16XXX module that DTC and FIFO are enabled in the UART configuration to facilitate a more reliable data transfer between module and MCU.

Note: If you wish to use flow control then you must enable flow control in the RA Configuration editor. This can be found in the UART setting. It is advantageous to use flow control all the time since it allows the hardware to gate the flow of data across the serial bus. Without hardware flow control for faster data rate you will most likely see an overflow condition between MCU and the module device.

Note: Higher baud rates are supported in the RA Configuration editor and should be changed in the first UART configuration. There is no need to change the second UART baud rate since it is only used as an AT command channel.

Note: It is a good idea to also enable the FIFO in the UART configuration settings if you plan to use higher baud rates.

Interrupt Configuration

Refer to UART (r_sci_uart). R_SCI_UART_Open() is called by WiFi Onchip DA16XXX Framework Driver (rm_wifi_da16xxx).

Clock Configuration

Refer to UART (r_sci_uart).

Pin Configuration

Refer to UART (r_sci_uart). R_SCI_UART_Open() is called by WiFi Onchip DA16XXX Framework Driver (rm_wifi_da16xxx)

Usage Notes

Limitations

Examples

Basic Example

This is a basic example of minimal use of WiFi Middleware in an application.

void wifi_basic_example (void)
{
WIFIReturnCode_t wifi_err;
/* Setup Access Point connection parameters */
WIFINetworkParams_t net_params =
{
.ucChannel = 0,
.xPassword.xWPA.cPassphrase = "password",
.ucSSID = "access_point_ssid",
.xPassword.xWPA.ucLength = 8,
.ucSSIDLength = 17,
.xSecurity = eWiFiSecurityWPA2,
};
memset(scan_data, 0, sizeof(WIFIScanResult_t) * MAX_WIFI_SCAN_RESULTS);
memset(g_socket_recv_buffer, 0, sizeof(uint8_t) * SX_WIFI_SOCKET_RX_BUFFER_SIZE);
/* Open connection to the Wifi Module */
wifi_err = WIFI_On();
assert(eWiFiSuccess == wifi_err);
/* Connect to the Access Point */
wifi_err = WIFI_ConnectAP(&net_params);
assert(eWiFiSuccess == wifi_err);
/* Get address assigned by AP */
wifi_err = WIFI_GetIPInfo(&ipInfo);
assert(eWiFiSuccess == wifi_err);
/* Ping an address accessible on the network */
uint8_t ip_address[4] = {216, 58, 194, 174}; // NOLINT
const uint16_t ping_count = 3;
const uint32_t intervalMS = 100;
wifi_err = WIFI_Ping(&ip_address[0], ping_count, intervalMS);
assert(eWiFiSuccess == wifi_err);
/* Scan the local Wifi network for other APs */
wifi_err = WIFI_Scan(&scan_data[0], MAX_WIFI_SCAN_RESULTS);
assert(eWiFiSuccess == wifi_err);
/* Shutdown the WIFI */
}

SNTP example

An example of using Simple Network Time Protocol (SNTP) on WiFi in an application.

#define RM_WIFI_DA16XXX_TEMP_BUFFER_SIZE (64)
/*
* Example of the use of SNTP with Wifi. Example gets the epoch time and local
* system time strings. It is also demonstrated how the user will need to disconnect
* from the access point to make changes to the SNTP configuration during runtime.
*
* Function assumes that the SNTP has been enabled and configured with proper
* SNTP server address. For brevity error checking has not been implemented.
*
*/
void wifi_sntp_example (void)
{
/* Setup Access Point connection parameters */
WIFINetworkParams_t net_params =
{
.ucSSID = "access_point_ssid",
.ucSSIDLength = 17,
.xPassword.xWPA.cPassphrase = "password",
.xPassword.xWPA.ucLength = 8,
.ucChannel = 0,
.xSecurity = eWiFiSecurityWPA2
};
uint8_t local_time[RM_WIFI_DA16XXX_TEMP_BUFFER_SIZE];
time_t current_sys_time = 0;
// SNTP IP address
uint8_t ip_address_sntp_server_valid[4] = {216, 239, 35, 0}; // NOLINT : Static IP address
memset(local_time, 0, sizeof(local_time));
/* Open connection to the Wifi Module */
/* Connect to the Access Point */
WIFI_ConnectAP(&net_params);
/* Get the local time string */
RM_WIFI_DA16XXX_LocalTimeGet((uint8_t *) local_time, sizeof(local_time));
/* Disconnect from the access point to make changes to the SNTP configuration */
/* Change the IP address of the server */
RM_WIFI_DA16XXX_SntpServerIpAddressSet((uint8_t *) ip_address_sntp_server_valid);
/* Change the timezone to PST with daylight saving enabled */
RM_WIFI_DA16XXX_SntpTimeZoneSet(-8, 0, WIFI_DA16XXX_SNTP_DAYLIGHT_SAVINGS_DISABLE);
/* Connect back to the access point */
WIFI_ConnectAP(&net_params);
/* Get the local time string in format [DayOfWeek Month DayOfMonth Year Hour:Minute:Second] */
RM_WIFI_DA16XXX_LocalTimeGet((uint8_t *) local_time, sizeof(local_time));
/* Disconnect from the Access Point and shutdown the WIFI module*/
}

Data Structures

struct  wifi_da16xxx_cfg_t
 
struct  da16xxx_socket_t
 
struct  wifi_da16xxx_instance_ctrl_t
 

Enumerations

enum  wifi_da16xxx_sntp_enable_t
 
enum  da16xxx_socket_status_t
 
enum  da16xxx_socket_rw
 
enum  da16xxx_recv_state
 
enum  wifi_da16xxx_sntp_daylight_savings_enable_t
 

Data Structure Documentation

◆ wifi_da16xxx_cfg_t

struct wifi_da16xxx_cfg_t

User configuration structure, used in open function

Data Fields
at_transport_da16xxx_instance_t
const *
p_transport_instance
const uint32_t num_sockets Number of sockets to initialize.
const uint8_t * country_code Country code defined in ISO3166-1 alpha-2 standard.
const uint8_t * sntp_server_ip The SNTP server IP address string.
const int32_t sntp_utc_offset_in_hours Timezone offset in secs (-43200 - 43200)
void const * p_context User defined context passed into callback function.
void const * p_extend Pointer to extended configuration by instance of interface.

◆ da16xxx_socket_t

struct da16xxx_socket_t

DA16XXX Wifi internal socket instance structure

Data Fields
uint8_t remote_ipaddr[4] Remote IP address.
int remote_port Remote Port.
int socket_recv_data_len Data length of incoming socket data.
int socket_type Socket type (TCP Server | TCP Client | UDP)
uint32_t socket_status Current socket status.
uint32_t socket_recv_error_count Socket receive error count.
uint32_t socket_create_flag Flag to determine in socket has been created.
uint32_t socket_read_write_flag flag to determine if read and/or write channels are active.
da16xxx_recv_state socket_recv_state Incoming Socket data header information.
StreamBufferHandle_t socket_byteq_hdl Socket stream buffer handle.
StaticStreamBuffer_t socket_byteq_struct Structure to hold stream buffer info.
uint8_t socket_recv_buff[WIFI_DA16XXX_CFG_MAX_SOCKET_RX_SIZE] Socket receive buffer used by byte queue.

◆ wifi_da16xxx_instance_ctrl_t

struct wifi_da16xxx_instance_ctrl_t

WIFI_DA16XXX private control block. DO NOT MODIFY.

Data Fields
wifi_da16xxx_cfg_t const * p_wifi_da16xxx_cfg Pointer to initial configurations.
uint32_t num_creatable_sockets Number of simultaneous sockets supported.
uint32_t curr_socket Current Socket index for AT commands.
uint32_t open Flag to indicate if wifi instance has been initialized.
uint8_t is_sntp_enabled Flag to indicate Enable/Disable of SNTP Client.
uint8_t cmd_tx_buff[WIFI_DA16XXX_CFG_CMD_TX_BUF_SIZE] Command send buffer.
uint8_t cmd_rx_buff[WIFI_DA16XXX_CFG_CMD_RX_BUF_SIZE] Command receive buffer.
volatile uint32_t curr_socket_index Currently active socket instance.
uint8_t curr_ipaddr[4] Current IP address of module.
uint8_t curr_subnetmask[4] Current Subnet Mask of module.
uint8_t curr_gateway[4] Current GAteway of module.
da16xxx_socket_t sockets[WIFI_DA16XXX_CFG_NUM_CREATEABLE_SOCKETS] Internal socket instances.

Enumeration Type Documentation

◆ wifi_da16xxx_sntp_enable_t

DA16XXX WiFi module enable/disable for SNTP

◆ da16xxx_socket_status_t

DA16XXX Wifi socket status types

◆ da16xxx_socket_rw

DA16XXX socket shutdown channels

◆ da16xxx_recv_state

DA16XXX socket receive state

◆ wifi_da16xxx_sntp_daylight_savings_enable_t

DA16XXX WiFi module enable/disable for SNTP Daylight

Function Documentation

◆ RM_WIFI_DA16XXX_SntpServerIpAddressSet()

fsp_err_t RM_WIFI_DA16XXX_SntpServerIpAddressSet ( uint8_t *  p_server_ip_addr)

Set the SNTP Client Server IP Address

Parameters
[in]p_server_ip_addrPointer to IP address of SNTP server in byte array format.
Return values
FSP_SUCCESSSuccessfully set the value.
FSP_ERR_WIFI_FAILEDError occurred with command to Wifi module.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_ASSERTIONThe parameter p_server_ip_addr is NULL.

Update the SNTP Server IP Address

◆ RM_WIFI_DA16XXX_SntpEnableSet()

fsp_err_t RM_WIFI_DA16XXX_SntpEnableSet ( wifi_da16xxx_sntp_enable_t  enable)

Set the SNTP Client to Enable or Disable

Parameters
[in]enableFlag to indicate enable/disable for SNTP support.
Return values
FSP_SUCCESSSuccessfully set the value.
FSP_ERR_WIFI_FAILEDError occurred with command to Wifi module.
FSP_ERR_NOT_OPENModule is not open.

Enable or Disable the SNTP Client Service

◆ RM_WIFI_DA16XXX_SntpTimeZoneSet()

fsp_err_t RM_WIFI_DA16XXX_SntpTimeZoneSet ( int  utc_offset_in_hours,
uint32_t  minutes,
wifi_da16xxx_sntp_daylight_savings_enable_t  daylightSavingsEnable 
)

Set the SNTP Client Timezone

Parameters
[in]utc_offset_in_hoursTimezone in UTC offset in hours
[in]minutesNumber of minutes used for timezone offset from GMT.
[in]daylightSavingsEnableEnable/Disable daylight saving in the timezone calculation.
Return values
FSP_SUCCESSSuccessfully set the value.
FSP_ERR_WIFI_FAILEDError occurred with command to Wifi module.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTParameter passed into function was invalid.

Update the SNTP Timezone

◆ RM_WIFI_DA16XXX_LocalTimeGet()

fsp_err_t RM_WIFI_DA16XXX_LocalTimeGet ( uint8_t *  p_local_time,
uint32_t  size_string 
)

Get the current local time based on current timezone in a string . Exp: YYYY-MM-DD,HOUR:MIN:SECS

Parameters
[out]p_local_timeReturns local time in string format.
[in]size_stringSize of p_local_time string buffer.The size of this string needs to be at least 25 bytes
Return values
FSP_SUCCESSSuccessfully returned the local time string.
FSP_ERR_ASSERTIONThe parameter local_time or p_instance_ctrl is NULL.
FSP_ERR_WIFI_FAILEDError occurred with command to Wifi module.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_SIZEString size value passed in exceeds maximum.

Get the current local time based on current timezone in a string format

◆ RM_WIFI_DA16XXX_GenericAtSendRcv()

fsp_err_t RM_WIFI_DA16XXX_GenericAtSendRcv ( char const *const  at_string,
char *const  response_buffer,
uint32_t  length 
)

Sends any AT command compatible with the DA16XXX module. Provide optional buffer to receive the response.

Parameters
[in]at_stringInput AT command string from the user.
[in]response_bufferOptional buffer for receiving the response.
[in]lengthSize of optional buffer.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_WIFI_FAILEDError occurred with command to Wifi module.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput was not a valid AT command.

Send a generic AT command to the DA16XXX and optionally receive a response