1.1.5.1.2 Using The Library
The SST38 driver provides the blocking API's to read, write and erase SST38 memory.
The SST38 driver can be used in following ways:
To perform sector erase operation.
To perform chip erase operation.
To perform page write to the SST38.
To read the product identification codes of the SST38.
Example application to Erase, Write and Read SST38 Memory
#define BUFFER_SIZE (DRV_SST38_PAGE_SIZE) #define SST38_MANUFACTURER_ID (0x00BFU) #define SST38_DEVICE_ID (0x536BU) 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_SST38_Status(DRV_SST38_INDEX) == SYS_STATUS_READY) { appData.state = APP_STATE_OPEN_DRIVER; } break; } case APP_STATE_OPEN_DRIVER: { appData.handle = DRV_SST38_Open((SYS_MODULE_INDEX)DRV_SST38_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_SST38_ReadProductId(appData.handle, &appData.readManId, &appData.readDeviceId) != true) { appData.state = APP_STATE_ERROR; } else { if ( (appData.readManId == SST38_MANUFACTURER_ID) && (appData.readDeviceId == SST38_DEVICE_ID) ) { appData.state = APP_STATE_ERASE_FLASH; } } break; } case APP_STATE_ERASE_FLASH: { if (DRV_SST38_ChipErase(appData.handle) != true) { appData.state = APP_STATE_ERROR; } else { appData.state = APP_STATE_WRITE_MEMORY; } break; } case APP_STATE_WRITE_MEMORY: { if (DRV_SST38_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_SST38_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; } }