boards/xtensa/esp32/esp32-core: Support for the external FLASH.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2020-09-10 18:12:02 +01:00 committed by Matias N
parent c27bf32ce9
commit d485ccc142
5 changed files with 137 additions and 0 deletions

View File

@ -44,4 +44,23 @@ config ESP32CORE_FLASH_IMAGE
---help---
Create flash_image.bin mainly used for QEMU.
choice
prompt "SPIFLASH File System"
default ESP32_SPIFLASH_SMARTFS
depends on ESP32_SPIFLASH
config ESP32_SPIFLASH_SMARTFS
bool "SmartFS"
depends on FS_SMARTFS
config ESP32_SPIFLASH_NXFFS
bool "NXFFS"
depends on FS_NXFFS
config ESP32_SPIFLASH_SPIFFS
bool "SPIFFS"
depends on FS_SPIFFS
config ESP32_SPIFLASH_LITTLEFS
bool "LittleFS"
depends on FS_LITTLEFS
endchoice
endif # ARCH_BOARD_ESP32CORE

View File

@ -53,6 +53,10 @@ ifeq ($(CONFIG_MMCSD),y)
CSRCS += esp32_mmcsd.c
endif
ifeq ($(CONFIG_ESP32_SPIFLASH),y)
CSRCS += esp32_spiflash.c
endif
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32.template
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32_out.ld

View File

@ -87,5 +87,14 @@ int esp32_bringup(void);
int esp32_mmcsd_initialize(int minor);
/****************************************************************************
* Name: esp32_spiflash_init
*
* Description:
* Initialize the SPIFLASH and register the MTD device.
****************************************************************************/
int esp32_spiflash_init(void);
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_XTENSA_ESP32_ESP32_CORE_SRC_ESP32_CORE_H */

View File

@ -90,6 +90,10 @@ int esp32_bringup(void)
}
#endif
#ifdef CONFIG_ESP32_SPIFLASH
ret = esp32_spiflash_init();
#endif
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.

View File

@ -0,0 +1,101 @@
/****************************************************************************
* boards/xtensa/esp32/esp32-core/src/esp32_spiflash.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/mount.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/spi/spi.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/fs/nxffs.h>
#include "esp32_spiflash.h"
#include "esp32-core.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32_spiflash_init
*
* Description:
* Initialize the SPIFLASH and register the MTD device.
****************************************************************************/
int esp32_spiflash_init(void)
{
FAR struct mtd_dev_s *mtd;
int ret = ERROR;
mtd = esp32_spiflash_alloc_mtdpart();
#if defined (CONFIG_ESP32_SPIFLASH_SMARTFS)
ret = smart_initialize(0, mtd, NULL);
if (ret < 0)
{
finfo("smart_initialize failed, Trying to erase first...\n");
ret = mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);
if (ret < 0)
{
ferr("ERROR: ioctl(BULKERASE) failed: %d\n", ret);
return ret;
}
finfo("Erase successed, initializaing again\n");
ret = smart_initialize(0, mtd, NULL);
if (ret < 0)
{
ferr("ERROR: smart_initialize failed: %d\n", ret);
return ret;
}
}
#elif defined (CONFIG_ESP32_SPIFLASH_NXFFS)
ret = nxffs_initialize(mtd);
if (ret < 0)
{
ferr("ERROR: NXFFS init failed: %d\n", ret);
return ret;
}
#else
ret = register_mtddriver("/dev/esp32flash", mtd, 0755, NULL);
if (ret < 0)
{
ferr("ERROR: Register mtd failed: %d\n", ret);
return ret;
}
#endif
return ret;
}