SPI Flash - InstrFetchProhibited occured

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

SPI Flash - InstrFetchProhibited occured

Postby battancs.zsolt » Thu Apr 20, 2017 2:23 pm

Hi,

I write a small c++ code, with spi read and write.

The code throw error - "InstrFetchProhibited occured".

I read http://esp-idf.readthedocs.io/en/latest ... flash.html page.
This page speak - "Concurrency Constraints".
I tried a lot, but unsuccessfully.

What do you suggest?

Thanks,

zs

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: SPI Flash - InstrFetchProhibited occured

Postby kolban » Fri Apr 21, 2017 4:11 am

I would suggest posting a fragment of code showing the exact statement that was being executed when the exception was caught.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Re: SPI Flash - InstrFetchProhibited occured

Postby battancs.zsolt » Fri Apr 21, 2017 8:57 am

Sorry for small info!


Some helper function:

Code: Select all

#include <esp_spi_flash.h>
#include <rom/spi_flash.h>
#include "../cache_utils.h"


SpiFlashOpResult IRAM_ATTR guarded_spi_flash_read(size_t src_addr, void *dest, size_t size){

	spi_flash_disable_interrupts_caches_and_other_cpu();
	SpiFlashOpResult ret = SPIRead(src_addr,dest,size);
	spi_flash_enable_interrupts_caches_and_other_cpu();

 	return ret;
}

SpiFlashOpResult IRAM_ATTR guarded_spi_flash_write(size_t src_addr, const uint32_t *dest, size_t size){

	spi_flash_disable_interrupts_caches_and_other_cpu();

	size_t alignedSize = size | 0x03;

	SpiFlashOpResult ret = SPIEraseArea(src_addr,alignedSize);
	ret = SPIWrite(src_addr,dest,size);
	spi_flash_enable_interrupts_caches_and_other_cpu();

 	return ret;
}

Config class:

Code: Select all

#ifndef CONFIG_H
#define CONFIG_H

#include <stdio.h>
#include "configuration.h"
#include <rom/spi_flash.h>

extern "C" SpiFlashOpResult guarded_spi_flash_read(size_t src_addr, void *dest, size_t size);
extern "C" SpiFlashOpResult guarded_spi_flash_write(size_t src_addr, const uint32_t *dest, size_t size);

class Config {
public:

	enum class NetworkType {
		AP, CLIENT, AP_CLIENT
	};

	Config(){};
    virtual ~Config(){};

    char ssid[32+1];
    char password[64+1];
    NetworkType networkType;

    virtual int sizeObject() {
    	return sizeof(class Config);
    }

    static int sizeClass() {
    	return sizeof(class Config);
    }

    virtual void getFromFlash() {
    	SpiFlashOpResult  err =   guarded_spi_flash_read((size_t)CONFIGURATION_CONFIG_START_ADDRESS,(void *)this,(size_t)sizeObject());
    }

    virtual void storeToFlash() {
    	SpiFlashOpResult  err =   guarded_spi_flash_write((size_t)CONFIGURATION_CONFIG_START_ADDRESS,(const uint32_t *)this,(size_t)sizeObject());
    }

	enum class ErrorType {
		OK = SPI_FLASH_RESULT_OK, SPI_FLASH_RESULT_ERR = SPI_FLASH_RESULT_ERR,SPI_FLASH_RESULT_TIMEOUT = SPI_FLASH_RESULT_TIMEOUT
	};


};

#endif /* CONFIG_H */


battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Re: SPI Flash - InstrFetchProhibited occured

Postby battancs.zsolt » Fri Apr 21, 2017 9:17 am

Symptoms:

- If I call the at the beginning code(see next section), and after call any location( for exampe - modified gatt server sample) - not error!

Code: Select all

	
extern "C" void app_main(void)
{
	spi_flash_init(); 
	nvs_flash_init(); 

	/* critical section */
	Config *testConfig = new Config;
	sprintf(testConfig->ssid,"ABCD");
	sprintf(testConfig->password,"XXXXXXXX");
	testConfig->storeToFlash();
	...
- but, I not execute this section, and after call any location( for exampe - modified gatt server sample) - error occured:

Code: Select all

Guru Meditation Error of type InstrFetchProhibited occurred on core  0. Exception was unhandled.
Register dump:
PC      : 0x00633269  PS      : 0x00060730  A0      : 0x800f624a  A1      : 0x3ffd59e0  
A2      : 0x3ffd1040  A3      : 0x00000004  A4      : 0x3ffd5cc0  A5      : 0x00633269  
A6      : 0x3f404924  A7      : 0x3ffcbb6c  A8      : 0x800f6055  A9      : 0x3ffd59d0  
A10     : 0x3ffd1040  A11     : 0x3ffd59fc  A12     : 0x000000ff  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000004  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00633268  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffc  

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Re: SPI Flash - InstrFetchProhibited occured

Postby battancs.zsolt » Sat Apr 22, 2017 12:23 am

Hi,

I make a git repository, for this problem:

https://github.com/Battancs/esp32_test_snippets

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: SPI Flash - InstrFetchProhibited occured

Postby WiFive » Sat Apr 22, 2017 2:05 am

Did you check https://github.com/espressif/esp-idf/bl ... ops.c#L187

You don't want to use nvs?

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Re: SPI Flash - InstrFetchProhibited occured

Postby battancs.zsolt » Sat Apr 22, 2017 4:57 am

WiFive wrote:Did you check https://github.com/espressif/esp-idf/bl ... ops.c#L187

You don't want to use nvs?
Good questions!

- I try spi_flash_write, read, erase combo. The result is the same. (InstrFetchProhibited)
- In my project want (must) use simple, own filesystem with big file. I also need to use these functions.

So, I must use spi_flash_read from any code!

Who is online

Users browsing this forum: No registered users and 97 guests