本文整理汇总了C++中spi_flash_read函数的典型用法代码示例。如果您正苦于以下问题:C++ spi_flash_read函数的具体用法?C++ spi_flash_read怎么用?C++ spi_flash_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spi_flash_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_mac_addr
static int get_mac_addr(u8 *addr)
{
struct spi_flash *flash;
int ret;
flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
if (!flash) {
printf("Error - unable to probe SPI flash.\n");
return -1;
}
ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr);
if (ret) {
printf("Error - unable to read MAC address from SPI flash.\n");
return -1;
}
return ret;
}
示例2: env_relocate_spec
void env_relocate_spec(void)
{
int ret;
env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
if (!env_flash)
goto err_probe;
ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, env_ptr);
if (ret)
goto err_read;
if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
goto err_crc;
gd->env_valid = 1;
return;
err_read:
puts("*** Warning - read\n");
spi_flash_free(env_flash);
env_flash = NULL;
err_probe:
puts("*** Warning - probe\n");
err_crc:
puts("*** Warning - CRC\n");
puts("*** Warning - bad CRC, using default environment\n\n");
if (default_environment_size > CONFIG_ENV_SIZE) {
gd->env_valid = 0;
puts("*** Error - default environment is too large\n\n");
return;
}
memset(env_ptr, 0, sizeof(env_t));
memcpy(env_ptr->data, default_environment, default_environment_size);
env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
gd->env_valid = 1;
}
示例3: getFlashChipSpeed
uint32_t EspClass::getFlashChipSpeed(void)
{
uint32_t data;
uint8_t * bytes = (uint8_t *) &data;
// read first 4 byte (magic byte + flash config)
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
switch(bytes[3] & 0x0F) {
case 0x0: // 40 MHz
return (40_MHz);
case 0x1: // 26 MHz
return (26_MHz);
case 0x2: // 20 MHz
return (20_MHz);
case 0xf: // 80 MHz
return (80_MHz);
default: // fail?
return 0;
}
}
return 0;
}
示例4: get_sh_eth_mac_raw
static int get_sh_eth_mac_raw(unsigned char *buf, int size)
{
struct spi_flash *spi;
int ret;
spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
if (spi == NULL) {
printf("%s: spi_flash probe failed.\n", __func__);
return 1;
}
ret = spi_flash_read(spi, SH7753EVB_ETHERNET_MAC_BASE, size, buf);
if (ret) {
printf("%s: spi_flash read failed.\n", __func__);
spi_flash_free(spi);
return 1;
}
spi_flash_free(spi);
return 0;
}
示例5: MFSReadSector
int32_t MFSReadSector( uint8_t* data, struct MFSFileInfo * mfi )
{
//returns # of bytes left tin file.
if( !mfi->filelen )
{
return 0;
}
int toread = mfi->filelen;
if( toread > MFS_SECTOR ) toread = MFS_SECTOR;
EnterCritical();
flashchip->chip_size = 0x01000000;
spi_flash_read( mfs_at+mfi->offset, (uint32*)data, MFS_SECTOR );
flashchip->chip_size = 0x00080000;
ExitCritical();
mfi->offset += toread;
mfi->filelen -= toread;
return mfi->filelen;
}
示例6: esp_spiffs_readwrite
ICACHE_FLASH_ATTR static s32_t esp_spiffs_readwrite(u32_t addr, u32_t size,
u8 *p, int write) {
/*
* With proper configurarion spiffs never reads or writes more than
* LOG_PAGE_SIZE
*/
if (size > LOG_PAGE_SIZE) {
os_printf("Invalid size provided to read/write (%d)\n\r", (int) size);
return SPIFFS_ERR_NOT_CONFIGURED;
}
char tmp_buf[LOG_PAGE_SIZE + FLASH_UNIT_SIZE * 2];
u32_t aligned_addr = addr & (-FLASH_UNIT_SIZE);
u32_t aligned_size =
((size + (FLASH_UNIT_SIZE - 1)) & -FLASH_UNIT_SIZE) + FLASH_UNIT_SIZE;
int res = spi_flash_read(aligned_addr, (u32_t *) tmp_buf, aligned_size);
if (res != 0) {
os_printf("spi_flash_read failed: %d (%d, %d)\n\r", res, (int) aligned_addr,
(int) aligned_size);
return res;
}
if (!write) {
memcpy(p, tmp_buf + (addr - aligned_addr), size);
return SPIFFS_OK;
}
memcpy(tmp_buf + (addr - aligned_addr), p, size);
res = spi_flash_write(aligned_addr, (u32_t *) tmp_buf, aligned_size);
if (res != 0) {
os_printf("spi_flash_write failed: %d (%d, %d)\n\r", res,
(int) aligned_addr, (int) aligned_size);
return res;
}
return SPIFFS_OK;
}
示例7: flash_rom_set_speed
bool flash_rom_set_speed(uint32_t speed)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DBG("\nBEGIN SET FLASH HEADER\n");
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
uint8_t speed_type = SPEED_40MHZ;
if (speed < 26700000)
{
speed_type = SPEED_20MHZ;
}
else if (speed < 40000000)
{
speed_type = SPEED_26MHZ;
}
else if (speed < 80000000)
{
speed_type = SPEED_40MHZ;
}
else if (speed >= 80000000)
{
speed_type = SPEED_80MHZ;
}
if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
((SPIFlashInfo *)(&data[0]))->speed = speed_type;
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nERASE SUCCESS\n");
}
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nWRITE SUCCESS, %u\n", speed_type);
}
}
NODE_DBG("\nEND SET FLASH HEADER\n");
return true;
}
示例8: spiflash_logic_read
int spiflash_logic_read(spiflash_logic_t *spiflash_logic,
unsigned long long offset,
unsigned int length,
unsigned char *buf)
{
int ret;
if (!length) {
printf("Attempt to read 0 Bytes\n");
return -1;
}
if (offset > spiflash_logic->length) {
printf("Attempt to read outside the flash handle area, "
"flash handle size: 0x%08llx, offset: 0x%08llx\n",
spiflash_logic->length, offset);
return -1;
}
if ((offset + length) > spiflash_logic->length) {
length = spiflash_logic->length - offset;
printf("Read length is too large, "
"paratition size: 0x%08llx, read offset: 0x%08llx\n"
"Try to read 0x%08x instead!\n",
spiflash_logic->length,
offset,
length);
}
ret = spi_flash_read(spiflash_logic->spiflash,
spiflash_logic->address + offset,
length,
buf);
if (!ret)
return length;
return ret;
}
示例9: MFSOpenFile
//Returns 0 on succses.
//Returns size of file if non-empty
//If positive, populates mfi.
//Returns -1 if can't find file or reached end of file list.
int8_t MFSOpenFile( const char * fname, struct MFSFileInfo * mfi )
{
flashchip->chip_size = 0x01000000;
uint32 ptr = MFS_START;
struct MFSFileEntry e;
while(1)
{
spi_flash_read( ptr, (uint32*)&e, sizeof( e ) );
ptr += sizeof(e);
if( e.name[0] == 0xff || ets_strlen( e.name ) == 0 ) break;
if( ets_strcmp( e.name, fname ) == 0 )
{
mfi->offset = e.start;
mfi->filelen = e.len;
flashchip->chip_size = 0x00080000;
return 0;
}
}
flashchip->chip_size = 0x00080000;
return -1;
}
示例10: eeSetData
ICACHE_FLASH_ATTR void eeSetData(int address, void* buffer, int size) { // address, size in BYTES !!!!
uint8_t* inbuf = buffer;
while(1) {
uint32_t sector = (EEPROM_START + address) & 0xFFF000;
spi_flash_read(sector, (uint32 *)eebuf, 4096);
spi_flash_erase_sector(sector >> 12);
uint8_t* eebuf8 = (uint8_t*)eebuf;
uint16_t startaddr = address & 0xFFF;
uint16_t maxsize = 4096 - startaddr;
uint16_t i;
for(i=0; (i<size && i<maxsize); i++) eebuf8[i+startaddr] = inbuf[i];
spi_flash_write(sector, (uint32 *)eebuf, 4096);
if(maxsize >= size) break;
address += i;
inbuf += i;
size -= i;
}
}
示例11: flash_rom_set_size_type
bool flash_rom_set_size_type(uint8_t size)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DBG("\nBEGIN SET FLASH HEADER\n");
uint8_t data[SPI_FLASH_SEC_SIZE] ICACHE_STORE_ATTR;
if (SPI_FLASH_RESULT_OK == spi_flash_read(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
((SPIFlashInfo *)(&data[0]))->size = size;
if (SPI_FLASH_RESULT_OK == spi_flash_erase_sector(0 * SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nERASE SUCCESS\n");
}
if (SPI_FLASH_RESULT_OK == spi_flash_write(0, (uint32 *)data, SPI_FLASH_SEC_SIZE))
{
NODE_DBG("\nWRITE SUCCESS, %u\n", size);
}
}
NODE_DBG("\nEND SET FLASH HEADER\n");
return true;
}
示例12: user_light_init
/******************************************************************************
* FunctionName : user_light_init
* Description : light demo init, mainy init pwm
* Parameters : none
* Returns : none
*******************************************************************************/
void user_light_init(void)
{
/*init to off*/
uint32 pwm_duty_init[PWM_CHANNEL];
light_param.pwm_period = 1000;
memset(pwm_duty_init,0,PWM_CHANNEL*sizeof(uint32));
pwm_init(light_param.pwm_period, pwm_duty_init,PWM_CHANNEL,pwmio_info);
/*set target valuve from memory*/
spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,(uint32 *)&light_param, sizeof(struct light_saved_param));
if(light_param.pwm_period>10000 || light_param.pwm_period <1000){
light_param.pwm_period = 1000;
light_param.pwm_duty[0]= APP_MAX_PWM;
light_param.pwm_duty[1]= APP_MAX_PWM;
light_param.pwm_duty[2]= APP_MAX_PWM;
light_param.pwm_duty[3]= APP_MAX_PWM;
light_param.pwm_duty[4]= APP_MAX_PWM;
}
printf("LIGHT P:%d",light_param.pwm_period);
printf(" R:%d",light_param.pwm_duty[LIGHT_RED]);
printf(" G:%d",light_param.pwm_duty[LIGHT_GREEN]);
printf(" B:%d",light_param.pwm_duty[LIGHT_BLUE]);
if(PWM_CHANNEL>LIGHT_COLD_WHITE){
printf(" CW:%d",light_param.pwm_duty[LIGHT_COLD_WHITE]);
printf(" WW:%d\r\n",light_param.pwm_duty[LIGHT_WARM_WHITE]);
}else{
printf("\r\n");
}
light_set_aim(light_param.pwm_duty[LIGHT_RED],
light_param.pwm_duty[LIGHT_GREEN],
light_param.pwm_duty[LIGHT_BLUE],
light_param.pwm_duty[LIGHT_COLD_WHITE],
light_param.pwm_duty[LIGHT_WARM_WHITE],
light_param.pwm_period);
return;
}
示例13: getFlashChipSize
uint32_t EspClass::getFlashChipSize(void)
{
uint32_t data;
uint8_t * bytes = (uint8_t *) &data;
// read first 4 byte (magic byte + flash config)
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
switch((bytes[3] & 0xf0) >> 4) {
case 0x0: // 4 Mbit (512KB)
return (512_kB);
case 0x1: // 2 MBit (256KB)
return (256_kB);
case 0x2: // 8 MBit (1MB)
return (1_MB);
case 0x3: // 16 MBit (2MB)
return (2_MB);
case 0x4: // 32 MBit (4MB)
return (4_MB);
default: // fail?
return 0;
}
}
return 0;
}
示例14: platform_partition_info
bool platform_partition_info (uint8_t idx, platform_partition_t *info)
{
if (!possible_idx (idx))
return false;
partition_info_t pi;
esp_err_t err = spi_flash_read (
PARTITION_ADD + idx * sizeof(pi), (uint32_t *)&pi, sizeof (pi));
if (err != ESP_OK) {
return false;
}
if (pi.magic != PARTITION_MAGIC) {
return false;
}
memcpy (info->label, pi.label, sizeof (info->label));
info->offs = pi.pos.offset;
info->size = pi.pos.size;
info->type = pi.type;
info->subtype = pi.subtype;
return true;
}
示例15: update_image_length
static int update_image_length(struct spi_flash *flash,
unsigned int offset,
unsigned char *dest,
unsigned char flag)
{
unsigned int length = flash->page_size;
int ret;
ret = spi_flash_read(flash, offset, length, dest);
if (ret)
return -1;
if (flag == KERNEL_IMAGE)
return kernel_size(dest);
#ifdef CONFIG_OF_LIBFDT
else {
ret = check_dt_blob_valid((void *)dest);
if (!ret)
return of_get_dt_total_size((void *)dest);
}
#endif
return -1;
}