Hi Carl,
I often don't hear what people are asking! Sorry.
Yes you can erase 0x1000 with FSLMQX.
I cannot attach file for some dumb reason...will hassle our IT people...but hear is copy-n-paste of it.
uint_32 app_flash_erase
(
uint_32 initial_data
)
{
FLASHX_BLOCK_INFO_STRUCT_PTR info_ptr;
FILE_PTR flash_hdl;
_mqx_uint error_code=FALSE;
_mem_size base_addr;
_mqx_uint num_sectors;
_mqx_uint num_blocks;
_mqx_uint width;
_mem_size total_size = 0;
_mem_size block_boundary_addr = 0;
uchar_ptr read_buffer;
_mqx_int i, k;
_mem_size seek_location;
_mem_size read_write_size = 0;
_mqx_uint ident_arr[3];
boolean test_completed = FALSE;
puts("\n\nMQX Flash Erase Program");
/* Open the flash device */
flash_hdl = flash_open(FLASH_NAME);
_io_ioctl(flash_hdl, IO_IOCTL_DEVICE_IDENTIFY, &ident_arr[0]);
printf("\nFlash Device Identity: %#010x, %#010x, %#010x",
ident_arr[0], ident_arr[1], ident_arr[2]);
error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BASE_ADDRESS, &base_addr); //DES base_addr=Start Address of Application Code
if (error_code != MQX_OK) {
printf("\nFLASH_IOCTL_GET_BASE_ADDRESS failed.");
_task_block();
} else {
printf("\nThe BASE_ADDRESS: 0x%x", base_addr);
} /* Endif */
error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_NUM_SECTORS, &num_sectors);
if (error_code != MQX_OK) {
printf("\nFLASH_IOCTL_GET_NUM_SECTORS failed.");
_task_block();
} else {
printf("\nNumber of sectors: %d", num_sectors);
} /* Endif */
error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_WIDTH, &width);
if (error_code != MQX_OK) {
printf("\nFLASH_IOCTL_GET_WIDTH failed.");
_task_block();
} else {
printf("\nThe WIDTH: %d", width);
} /* Endif */
error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BLOCK_MAP,
(uint_32 _PTR_)&info_ptr);
if (error_code != MQX_OK) {
printf("\nFLASH_IOCTL_GET_BLOCK_MAP failed.");
_task_block();
} /* Endif */
error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BLOCK_GROUPS, &num_blocks);
if (error_code != MQX_OK) {
printf("\nFLASH_IOCTL_GET_NUM_BLOCKS failed");
_task_block();
} /* Endif */
for ( i = 0; i < num_blocks; i++ ) {
printf("\nThere are %d sectors in Block %d", info_ptr[i].NUM_SECTORS,
(i + 1));
printf("\nBlock %d Sector Size: %d (0x%x)", (i + 1),
info_ptr[i].SECT_SIZE, info_ptr[i].SECT_SIZE);
total_size += (info_ptr[i].SECT_SIZE * info_ptr[i].NUM_SECTORS);
} /* Endfor */
printf("\nApplication size of the Flash to erase is: %d (0x%08x) bytes", total_size,
total_size);
#if WRITE_PROTECT_TEST
flash_write_ptotect_test(flash_hdl);
#endif
read_write_size = info_ptr[num_blocks-1].SECT_SIZE; //DES get "page" size to erase
read_buffer = allocate_buffer(read_write_size, read_write_size, "read"); //DES
if (read_buffer == 0 ) {
printf("\n\tFailed to acquire memory");
_task_block();
} /* Endif */
seek_location = 0;
for ( k = 0; k < num_sectors; k++) {
/* Seek to sector, and erase it */
//DES printf("\nTesting _io_ioctl erase_sector: %d (0x%x)", seek_location, seek_location);
fseek(flash_hdl, seek_location, IO_SEEK_SET);
error_code = _io_ioctl(flash_hdl, FLASH_IOCTL_ERASE_SECTOR, NULL);
if (error_code != MQX_OK) {
printf("\nFLASH_IOCTL_ERASE_SECTOR failed.");
_task_block();
} /* Endif */
/* Seek to erased sector, and read it */
fseek(flash_hdl, seek_location, IO_SEEK_SET);
i = read(flash_hdl, read_buffer, read_write_size);
if (i != read_write_size ) {
printf("\nFailed to read flash, 0x%x", _task_get_error());
} /* Endif */
/* Check if all ff's */
for ( i = 0; i < read_write_size; i++ ) {
if (read_buffer[i] != 0xff) {
printf("\nFailed to erase flash at index %d Seek location %d (0x%x)", i, seek_location, seek_location);
_task_block();
} /* Endif */
} /* Endfor */
seek_location+=0x1000; //DES increment pointer to next relative sector address to erase
} /* Endfor */
/* Close device */
flash_close(flash_hdl);
/* end */
printf("\n\tErase finshed");
return(error_code); //DES-USBStick
}
Hope this helps.
Regards,
David