RAFW Flexible Software Package Documentation  Release v2.0.1

 
I/O Port (W) (r_gpio_w)

Functions

fsp_err_t R_GPIO_W_Open (ioport_ctrl_t *const p_ctrl, const ioport_cfg_t *p_cfg)
 
fsp_err_t R_GPIO_W_Close (ioport_ctrl_t *const p_ctrl)
 
fsp_err_t R_GPIO_W_PinsCfg (ioport_ctrl_t *const p_ctrl, const ioport_cfg_t *p_cfg)
 
fsp_err_t R_GPIO_W_PinCfg (ioport_ctrl_t *const p_ctrl, bsp_io_port_pin_t pin, uint32_t cfg)
 
fsp_err_t R_GPIO_W_PinRead (ioport_ctrl_t *const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t *p_pin_value)
 
fsp_err_t R_GPIO_W_PortRead (ioport_ctrl_t *const p_ctrl, bsp_io_port_t port, ioport_size_t *p_port_value)
 
fsp_err_t R_GPIO_W_PortWrite (ioport_ctrl_t *const p_ctrl, bsp_io_port_t port, ioport_size_t value, ioport_size_t mask)
 
fsp_err_t R_GPIO_W_PinWrite (ioport_ctrl_t *const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t level)
 
fsp_err_t R_GPIO_W_PortDirectionSet (ioport_ctrl_t *const p_ctrl, bsp_io_port_t port, ioport_size_t direction_values, ioport_size_t mask)
 
fsp_err_t R_GPIO_W_PortEventInputRead (ioport_ctrl_t *const p_ctrl, bsp_io_port_t port, ioport_size_t *p_event_data)
 
fsp_err_t R_GPIO_W_PinEventInputRead (ioport_ctrl_t *const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t *p_pin_event)
 
fsp_err_t R_GPIO_W_PortEventOutputWrite (ioport_ctrl_t *const p_ctrl, bsp_io_port_t port, ioport_size_t event_data, ioport_size_t mask_value)
 
fsp_err_t R_GPIO_W_PinEventOutputWrite (ioport_ctrl_t *const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t pin_value)
 

Detailed Description

Driver for the I/O Ports peripheral on RAFW MCUs. This module implements the I/O Port Interface.

Overview

The I/O port pins operate as general I/O port pins, I/O pins for peripheral modules, interrupt input pins, analog I/O, response pins for the ELC, or bus control pins.

Features

The GPIO_W HAL module can configure the following pin settings:

--—Features-------------—RA6B1 RA6U1 RA6B2 RA6W1 RA6W3
Peripheral event assignment SupportedSupportedSupported Not Supported Supported
Response task assignment SupportedSupportedSupported Not Supported Supported

The module also provides the following functionality:

Configuration

The I/O PORT HAL module must be configured by the user for the desired operation. The operating state of an I/O pin can be set via the RA Configuraton tool. When the project is built a pin configuration file is created. The BSP will automatically configure the MCU IO ports accordingly at startup using the same API functions mentioned in this document.

Build Time Configurations for r_gpio_w

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

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for System > I/O Port (r_gpio_w)

This module can be added to the Stacks tab via New Stack > System > I/O Port (r_gpio_w).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_gpio_w Module name.
Pin Configuration NameName must be a valid C symbolg_bsp_pin_cfg Name for pin configuration structure

Clock Configuration

The GPIO_W HAL module does not require a specific clock configuration.

Pin Configuration

The GPIO_W module is used for configuring pins.

Usage Notes

Examples

Basic Example

This is a basic example of minimal use of the GPIO_W in an application.

void basic_example (void)
{
bsp_io_level_t readLevel;
fsp_err_t err;
/* Initialize the GPIO_W module and configure the pins
* Note: The default pin configuration name in the RAFW Configuration tool is g_bsp_pin_cfg_exmpl */
err = R_GPIO_W_Open(&g_gpio_w_ctrl, &g_bsp_pin_cfg_exmpl);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Call R_GPIO_W_PinsCfg if the configuration was not part of initial configurations made in open */
#if !defined(BSP_MCU_GROUP_RA6W1)
err = R_GPIO_W_PinsCfg(&g_gpio_w_ctrl, &g_runtime_pin_cfg);
#else
err = R_GPIO_W_PinsCfg(&g_gpio_w_ctrl, &g_bsp_pin_cfg_runtime_exmpl);
#endif
assert(FSP_SUCCESS == err);
/* Set Pin 00 of Port 00 to High */
#if !defined(BSP_MCU_GROUP_RA6W1)
#else
#endif
assert(FSP_SUCCESS == err);
/* Read Pin 00 of Port 00 */
#if !defined(BSP_MCU_GROUP_RA6W1)
err = R_GPIO_W_PinRead(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_00, &readLevel);
#else
err = R_GPIO_W_PinRead(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_11, &readLevel);
#endif
assert(FSP_SUCCESS == err);
}

Blinky Example

This example uses GPIO_W to configure and toggle a pin to blink an LED.

#if !defined(BSP_MCU_GROUP_RA6W1)
void blinky_example (void)
{
fsp_err_t err;
#if defined(BSP_MCU_GROUP_RA6W1)
R_BSP_IrqEnable(BSP_VECTOR_GPIO_P0_INT);
#endif
/* Initialize the GPIO_W module and configure the pins */
err = R_GPIO_W_Open(&g_gpio_w_ctrl, &g_bsp_pin_cfg_exmpl);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Configure Pin as output
* Call the R_GPIO_W_PinCfg if the configuration was not part of initial configurations made in open */
err = R_GPIO_W_PinCfg(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_00, GPIO_W_CFG_PORT_DIRECTION_OUTPUT);
assert(FSP_SUCCESS == err);
while (1)
{
/* Determine the next state of the LEDs */
if (BSP_IO_LEVEL_LOW == level)
{
}
else
{
}
/* Update LED on RA6B1-PRODK */
err = R_GPIO_W_PinWrite(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_00, level);
assert(FSP_SUCCESS == err);
/* Delay */
}
}
#else
void blinky_example (void)
{
fsp_err_t err;
R_BSP_IrqEnable(BSP_VECTOR_GPIO_P0_INT);
/* Initialize the GPIO_W module and configure the pins */
err = R_GPIO_W_Open(&g_gpio_w_ctrl, &g_bsp_pin_cfg_exmpl);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Configure Pin as output
* Call the R_GPIO_W_PinCfg if the configuration was not part of initial configurations made in open */
err = R_GPIO_W_PinCfg(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_10, GPIO_W_CFG_PULLUP_ENABLE);
assert(FSP_SUCCESS == err);
/* Configure Pin as output
* Call the R_GPIO_W_PinCfg if the configuration was not part of initial configurations made in open */
err = R_GPIO_W_PinCfg(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_11, GPIO_W_CFG_PORT_DIRECTION_OUTPUT);
assert(FSP_SUCCESS == err);
while (1)
{
if (toggle)
{
level = !level;
}
/* Update LED on EK-RQ61 */
err = R_GPIO_W_PinWrite(&g_gpio_w_ctrl, BSP_IO_PORT_00_PIN_11, level);
assert(FSP_SUCCESS == err);
/* Delay */
}
}
#endif

ELC Example

ELC Example is available only in supported devices:

RA6B1 RA6U1 RA6B2 RA6W1 RA6W3
SupportedSupportedSupported Not Supported Supported

This is an example of using GPIO_W with ELC events. Any pin can be assigned to 1) a peripheral event which can be linked to any event via ELC. 2) a response task performed when the linked event occurs. SET,RESET or TOGGLE. The response can be found by simply reading the corresponding data register.

static elc_w_instance_ctrl_t g_elc_ctrl;
static elc_cfg_t g_elc_cfg;
void gpio_w_elc_example ()
{
bsp_io_level_t eventValue;
fsp_err_t err;
/* Initializes the software and sets the links defined in the control structure. */
err = R_ELC_W_Open(&g_elc_ctrl, &g_elc_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Create or modify a link between a peripheral function and an event source. */
err = R_ELC_W_LinkSet(&g_elc_ctrl, (elc_peripheral_t) ELC_PERIPHERAL_GPIOW2, ELC_EVENT_ELCW_SWEVT0);
assert(FSP_SUCCESS == err);
/* Globally enable event linking in the ELC. */
err = R_ELC_W_Enable(&g_elc_ctrl);
assert(FSP_SUCCESS == err);
/* Initialize the GPIO_W module and configure the pins */
err = R_GPIO_W_Open(&g_gpio_w_ctrl, &g_bsp_pin_cfg_exmpl);
assert(FSP_SUCCESS == err);
/* SET ELC action */
/* Call the R_GPIO_W_PinCfg if the configuration was not part of initial configurations made in open
* Use the mask-macro-function with desired ELC_GPIO_EVT for SET elc task */
err =
R_GPIO_W_PinCfg(&g_gpio_w_ctrl, BSP_IO_PORT_02_PIN_00, SET_GPIO_EVENTx_MASK(ELC_PERIPHERAL_GPIOW2));
assert(FSP_SUCCESS == err);
/* Generate an event signal through software to the linked peripheral. */
err = R_ELC_W_SoftwareEventGenerate(&g_elc_ctrl, ELC_SOFTWARE_EVENT_0);
assert(FSP_SUCCESS == err);
/* Wait for event to occur */
/* Read Pin Event Output. */
err = R_GPIO_W_PinRead(&g_gpio_w_ctrl, BSP_IO_PORT_02_PIN_00, &eventValue);
assert(FSP_SUCCESS == err);
assert(BSP_IO_LEVEL_HIGH == eventValue);
/* RESET ELC action */
/* Call the R_GPIO_W_PinCfg if the configuration was not part of initial configurations made in open
* Use the mask-macro-function with desired ELC_GPIO_EVT for RESET elc task */
err =
R_GPIO_W_PinCfg(&g_gpio_w_ctrl, BSP_IO_PORT_02_PIN_00, RESET_GPIO_EVENTx_MASK(ELC_PERIPHERAL_GPIOW2));
assert(FSP_SUCCESS == err);
/* Generate an event signal through software to the linked peripheral. */
err = R_ELC_W_SoftwareEventGenerate(&g_elc_ctrl, ELC_SOFTWARE_EVENT_0);
assert(FSP_SUCCESS == err);
/* Wait for event to occur */
/* Read Pin Event Output. */
err = R_GPIO_W_PinRead(&g_gpio_w_ctrl, BSP_IO_PORT_02_PIN_00, &eventValue);
assert(FSP_SUCCESS == err);
assert(BSP_IO_LEVEL_LOW == eventValue);
/* TOGGLE ELC action */
/* Call the R_GPIO_W_PinCfg if the configuration was not part of initial configurations made in open
* Use the mask-macro-function with desired ELC_GPIO_EVT for TOGGLE elc task */
err =
TOGGLE_GPIO_EVENTx_MASK(ELC_PERIPHERAL_GPIOW2, BSP_IO_LEVEL_HIGH));
assert(FSP_SUCCESS == err);
/* Generate an event signal through software to the linked peripheral. */
err = R_ELC_W_SoftwareEventGenerate(&g_elc_ctrl, ELC_SOFTWARE_EVENT_0);
assert(FSP_SUCCESS == err);
/* Wait for event to occur */
/* Read Pin Event Output. */
err = R_GPIO_W_PinRead(&g_gpio_w_ctrl, BSP_IO_PORT_02_PIN_00, &eventValue);
assert(FSP_SUCCESS == err);
assert(BSP_IO_LEVEL_LOW == eventValue);
}

Data Structures

struct  gpio_w_instance_ctrl_t
 
struct  pad_power_t
 
struct  pad_weak_t
 
struct  sel_pin_clk_out_t
 
struct  gpio_w_extended_cfg_t
 

Enumerations

enum  gpio_w_peripheral_t
 

Data Structure Documentation

◆ gpio_w_instance_ctrl_t

struct gpio_w_instance_ctrl_t

GPIO_W private control block. DO NOT MODIFY. Initialization occurs when R_GPIO_W_Open() is called.

◆ pad_power_t

struct pad_power_t

Pins power configuration structure

Data Fields
uint32_t p0_pwr

Pins output power for P0

uint32_t p1_pwr

Pins output power for P1

◆ pad_weak_t

struct pad_weak_t

Pins driving strength configuration structure

◆ sel_pin_clk_out_t

struct sel_pin_clk_out_t

Map clock output to selectable pin structure

Data Fields
bsp_io_clk_func_t clk_sel

Select which clock to map

bool clk_en

Enable mapping of the selected clock signal

◆ gpio_w_extended_cfg_t

struct gpio_w_extended_cfg_t

Extended configuration struct

Data Fields
pad_power_t power

Pins power configuration

pad_weak_t weak_pad_power

Pins driving strength configuration

bsp_io_clk_output_t fixed_pin_clk_out

Map clock output to fixed pin

sel_pin_clk_out_t sel_pin_clk_out

Map clock output to selectable pin

Enumeration Type Documentation

◆ gpio_w_peripheral_t

Superset of all peripheral functions.

Enumerator
GPIO_W_PERIPHERAL_DEBUG 

Pin will function as a DEBUG pin (controlled by SYS_CTRL_REG[DEBUGGER_ENABLE])

GPIO_W_PERIPHERAL_TRACE 

Pin will function as a TRACE pin (controlled by DEBUG_REG[ETM_TRACE_MAP_ON_PINS_EN])

GPIO_W_PERIPHERAL_ACOMP 

Pin will function as an ACOMP Channel pin

GPIO_W_PERIPHERAL_QSPI 

Pin will function as a QSPIC pin

Function Documentation

◆ R_GPIO_W_Open()

fsp_err_t R_GPIO_W_Open ( ioport_ctrl_t *const  p_ctrl,
const ioport_cfg_t p_cfg 
)

Initializes internal driver data, then calls pin configuration function to configure pins.

Return values
FSP_SUCCESSPin configuration data written to MODE, Set port pins and Reset port pins register(s)
FSP_ERR_ASSERTIONNULL pointer
FSP_ERR_ALREADY_OPENModule is already open.

◆ R_GPIO_W_Close()

fsp_err_t R_GPIO_W_Close ( ioport_ctrl_t *const  p_ctrl)

Resets GPIO_W registers. Implements ioport_api_t::close

Return values
FSP_SUCCESSThe GPIO_W was successfully uninitialized
FSP_ERR_ASSERTIONp_ctrl was NULL
FSP_ERR_NOT_OPENThe module has not been opened

◆ R_GPIO_W_PinsCfg()

fsp_err_t R_GPIO_W_PinsCfg ( ioport_ctrl_t *const  p_ctrl,
const ioport_cfg_t p_cfg 
)

Configures the functions of multiple pins by loading configuration data into pin MODE,Set port pins and Reset port pins registers. Implements ioport_api_t::pinsCfg.

This function initializes the supplied list of MODE, Set port pins and Reset port pins registers with the supplied values. This data can be generated by the Pins tab of the RAFW Configuration editor or manually by the developer. Different pin configurations can be loaded for different situations such as low power modes and testing.

Return values
FSP_SUCCESSPin configuration data written to MODE,Set port pins and Reset port pins register(s)
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_ASSERTIONNULL pointer

◆ R_GPIO_W_PinCfg()

fsp_err_t R_GPIO_W_PinCfg ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_pin_t  pin,
uint32_t  cfg 
)

Configures the settings of a pin. Implements ioport_api_t::pinCfg.

Return values
FSP_SUCCESSPin configured
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_ASSERTIONNULL pointer
Note
This function is re-entrant for different pins. This function will change the configuration of the pin with the new configuration. For example it is not possible with this function to change the drive strength of a pin while leaving all the other pin settings unchanged. To achieve this the original settings with the required change will need to be written using this function.

◆ R_GPIO_W_PinRead()

fsp_err_t R_GPIO_W_PinRead ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_pin_t  pin,
bsp_io_level_t p_pin_value 
)

Reads the level on a pin. Implements ioport_api_t::pinRead.

Return values
FSP_SUCCESSPin read
FSP_ERR_ASSERTIONNULL pointer
FSP_ERR_NOT_OPENThe module has not been opened
Note
This function is re-entrant for different pins.

◆ R_GPIO_W_PortRead()

fsp_err_t R_GPIO_W_PortRead ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_t  port,
ioport_size_t p_port_value 
)

Reads the value on an IO port. Implements ioport_api_t::portRead.

The specified port will be read, and the levels for all the pins will be returned. Each bit in the returned value corresponds to a pin on the port. For example, bit 7 corresponds to pin 7, bit 6 to pin 6, and so on.

Return values
FSP_SUCCESSPort read
FSP_ERR_ASSERTIONNULL pointer
FSP_ERR_NOT_OPENThe module has not been opened
Note
This function is re-entrant for different ports.

◆ R_GPIO_W_PortWrite()

fsp_err_t R_GPIO_W_PortWrite ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_t  port,
ioport_size_t  value,
ioport_size_t  mask 
)

Writes to multiple pins on a port. Implements ioport_api_t::portWrite.

The input value will be written to the specified port. Each bit in the value parameter corresponds to a bit on the port. For example, bit 7 corresponds to pin 7, bit 6 to pin 6, and so on. Each bit in the mask parameter corresponds to a pin on the port.

Only the bits with the corresponding bit in the mask value set will be updated. For example, value = 0xFFFF, mask = 0x0003 results in only bits 0 and 1 being updated.

Return values
FSP_SUCCESSPort written to
FSP_ERR_INVALID_ARGUMENTThe port and/or mask not valid
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_ASSERTIONNULL pointerd
Note
This function is re-entrant for different ports. This function makes use of the Set port pins and Reset port pins registers to atomically modify the levels on the specified pins on a port.

◆ R_GPIO_W_PinWrite()

fsp_err_t R_GPIO_W_PinWrite ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_pin_t  pin,
bsp_io_level_t  level 
)

Sets a pin's output either high or low. Implements ioport_api_t::pinWrite.

Return values
FSP_SUCCESSPin written to
FSP_ERR_INVALID_ARGUMENTThe pin and/or level not valid
FSP_ERR_NOT_OPENThe module has not been opene
FSP_ERR_ASSERTIONNULL pointerd
Note
This function is re-entrant for different pins. This function makes use of the Set port pins and Reset port pins registers to atomically modify the level on the specified pin on a port.

◆ R_GPIO_W_PortDirectionSet()

fsp_err_t R_GPIO_W_PortDirectionSet ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_t  port,
ioport_size_t  direction_values,
ioport_size_t  mask 
)

Sets the direction of individual pins on a port. Implements ioport_api_t::portDirectionSet().

Multiple pins on a port can be set to inputs or outputs at once. Each bit in the mask parameter corresponds to a pin on the port. For example, bit 7 corresponds to pin 7, bit 6 to pin 6, and so on. If a bit is set to 1 then the corresponding pin will be changed to an input or an output as specified by the direction values. If a mask bit is set to 0 then the direction of the pin will not be changed.

Return values
FSP_SUCCESSPort direction updated
FSP_ERR_INVALID_ARGUMENTThe port and/or mask not valid
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_ASSERTIONNULL pointer
Note
This function is re-entrant for different ports.

◆ R_GPIO_W_PortEventInputRead()

fsp_err_t R_GPIO_W_PortEventInputRead ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_t  port,
ioport_size_t p_event_data 
)

Reads the value of the event input data. Implements ioport_api_t::portEventInputRead().

The event input data for the port will be read. Each bit in the returned value corresponds to a pin on the port. For example, bit 7 corresponds to pin 7, bit 6 to pin 6, and so on.

The port event data is captured in response to a trigger from the ELC. This function enables this data to be read. Using the event system allows the captured data to be stored when it occurs and then read back at a later time.

Return values
FSP_SUCCESSPort read
FSP_ERR_INVALID_ARGUMENTPort not a valid ELC port
FSP_ERR_ASSERTIONNULL pointer
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_UNSUPPORTEDFunction not supported.
Note
This function is re-entrant for different ports.

◆ R_GPIO_W_PinEventInputRead()

fsp_err_t R_GPIO_W_PinEventInputRead ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_pin_t  pin,
bsp_io_level_t p_pin_event 
)

Reads the value of the event input data of a specific pin. Implements ioport_api_t::pinEventInputRead.

The pin event data is captured in response to a trigger from the ELC. This function enables this data to be read. Using the event system allows the captured data to be stored when it occurs and then read back at a later time.

Return values
FSP_SUCCESSPin read
FSP_ERR_ASSERTIONNULL pointer
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_INVALID_ARGUMENTPort is not valid ELC PORT.
FSP_ERR_UNSUPPORTEDFunction not supported.
Note
This function is re-entrant.

◆ R_GPIO_W_PortEventOutputWrite()

fsp_err_t R_GPIO_W_PortEventOutputWrite ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_t  port,
ioport_size_t  event_data,
ioport_size_t  mask_value 
)

This function writes the set and reset event output data for a port. Implements ioport_api_t::portEventOutputWrite.

Using the event system enables a port state to be stored by this function in advance of being output on the port. The output to the port will occur when the ELC event occurs.

The input value will be written to the specified port when an ELC event configured for that port occurs. Each bit in the value parameter corresponds to a bit on the port. For example, bit 7 corresponds to pin 7, bit 6 to pin 6, and so on. Each bit in the mask parameter corresponds to a pin on the port.

Return values
FSP_SUCCESSPort event data written
FSP_ERR_INVALID_ARGUMENTPort or Mask not valid
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_ASSERTIONNULL pointer
Note
This function is re-entrant for different ports.

◆ R_GPIO_W_PinEventOutputWrite()

fsp_err_t R_GPIO_W_PinEventOutputWrite ( ioport_ctrl_t *const  p_ctrl,
bsp_io_port_pin_t  pin,
bsp_io_level_t  pin_value 
)

This function writes the event output data value to a pin. Implements ioport_api_t::pinEventOutputWrite.

Using the event system enables a pin state to be stored by this function in advance of being output on the pin. The output to the pin will occur when the ELC event occurs.

Return values
FSP_SUCCESSPin event data written
FSP_ERR_INVALID_ARGUMENTPort or Pin or value not valid
FSP_ERR_NOT_OPENThe module has not been opened
FSP_ERR_ASSERTIONNULL pointer
Note
This function is re-entrant for different ports.