本文整理汇总了C++中spi_flash_write函数的典型用法代码示例。如果您正苦于以下问题:C++ spi_flash_write函数的具体用法?C++ spi_flash_write怎么用?C++ spi_flash_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spi_flash_write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: user_esp_platform_save_param
/******************************************************************************
* FunctionName : user_esp_platform_save_param
* Description : toggle save param to two sector by flag value,
* : protect write and erase data while power off.
* Parameters : param -- the parame point which write the flash
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_save_param(void *param, uint16 len)
{
struct esp_platform_sec_flag_param flag;
spi_flash_read((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
if (flag.flag == 0) {
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_SAVE_1);
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_SAVE_1) * SPI_FLASH_SEC_SIZE,
(uint32 *)param, len);
flag.flag = 1;
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_FLAG);
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
} else {
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_SAVE_0);
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_SAVE_0) * SPI_FLASH_SEC_SIZE,
(uint32 *)param, len);
flag.flag = 0;
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_FLAG);
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
}
}
示例2: env_sf_save
static int env_sf_save(void)
{
u32 saved_size, saved_offset, sector;
char *saved_buffer = NULL;
int ret = 1;
env_t env_new;
ret = setup_flash_device();
if (ret)
return ret;
/* Is the sector larger than the env (i.e. embedded) */
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;
saved_buffer = malloc(saved_size);
if (!saved_buffer)
goto done;
ret = spi_flash_read(env_flash, saved_offset,
saved_size, saved_buffer);
if (ret)
goto done;
}
ret = env_export(&env_new);
if (ret)
goto done;
sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
puts("Erasing SPI flash...");
ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET,
sector * CONFIG_ENV_SECT_SIZE);
if (ret)
goto done;
puts("Writing to SPI flash...");
ret = spi_flash_write(env_flash, CONFIG_ENV_OFFSET,
CONFIG_ENV_SIZE, &env_new);
if (ret)
goto done;
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
ret = spi_flash_write(env_flash, saved_offset,
saved_size, saved_buffer);
if (ret)
goto done;
}
ret = 0;
puts("done\n");
done:
if (saved_buffer)
free(saved_buffer);
return ret;
}
示例3: iot_atcmd_exec_flash
/* Format: AT#FLASH -s6 -v56+enter*/
int16 iot_atcmd_exec_flash(puchar pCmdBuf, int16 AtCmdLen)
{
char *argv[MAX_OPTION_COUNT];
char *opString = "r:s:v:c:?";
char *endptr = NULL;
long num = 0;
int16 argc = 0;
char opt = 0;
uint32 fOffset = 0;
uint8 fData[1] = {0};
uint32 stringLen = 0;
uint8 buffer[48] = {0};
split_string_cmd(pCmdBuf, AtCmdLen, &argc, argv);
opt = getopt(argc, argv, opString);
while (opt != -1) {
switch (opt) {
case 'r':
/*Flash Read Offset*/
num = simple_strtol(optarg,&endptr,0);
spi_flash_read((uint32)num, fData, 1);
printf_high("[0x%x]=[0x%02x]\n",num,fData[0]);
break;
case 's':
/*Flash Write Offset*/
num = simple_strtol(optarg,&endptr,0);
fOffset = (uint32)num;
break;
case 'v':
/*Flash Write Value*/
num = simple_strtol(optarg,&endptr,0);
if ( (fOffset < FLASH_OFFSET_RESERVE_2_START) ||
((fOffset >= FLASH_OFFSET_STA_FW_START) && (fOffset < FLASH_OFFSET_RESERVE_7_START))) {
/*Protecte the FW region*/
printf_high("[0x%x] is not permit to write!\n",fOffset);
}else{
spi_flash_write(fOffset, (uint8*)&num, 1);
printf_high("[0x%x]=[0x%02x]\n",fOffset,num);
}
break;
case 'c':
stringLen = strlen(optarg);
if(stringLen > (sizeof(buffer)-1))
stringLen = sizeof(buffer)-1;
memcpy(buffer, optarg, stringLen);
buffer[stringLen] ='\0';
spi_flash_write(fOffset, (uint8*)buffer, stringLen+1);
printf_high("[0x%x]=%s\n",fOffset,buffer);
break;
case '?':
default:
break;
}
opt = getopt(argc, argv, opString);
}
return 0;
}
示例4: initializePage
IROM bool Flash::initializePage(uint32_t pageIdx,uint32_t sequence) {
// INFO(" pageIdx : %d sequence : %d ",pageIdx,sequence);
uint32_t sector = PAGE_START/PAGE_SIZE + pageIdx;
if ( spi_flash_erase_sector(sector) != SPI_FLASH_RESULT_OK ) return false;
uint32_t magic=PAGE_SIGNATURE;
if ( spi_flash_write(pageAddress(pageIdx),&magic, sizeof(magic))!= SPI_FLASH_RESULT_OK ) return false;
if ( spi_flash_write(pageAddress(pageIdx)+4,&sequence, sizeof(sequence))!= SPI_FLASH_RESULT_OK ) return false;
return true;
}
示例5: saveenv
int saveenv(void)
{
u32 saved_size, saved_offset;
char *saved_buffer = NULL;
u32 sector = 1;
int ret;
if (!env_flash) {
puts("Environment SPI flash not initialized\n");
return 1;
}
/* Is the sector larger than the env (i.e. embedded) */
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;
saved_buffer = malloc(saved_size);
if (!saved_buffer) {
ret = 1;
goto done;
}
ret = spi_flash_read(env_flash, saved_offset, saved_size, saved_buffer);
if (ret)
goto done;
}
if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) {
sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE;
if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE)
sector++;
}
puts("Erasing SPI flash...");
ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET, sector * CONFIG_ENV_SECT_SIZE);
if (ret)
goto done;
puts("Writing to SPI flash...");
ret = spi_flash_write(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, env_ptr);
if (ret)
goto done;
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
ret = spi_flash_write(env_flash, saved_offset, saved_size, saved_buffer);
if (ret)
goto done;
}
ret = 0;
puts("done\n");
done:
if (saved_buffer)
free(saved_buffer);
return ret;
}
示例6: set_arc_product
static int set_arc_product(int argc, char *const argv[])
{
int err = 0;
char *mystrerr = "ERROR: Failed to save factory info in spi location";
if (argc != 5)
return -1;
/* Check serial number */
if (strlen(argv[1]) != MAX_SERIAL_SIZE)
return -1;
/* Check HWaddrs */
if (ishwaddr(argv[2]) || ishwaddr(argv[3]) || ishwaddr(argv[4]))
return -1;
strcpy(smac[3], argv[1]);
strcpy(smac[2], argv[2]);
strcpy(smac[1], argv[3]);
strcpy(smac[0], argv[4]);
flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
/*
* Save factory defaults
*/
if (spi_flash_write(flash, FIRM_ADDR1, sizeof(smac), smac)) {
printf("%s: %s [1]\n", __func__, mystrerr);
err++;
}
if (spi_flash_write(flash, FIRM_ADDR2, sizeof(smac), smac)) {
printf("%s: %s [2]\n", __func__, mystrerr);
err++;
}
if (spi_flash_write(flash, FIRM_ADDR3, sizeof(smac), smac)) {
printf("%s: %s [3]\n", __func__, mystrerr);
err++;
}
if (spi_flash_write(flash, FIRM_ADDR4, sizeof(smac), smac)) {
printf("%s: %s [4]\n", __func__, mystrerr);
err++;
}
if (err == 4) {
printf("%s: %s [ALL]\n", __func__, mystrerr);
return -2;
}
return 0;
}
示例7: write_config
/*ALINK_CONFIG_LEN 2048, len need < ALINK_CONFIG_LEN */
static int ICACHE_FLASH_ATTR write_config(unsigned char *buffer, unsigned int len)
{
int res = 0, pos = 0;
if (buffer == NULL) {
return ALINK_ERR;
}
if (len > ALINK_CONFIG_LEN)
len = ALINK_CONFIG_LEN;
res = spi_flash_erase_sector(LFILE_START_ADDR / 4096); //one sector is 4KB
if (res != SPI_FLASH_RESULT_OK) {
wsf_err("erase flash data fail\n");
}
else {
wsf_err("erase flash data %d Byte\n", res);
}
os_printf("write data:\n");
res = spi_flash_write((LFILE_START_ADDR), (uint32 *)buffer, len);
if (res != SPI_FLASH_RESULT_OK) {
wsf_err("write data error\n");
return ALINK_ERR;
}
wsf_deb("write key(%s) success.", buffer);
return ALINK_OK;
}
示例8: spiflash_logic_write
int spiflash_logic_write(spiflash_logic_t *spiflash_logic,
unsigned long long offset,
unsigned int length,
unsigned char *buf)
{
unsigned int totalwrite = length;
unsigned int ret;
if (!length) {
printf("Attempt to write 0 Bytes\n");
return -1;
}
if ((offset > spiflash_logic->length)
|| (length > spiflash_logic->length)
|| ((offset + length) > spiflash_logic->length)) {
printf("Attempt to write outside the flash handle area, "
"flash handle size: 0x%08llx, offset: 0x%08llx, "
"length: 0x%08x, phylength: 0x%08llx\n",
spiflash_logic->length, offset,
length, offset + length);
return -1;
}
ret = spi_flash_write(spiflash_logic->spiflash,
spiflash_logic->address + offset,
length,
buf);
if (!ret)
return totalwrite;
return ret;
}
示例9: pageAddress
IROM bool Flash::writeItem( uint16_t index,uint8_t* start,uint32_t length) {
// INFO(" index : %u , length : %u ",index,length);
uint32_t address = pageAddress(_pageIdx)+_freePos;
Quad W;
W.index = index;
W.length=length;
// INFO(" address 0x%x length %d",address,length);
if (spi_flash_write(address,&W.w,4)!= SPI_FLASH_RESULT_OK ) return false;
for(uint32_t i=0;i<length+3;i+=4) {
W.w=0xFFFFFFFF;
for(uint32_t j=0;i+j<length && j<4;j++) W.b[j]=start[i+j];
if (spi_flash_write(address+4+i,&W.w,4)!= SPI_FLASH_RESULT_OK ) return false;
}
_freePos += 4+roundQuad(length);
return true;
}
示例10: rboot_set_config
// write the rboot config
// preserves the contents of the rest of the sector,
// so the rest of the sector can be used to store user data
// updates checksum automatically (if enabled)
bool ICACHE_FLASH_ATTR rboot_set_config(rboot_config *conf) {
uint8 *buffer;
buffer = (uint8*)os_malloc(SECTOR_SIZE);
if (!buffer) {
//os_printf("No ram!\r\n");
return false;
}
#ifdef BOOT_CONFIG_CHKSUM
conf->chksum = calc_chksum((uint8*)conf, (uint8*)&conf->chksum);
#endif
spi_flash_read(BOOT_CONFIG_SECTOR * SECTOR_SIZE, (uint32*)((void*)buffer), SECTOR_SIZE);
memcpy(buffer, conf, sizeof(rboot_config));
vPortEnterCritical();
spi_flash_erase_sector(BOOT_CONFIG_SECTOR);
vPortExitCritical();
taskYIELD();
vPortEnterCritical();
//spi_flash_write(BOOT_CONFIG_SECTOR * SECTOR_SIZE, (uint32*)((void*)buffer), SECTOR_SIZE);
spi_flash_write(BOOT_CONFIG_SECTOR * SECTOR_SIZE, (uint32*)((void*)buffer), SECTOR_SIZE);
vPortExitCritical();
os_free(buffer);
return true;
}
示例11: spi_flash_write_test
void ICACHE_FLASH_ATTR spi_flash_write_test(enum RUN_MODE mode)
{
rw_info rw;
os_memset(&rw, 0, sizeof(rw));
rw.server_addr = ipaddr_addr("192.168.0.241");
rw.server_port = 10010;
os_strcpy(rw.ssid, "useease2");
os_strcpy(rw.ssid_pwd, "1CBE991A14");
os_strcpy(rw.ssid_mine, "iPLUG");
os_strcpy(rw.ssid_pwd_mine, "iPLUG123");
rw.run_mode = mode;
rw.dev_type = DEV_PLUG;
show_rw(&rw);
//写入前,需要擦除
if (spi_flash_erase_sector(FLASH_HEAD_ADDR / (4 * 1024))
!= SPI_FLASH_RESULT_OK) {
os_printf("SPI FLASH ERASE ERROR\n");
} else {
os_printf("SPI FLASH ERASE SUCCESS\n");
}
//写入
if (spi_flash_write(FLASH_HEAD_ADDR, (uint32*) &rw, sizeof(rw))
!= SPI_FLASH_RESULT_OK) {
os_printf("SPI FLASH WRITE ERROR\n");
} else {
os_printf("SPI FLASH WRITE SUCCESS\n");
}
}
示例12: debug_FlashParamSv
void ICACHE_FLASH_ATTR
debug_FlashParamSv()
{
debug_FlashParamCsumSet();
spi_flash_erase_sector(Flash_DEBUG_INFO_ADDR);
spi_flash_write(Flash_DEBUG_INFO_ADDR*0x1000,(uint32*)&FlashDebugBufParam,sizeof(FlashDebugBufParam));
}
示例13: flash_data
LOCAL UP_STATUS ICACHE_FLASH_ATTR flash_data() {
if(mFlashingSector > UPLOADABLE_PAGE_END_SECTOR) {
return UP_STATUS_OVERFLOW;
}
if((SPI_FLASH_SEC_SIZE - mBufferPos) > 0) {
irom_read(&mBuffer[mBufferPos], (const char *)
(mFlashingSector * SPI_FLASH_SEC_SIZE + mBufferPos + IROM_FLASH_BASE_ADDRESS),
SPI_FLASH_SEC_SIZE - mBufferPos);
mBufferPos = SPI_FLASH_SEC_SIZE;
}
if(irom_cmp(mBuffer, (const char *)
(mFlashingSector * SPI_FLASH_SEC_SIZE + IROM_FLASH_BASE_ADDRESS),
SPI_FLASH_SEC_SIZE) == 0) {
mFlashingSector++;
return UP_STATUS_OK;
}
SpiFlashOpResult res;
res = spi_flash_erase_sector(mFlashingSector);
if(res == SPI_FLASH_RESULT_OK) {
dhdebug("Flashing page at address 0x%X", mFlashingSector * SPI_FLASH_SEC_SIZE);
res = spi_flash_write(mFlashingSector * SPI_FLASH_SEC_SIZE,
(uint32 *)mBuffer, SPI_FLASH_SEC_SIZE);
}
system_soft_wdt_feed();
if(res == SPI_FLASH_RESULT_OK) {
mFlashingSector++;
return UP_STATUS_OK;
}
return UP_STATUS_INTERNAL_ERROR;
}
示例14: while
void IRAM_ATTR SystemClass::internalApplyFirmwareUpdate(uint32_t readFlashOffset, uint32_t targetFlashOffset, int firmwareSize, bool outputDebug)
{
uint32_t to = targetFlashOffset;
uint32_t from = readFlashOffset;
int size = firmwareSize;
const int unit = INTERNAL_FLASH_SECTOR_SIZE;
char buf[unit];
while (size > 0)
{
int sect = to / unit;
if (outputDebug) ets_uart_printf("write: 0x%X -> 0x%X (sect: %d), %d\n", from, to, sect, size);
spi_flash_erase_sector(sect);
//ets_uart_printf("ers.");
spi_flash_read(from, (uint32*)buf, unit);
//ets_uart_printf("read.");
spi_flash_write(to, (uint32*)buf, unit);
//ets_uart_printf("wr.\r\n");
from += unit;
to += unit;
size -= unit;
}
if (outputDebug) ets_uart_printf("Firmware upgrade finished\n");
((void (*)(void))0x40000080)(); // Hardcore reset vector
ets_wdt_enable();
while (1)
; // Reboot anyway!
}
示例15: hpm_write_block_nvram
/**
* writes one block of the image to a device
*
* \param address write offset
* \param length number of bytes to write
* \param buffer write data buffer
* \return status code
*/
unsigned char hpm_write_block_nvram(int address, int length, unsigned char *buffer)
{
/* add offset for upper selected nvram regions */
address += (oem_config.update_nvram * BIOS_NVRAM_SIZE);
return spi_flash_write(&spi_flash, address, length, buffer);
}