Merge pull request #674 from armink/master

[DeviceDrivers] 更新 SFUD 库源码;完善探测 SPI Flash 设备代码,确保被探测设备必须为 SPI 设备。
This commit is contained in:
Bernard Xiong 2016-10-15 11:44:46 +08:00 committed by GitHub
commit 60591fefb6
4 changed files with 29 additions and 23 deletions

View File

@ -73,7 +73,7 @@ if (!(EXPR)) \
else {if (__delay_temp) {__delay_temp();} retry --;} else {if (__delay_temp) {__delay_temp();} retry --;}
/* software version number */ /* software version number */
#define SFUD_SW_VERSION "0.10.06" #define SFUD_SW_VERSION "0.10.14"
/* /*
* all defined supported command * all defined supported command
*/ */

View File

@ -354,7 +354,7 @@ sfud_err sfud_chip_erase(const sfud_flash *flash) {
/* set the flash write enable */ /* set the flash write enable */
result = set_write_enabled(flash, true); result = set_write_enabled(flash, true);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
goto exit; goto __exit;
} }
cmd_data[0] = SFUD_CMD_ERASE_CHIP; cmd_data[0] = SFUD_CMD_ERASE_CHIP;
@ -369,11 +369,13 @@ sfud_err sfud_chip_erase(const sfud_flash *flash) {
} }
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
SFUD_INFO("Error: Flash chip erase SPI communicate error."); SFUD_INFO("Error: Flash chip erase SPI communicate error.");
goto exit; goto __exit;
} }
result = wait_busy(flash); result = wait_busy(flash);
exit: __exit:
/* set the flash write disable */
set_write_enabled(flash, false);
/* unlock SPI */ /* unlock SPI */
if (spi->unlock) { if (spi->unlock) {
spi->unlock(spi); spi->unlock(spi);
@ -438,7 +440,7 @@ sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size) {
/* set the flash write enable */ /* set the flash write enable */
result = set_write_enabled(flash, true); result = set_write_enabled(flash, true);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
break; goto __exit;
} }
cmd_data[0] = cur_erase_cmd; cmd_data[0] = cur_erase_cmd;
@ -447,11 +449,11 @@ sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size) {
result = spi->wr(spi, cmd_data, cmd_size, NULL, 0); result = spi->wr(spi, cmd_data, cmd_size, NULL, 0);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
SFUD_INFO("Error: Flash erase SPI communicate error."); SFUD_INFO("Error: Flash erase SPI communicate error.");
break; goto __exit;
} }
result = wait_busy(flash); result = wait_busy(flash);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
break; goto __exit;
} }
/* make erase align and calculate next erase address */ /* make erase align and calculate next erase address */
if (addr % cur_erase_size != 0) { if (addr % cur_erase_size != 0) {
@ -459,18 +461,21 @@ sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size) {
size -= cur_erase_size - (addr % cur_erase_size); size -= cur_erase_size - (addr % cur_erase_size);
addr += cur_erase_size - (addr % cur_erase_size); addr += cur_erase_size - (addr % cur_erase_size);
} else { } else {
break; goto __exit;
} }
} else { } else {
if (size > cur_erase_size) { if (size > cur_erase_size) {
size -= cur_erase_size; size -= cur_erase_size;
addr += cur_erase_size; addr += cur_erase_size;
} else { } else {
break; goto __exit;
} }
} }
} }
__exit:
/* set the flash write disable */
set_write_enabled(flash, false);
/* unlock SPI */ /* unlock SPI */
if (spi->unlock) { if (spi->unlock) {
spi->unlock(spi); spi->unlock(spi);
@ -517,7 +522,7 @@ static sfud_err page256_or_1_byte_write(const sfud_flash *flash, uint32_t addr,
/* set the flash write enable */ /* set the flash write enable */
result = set_write_enabled(flash, true); result = set_write_enabled(flash, true);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
break; goto __exit;
} }
cmd_data[0] = SFUD_CMD_PAGE_PROGRAM; cmd_data[0] = SFUD_CMD_PAGE_PROGRAM;
make_adress_byte_array(flash, addr, &cmd_data[1]); make_adress_byte_array(flash, addr, &cmd_data[1]);
@ -545,15 +550,18 @@ static sfud_err page256_or_1_byte_write(const sfud_flash *flash, uint32_t addr,
result = spi->wr(spi, cmd_data, cmd_size + data_size, NULL, 0); result = spi->wr(spi, cmd_data, cmd_size + data_size, NULL, 0);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
SFUD_INFO("Error: Flash write SPI communicate error."); SFUD_INFO("Error: Flash write SPI communicate error.");
break; goto __exit;
} }
result = wait_busy(flash); result = wait_busy(flash);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
break; goto __exit;
} }
data += data_size; data += data_size;
} }
__exit:
/* set the flash write disable */
set_write_enabled(flash, false);
/* unlock SPI */ /* unlock SPI */
if (spi->unlock) { if (spi->unlock) {
spi->unlock(spi); spi->unlock(spi);
@ -599,7 +607,7 @@ static sfud_err aai_write(const sfud_flash *flash, uint32_t addr, size_t size, c
/* set the flash write enable */ /* set the flash write enable */
result = set_write_enabled(flash, true); result = set_write_enabled(flash, true);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
goto exit; goto __exit;
} }
/* loop write operate. write unit is write granularity */ /* loop write operate. write unit is write granularity */
cmd_data[0] = SFUD_CMD_AAI_WORD_PROGRAM; cmd_data[0] = SFUD_CMD_AAI_WORD_PROGRAM;
@ -632,21 +640,21 @@ static sfud_err aai_write(const sfud_flash *flash, uint32_t addr, size_t size, c
result = spi->wr(spi, cmd_data, cmd_size + data_size, NULL, 0); result = spi->wr(spi, cmd_data, cmd_size + data_size, NULL, 0);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
SFUD_INFO("Error: Flash write SPI communicate error."); SFUD_INFO("Error: Flash write SPI communicate error.");
goto exit; goto __exit;
} }
result = wait_busy(flash); result = wait_busy(flash);
if (result != SFUD_SUCCESS) { if (result != SFUD_SUCCESS) {
goto exit; goto __exit;
} }
size -= 2; size -= 2;
data += data_size; data += data_size;
} }
/* set the flash write disable */
result = set_write_enabled(flash, false);
exit: __exit:
/* set the flash write disable for exist AAI mode */
set_write_enabled(flash, false);
/* unlock SPI */ /* unlock SPI */
if (spi->unlock) { if (spi->unlock) {
spi->unlock(spi); spi->unlock(spi);

View File

@ -105,8 +105,6 @@ static bool read_sfdp_header(sfud_flash *flash) {
uint32_t header_addr = 0; uint32_t header_addr = 0;
/* each parameter header being 2 DWORDs (64-bit) */ /* each parameter header being 2 DWORDs (64-bit) */
uint8_t header[2 * 4] = { 0 }; uint8_t header[2 * 4] = { 0 };
/* number of parameter headers */
uint8_t npn = 0;
SFUD_ASSERT(flash); SFUD_ASSERT(flash);
@ -126,12 +124,12 @@ static bool read_sfdp_header(sfud_flash *flash) {
} }
sfdp->minor_rev = header[4]; sfdp->minor_rev = header[4];
sfdp->major_rev = header[5]; sfdp->major_rev = header[5];
npn = header[6];
if (sfdp->major_rev > SUPPORT_MAX_SFDP_MAJOR_REV) { if (sfdp->major_rev > SUPPORT_MAX_SFDP_MAJOR_REV) {
SFUD_INFO("Error: This reversion(V%d.%d) SFDP is not supported.", sfdp->major_rev, sfdp->minor_rev); SFUD_INFO("Error: This reversion(V%d.%d) SFDP is not supported.", sfdp->major_rev, sfdp->minor_rev);
return false; return false;
} }
SFUD_DEBUG("Check SFDP header is OK. The reversion is V%d.%d, NPN is %d.", sfdp->major_rev, sfdp->minor_rev, npn); SFUD_DEBUG("Check SFDP header is OK. The reversion is V%d.%d, NPN is %d.", sfdp->major_rev, sfdp->minor_rev,
header[6]);
return true; return true;
} }

View File

@ -264,7 +264,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
{ {
/* RT-Thread SPI device initialize */ /* RT-Thread SPI device initialize */
rtt_dev->rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name); rtt_dev->rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
if (rtt_dev->rt_spi_device == RT_NULL) { if (rtt_dev->rt_spi_device == RT_NULL || rtt_dev->rt_spi_device->parent.type != RT_Device_Class_SPIDevice) {
rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name); rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
goto error; goto error;
} }