Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI_FLASH_MMAP_INST Exception #378

Closed
elix22 opened this issue Feb 24, 2017 · 2 comments
Closed

SPI_FLASH_MMAP_INST Exception #378

elix22 opened this issue Feb 24, 2017 · 2 comments
Assignees
Labels
Type: Bug bugs in IDF

Comments

@elix22
Copy link

elix22 commented Feb 24, 2017

Attached a small example that triggers the exception.
Both the address and the size are 4 bytes aligned .
100% reproducible
Looks like a genuine issue.

`#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include <esp_log.h>
#include <esp_err.h>
#include <esp_spi_flash.h>

#define ADDR 0x300000
#define MEMMAP_SIZE (1024*1024)

static char tag[] = "memmap_test";

static spi_flash_mmap_handle_t handle;

static uint32_t pInstrPtr = 0;

void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
spi_flash_init();

esp_err_t rc = spi_flash_mmap((uint32_t) ADDR, MEMMAP_SIZE, SPI_FLASH_MMAP_INST, (const void **)&pInstrPtr, &handle);

if (rc != ESP_OK) {
ESP_LOGE(tag, "rc from spi_flash_mmap: %d", rc);
}
else
{
ESP_LOGD(tag, "spi_flash_mmap success");
}
}
`

@igrr igrr self-assigned this Feb 24, 2017
@igrr igrr added the Type: Bug bugs in IDF label Feb 24, 2017
@igrr
Copy link
Member

igrr commented Feb 24, 2017

Thanks for reporting this.
The fix is basically:

diff --git a/components/spi_flash/flash_mmap.c b/components/spi_flash/flash_mmap.c
index f8d2e32..8d284c6 100644
--- a/components/spi_flash/flash_mmap.c
+++ b/components/spi_flash/flash_mmap.c
@@ -122,7 +122,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_
         region_addr = VADDR0_START_ADDR;
     } else {
         // only part of VAddr1 is usable, so adjust for that
-        region_begin = VADDR1_FIRST_USABLE_ADDR;
+        region_begin = PRO_IRAM0_FIRST_USABLE_PAGE;
         region_size = 3 * 64 - region_begin;
         region_addr = VADDR1_FIRST_USABLE_ADDR;
     }
@@ -177,7 +177,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_
         new_entry->count = page_count;
         new_entry->handle = ++s_mmap_last_handle;
         *out_handle = new_entry->handle;
-        *out_ptr = (void*) (region_addr + start * SPI_FLASH_MMU_PAGE_SIZE);
+        *out_ptr = (void*) (region_addr + (start - region_begin) * SPI_FLASH_MMU_PAGE_SIZE);
         ret = ESP_OK;
     }

It'll be in master after review.

@elix22
Copy link
Author

elix22 commented Feb 24, 2017

It works
Thanks

@projectgus projectgus added the Status: In Progress Work is in progress label Feb 27, 2017
@igrr igrr closed this as completed in c025dfb Mar 2, 2017
@igrr igrr removed the Status: In Progress Work is in progress label Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants