FLASH Interface

FLASH Platform interface

FLASH Overview

Flash memory is a non-volatile storage technology commonly used in embedded systems, microcontrollers, and electronic devices to store code, configuration data, and other information. It retains data even when the power is turned off, making it ideal for long-term storage needs.

Supported Communication Modes

The following modes of FLASH:

  • Blocking - The operation (e.g., read, write, or erase) is performed synchronously, meaning the function call waits until the operation is complete before returning control to the caller.

  • Non-Blocking - The function returns immediately after initiating the operation. A callback or interrupt is used to notify the completion of the operation, allowing other tasks to execute concurrently.

FLASH BUS Interface

The Flash bus interface defines how the flash memory is connected to the system:

  • FLASH Internal Type : The flash memory is located within the internal device memory.

  • FLASH External Type : The flash memory is an external device connected to the system.

  • FLASH Interface SPI : The flash memory is an external device connected via the SPI (Serial Peripheral Interface) bus.

Application Interface

Users can directly call the API’s though most of them will be called by device drivers.

The below table captures the functions that are to be called from the application layer.

API Functions

Function

Description

rs_flash_open

To open the FLASH interface.

rs_flash_set_config

To configure the FLASH interface.

rs_flash_enable_write

To enables write access for the FLASH

rs_flash_disable_write

To disables write access in the FLASH

rs_flash_erase

To erases the given page in the FLASH

rs_flash_write

To writes the given data in the FLASH

rs_flash_read

To reads the data from the FLASH

rs_flash_register_completion_callback

Registers the given callback function for completion of FLASH operation

rs_flash_read_uuid

To reads UUID from the FLASH.

rs_flash_close

To close the FLASH

Error Code

  • Every API’s for the FLASH returns some success or failure values. Please refer below section,

Implementation Guide

This section explains how to implement the FLASH interface using the RAPIDSEA stack, the steps to be followed are

  • Configure the FLASH interface(flash type, interface handle, page count, page size,write protect port and pin).

  • Open the FLASH depends on the FLASH type.

  • Register the FLASH completion callback.

  • Perform the read and write FLASH functions as required and handle the error codes.

  • Close the FLASH interface.

Documentation from the relevant header as follows:

FLASH Specific APIs.

Defines macros and functions specific to FLASH functionality

Author

Embien RAPIDSEA Team

Copyright

Embien Technologies India Pvt. Ltd.

Defines

RS_FLASH_INTERNAL_TYPE

FLASH Bus Interface Internal device memory

RS_FLASH_EXTERNAL_TYPE

External device memory.

RS_FLASH_INTERFACE_SPI

Connected over SPI.

RS_FLASH_STATUS_WRITE_PROTECTED

FLASH Status Device is currently write-protected

RS_FLASH_STATUS_WRITE_ENABLED

Device is currently write-enabled.

RS_FLASH_BLOCKING

Operation mode Blocking Mode operation

RS_FLASH_NON_BLOCKING

Non-Blocking Mode operation.

Typedefs

typedef void (*rs_flash_callback)(rs_handle_t handle, rs_ret_val_t reason, void *ptr_args)

FLASH callback function.

typedef struct tag_rs_flash_config rs_flash_config_t

Structure for setting up FLASH configuration.

typedef struct tag_rs_flash_instance rs_flash_instance_t

Structure for the FLASH instance information.

typedef void (*rs_flash_callback_completion)(rs_handle_t handle, int32_t s32_result)

Callback function format.

This callback function is called on completion of given activity

Param handle:

[in] - Handle to the FLASH interface

Param s32_result:

[in] - Result of the last operation requested in non-blocking mode

Return:

None

Functions

rs_handle_t rs_flash_open(rs_flash_instance_t *ptr_instance, rs_flash_config_t *ptr_config)

Configures the FLASH device for further operations.

This function configures/re-configures FLASH as per given configuration

Parameters:

ptr_instance[in] - Pointer to the FLASH instance ptr_config - Pointer to the configuration structure

Returns:

handle to FLASH on success or error code on failure

rs_ret_val_t rs_flash_set_config(rs_flash_config_t *ptr_config, uint8_t u8_flash_type, uint32_t u32_interface_handle, uint32_t u32_max_size, uint16_t u16_page_count, uint16_t u16_page_size, uint8_t u8_write_protect_port, uint16_t u16_write_protect_pin)
rs_ret_val_t rs_flash_is_write_enabled(rs_handle_t handle)

Returns the write protected status of FLASH.

This function queries the current status of FLASH and returns based on its write-protected state

Parameters:

handle[in] - Handle to FLASH device

Returns:

1 if write enabled or 0 if write protested

rs_ret_val_t rs_flash_enable_write(rs_handle_t handle)

Enables write access for the FLASH.

This function executes FLASH Write enable sequence and drives WP pin suitably, if needed

Parameters:

handle[in] - Handle to FLASH device

Returns:

0 on success or error code on failure

rs_ret_val_t rs_flash_disable_write(rs_handle_t handle)

Disables write access in the FLASH.

This function executes FLASH Write disable sequence and drives WP pin suitably, if needed

Parameters:

handle[in] - Handle to FLASH device

Returns:

0 on success or error code on failure

rs_ret_val_t rs_flash_erase(rs_handle_t handle, uint32_t u32_addr, uint32_t u32_size)
rs_ret_val_t rs_flash_write(rs_handle_t handle, uint32_t u32_addr, void *ptr_write_data, uint32_t u32_write_len, uint32_t u32_time_out)

Writes the given data in the FLASH.

This function writes the given data at the given address

Parameters:
  • handle[in] - Handle to FLASH device

  • u32_addr[in] - Address to write to

  • ptr_write_data[in] - Pointer to write buffer

  • u32_write_len[in] - Number of bytes to write to

  • u32_time_out[in] - Time out in ms to wait for write complete

Returns:

Number of bytes written on success or error code on failure

rs_ret_val_t rs_flash_read(rs_handle_t handle, uint32_t u32_addr, void *ptr_read_data, uint32_t u32_read_len, uint32_t u32_time_out)
rs_ret_val_t rs_flash_register_completion_callback(rs_handle_t handle, rs_flash_callback_completion ptr_func)

Registers the given callback function for completion of FLASH operation.

This function registers the given callback function for completion of transfer operation

Parameters:
  • handle[in] - Handle to the FLASH device

  • ptr_func[in] - Callback function to call to

Returns:

0 on success or error code on failure

rs_ret_val_t rs_flash_read_uuid(rs_handle_t handle, uint8_t *ptr_uuid_buff)

Read UUID from the FLASH.

This function to read the UUID from the FLASH.

Parameters:
  • handle[in] - Handle to FLASH device

  • ptr_uuid_buff[out] - Pointer to store the uuid.

Returns:

0 on success or error code on failure

rs_ret_val_t rs_flash_close(rs_handle_t handle)

Un-initializes the FLASH.

This function un-initializes the FLASH and releases the underlying resources

Parameters:

handle[in] - Handle to FLASH device

Returns:

0 on success or error code on failure

struct tag_rs_flash_config
#include <rs_flash.h>

Structure for setting up FLASH configuration.

Public Members

uint32_t interface_handle

Interface handle.

uint8_t flash_type

FLASH type.

uint32_t flash_max_size

FLASH maximum size.

uint16_t flash_max_page_count

FLASH maximum page count.

uint16_t flash_page_size

FLASH page size.

uint8_t write_protect_port

FLASH write protect port.

uint16_t write_protect_pin

FLASH write protect pin.

struct tag_rs_flash_instance
#include <rs_flash.h>

Structure for the FLASH instance information.

Public Members

rs_flash_config_t *ptr_config

Pointer to the configuration structure.

rs_flash_callback ptr_cb

Pointer to the callback function.

void *ptr_arg

Pointer to the callback function argument.