1.1.5.2.2 Using The Library

The SST39 driver provides the blocking API's to read, write and erase SST39 memory.

The SST39 driver can be used in following ways:

  • To perform sector erase operation.

  • To perform chip erase operation.

  • To perform page write to the SST39.

  • To read the product identification codes of the SST39.

Example application to Erase, Write and Read SST39 Memory

#define BUFFER_SIZE                       (DRV_SST39_PAGE_SIZE)
#define SST39_MANUFACTURER_ID             (0xBFU)
#define SST39_DEVICE_ID                   (0xD7U)

APP_DATA appData;

void APP_Initialize ( void )
{
    uint32_t i = 0;

    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;

    for (i = 0; i < BUFFER_SIZE; i++)
    {
        appData.writeBuffer[i] = i;
    }
}

void APP_Tasks ( void )
{

    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            if (DRV_SST39_Status(DRV_SST39_INDEX) == SYS_STATUS_READY)
            {
                appData.state = APP_STATE_OPEN_DRIVER;
            }
            break;
        }

        case APP_STATE_OPEN_DRIVER:
        {
            appData.handle = DRV_SST39_Open((SYS_MODULE_INDEX)DRV_SST39_INDEX, DRV_IO_INTENT_READWRITE);

            if (appData.handle != DRV_HANDLE_INVALID)
            {
                appData.state = APP_STATE_ID_GET;
            }
            break;
        }

        case APP_STATE_ID_GET:
        {
            if (DRV_SST39_ReadProductId(appData.handle, &appData.readManId, &appData.readDeviceId) != true)
            {
                appData.state = APP_STATE_ERROR;
            }
            else
            {
                if ( (appData.readManId == SST39_MANUFACTURER_ID) && (appData.readDeviceId == SST39_DEVICE_ID) )
                {
                    appData.state = APP_STATE_ERASE_FLASH;
                }
            }
            break;
        }

        case APP_STATE_ERASE_FLASH:
        {
            if (DRV_SST39_ChipErase(appData.handle) != true)
            {
                appData.state = APP_STATE_ERROR;
            }
            else
            {
                appData.state = APP_STATE_WRITE_MEMORY;
            }
            break;
        }

        case APP_STATE_WRITE_MEMORY:
        {
            if (DRV_SST39_PageWrite(appData.handle, appData.writeBuffer, 0x60000000U) != true)
            {
                appData.state = APP_STATE_ERROR;
            }
            else
            {
                appData.state = APP_STATE_READ_MEMORY;
            }
            break;
        }
        
        case APP_STATE_READ_MEMORY:
        {
            if (DRV_SST39_Read(appData.handle, appData.readBuffer, BUFFER_SIZE, 0x60000000U) != true)
            {
                appData.state = APP_STATE_ERROR;
            }
            else
            {
                appData.state = APP_STATE_VERIFY_DATA;
            }
            break;
        }    

        case APP_STATE_VERIFY_DATA:
        {
            if (!memcmp(appData.writeBuffer, appData.readBuffer, BUFFER_SIZE))
            {
                appData.state = APP_STATE_SUCCESS;
            }
            else
            {
                appData.state = APP_STATE_ERROR;
            }
            break;
        }

        case APP_STATE_SUCCESS:
        case APP_STATE_ERROR:
        default:
            break;
    }
}