arch/risc-v/bl602 : add spiflash(hardware sf controller)
This commit is contained in:
parent
1604fe0b4b
commit
32708ab849
@ -39,4 +39,27 @@ config BL602_TIMER1
|
||||
config BL602_PWM0
|
||||
bool "PWM0"
|
||||
|
||||
config BL602_SPIFLASH
|
||||
bool "SPI Flash"
|
||||
default n
|
||||
select MTD
|
||||
select MTD_PARTITION
|
||||
|
||||
menu "SPI Flash configuration"
|
||||
depends on BL602_SPIFLASH
|
||||
|
||||
config BL602_MTD_OFFSET
|
||||
hex "MTD base address in SPI Flash"
|
||||
default 0x001c5000
|
||||
help
|
||||
MTD base address in SPI Flash.
|
||||
|
||||
config BL602_MTD_SIZE
|
||||
hex "MTD size in SPI Flash"
|
||||
default 0x30000
|
||||
help
|
||||
MTD size in SPI Flash.
|
||||
|
||||
endmenu # BL602_SPIFLASH
|
||||
|
||||
endmenu
|
||||
|
@ -60,6 +60,10 @@ endif
|
||||
ifeq ($(CONFIG_PWM),y)
|
||||
CHIP_CSRCS += bl602_pwm_lowerhalf.c
|
||||
endif
|
||||
ifeq ($(CONFIG_BL602_SPIFLASH),y)
|
||||
CHIP_CSRCS += bl602_flash.c bl602_spiflash.c
|
||||
endif
|
||||
|
||||
CHIP_CSRCS += bl602_glb.c bl602_gpio.c bl602_hbn.c bl602_systemreset.c
|
||||
|
||||
# INCLUDES += ${shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)hardware}
|
||||
|
112
arch/risc-v/src/bl602/bl602_flash.c
Normal file
112
arch/risc-v/src/bl602/bl602_flash.c
Normal file
@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/bl602/bl602_flash.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 <stdint.h>
|
||||
#include <syslog.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_BL602_SPIFLASH
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
struct bl602_romflash_cfg_desc
|
||||
{
|
||||
uint32_t magic;
|
||||
uint8_t cfg[84];
|
||||
};
|
||||
|
||||
#define ROMAPI_BASE (0x21010800)
|
||||
#define ROMAPI_SFLASH_EREASE_NEEDLOCK (ROMAPI_BASE + 163 * 4)
|
||||
#define ROMAPI_SFLASH_WRITE_NEEDLOCK (ROMAPI_BASE + 164 * 4)
|
||||
#define ROMAPI_SFLASH_READ_NEEDLOCK (ROMAPI_BASE + 165 * 4)
|
||||
#define ROMAPI_SFLASH_GET_JEDECID_NOLOCK (ROMAPI_BASE + 166 * 4)
|
||||
#define ROMAPI_SFLASH_READ_WITHLOCK (ROMAPI_BASE + 170 * 4)
|
||||
#define ROMAPI_SFLASH_WRITE_WITHLOCK (ROMAPI_BASE + 171 * 4)
|
||||
#define ROMAPI_SFLASH_EREASE_WITHLOCK (ROMAPI_BASE + 172 * 4)
|
||||
|
||||
static struct bl602_romflash_cfg_desc g_bl602_romflash_cfg;
|
||||
|
||||
typedef void (*bl602_romdrv_erase_fn) (uint8_t *cfg,
|
||||
uint32_t addr, int len);
|
||||
typedef void (*bl602_romdrv_write_fn) (uint8_t *cfg,
|
||||
uint32_t addr, const uint8_t *dst, int len);
|
||||
typedef void (*bl602_romdrv_read_fn) (uint8_t *cfg,
|
||||
uint32_t addr, uint8_t *dst, int len);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int bl602_flash_erase(uint32_t addr, int len)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"bl602_flash_erase addr = %08lx, len = %d\r\n", addr, len);
|
||||
|
||||
flags = up_irq_save();
|
||||
((bl602_romdrv_erase_fn)(*((uint32_t *)(ROMAPI_SFLASH_EREASE_NEEDLOCK))))
|
||||
(g_bl602_romflash_cfg.cfg, addr, addr + len);
|
||||
up_irq_restore(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bl602_flash_write(uint32_t addr, const uint8_t *src, int len)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"bl602_flash_write addr = %08lx, len = %d\r\n", addr, len);
|
||||
|
||||
flags = up_irq_save();
|
||||
((bl602_romdrv_write_fn)(*((uint32_t *)(ROMAPI_SFLASH_WRITE_NEEDLOCK))))
|
||||
(g_bl602_romflash_cfg.cfg, addr, src, len);
|
||||
up_irq_restore(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bl602_flash_read(uint32_t addr, uint8_t *dst, int len)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"bl602_flash_read addr = %08lx, len = %d\r\n", addr, len);
|
||||
|
||||
flags = up_irq_save();
|
||||
((bl602_romdrv_read_fn)(*((uint32_t *)(ROMAPI_SFLASH_READ_NEEDLOCK))))
|
||||
(g_bl602_romflash_cfg.cfg, addr, dst, len);
|
||||
up_irq_restore(flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BL602_SPIFLASH */
|
||||
|
80
arch/risc-v/src/bl602/bl602_flash.h
Normal file
80
arch/risc-v/src/bl602/bl602_flash.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/bl602/hardware/bl602_flash.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_BL602_BL602_FLASH_H
|
||||
#define __ARCH_RISCV_SRC_BL602_BL602_FLASH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_flash_erase
|
||||
****************************************************************************/
|
||||
|
||||
int bl602_flash_erase(uint32_t addr, int len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_flash_write
|
||||
****************************************************************************/
|
||||
|
||||
int bl602_flash_write(uint32_t addr, const uint8_t *src, int len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_flash_read
|
||||
****************************************************************************/
|
||||
|
||||
int bl602_flash_read(uint32_t addr, uint8_t *dst, int len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_flash_getjedecid
|
||||
****************************************************************************/
|
||||
|
||||
int bl602_flash_getjedecid(uint8_t *data);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_BL602_BL602_FLASH_H */
|
407
arch/risc-v/src/bl602/bl602_spiflash.c
Normal file
407
arch/risc-v/src/bl602/bl602_spiflash.c
Normal file
@ -0,0 +1,407 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/bl602/bl602_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 <stdint.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#ifdef CONFIG_BL602_SPIFLASH
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/init.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/timers/timer.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include <bl602_flash.h>
|
||||
#include <bl602_spiflash.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SPIFLASH_BLOCKSIZE (0x1000)
|
||||
#define MTD2PRIV(_dev) ((FAR struct bl602_spiflash_s *)_dev)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* SPI Flash device hardware configuration */
|
||||
|
||||
struct bl602_spiflash_config_s
|
||||
{
|
||||
/* SPI register base address */
|
||||
|
||||
uint32_t flash_offset;
|
||||
uint32_t flash_size;
|
||||
uint32_t flash_offset_xip;
|
||||
};
|
||||
|
||||
/* SPI Flash device private data */
|
||||
|
||||
struct bl602_spiflash_s
|
||||
{
|
||||
struct mtd_dev_s mtd;
|
||||
struct bl602_spiflash_config_s *config;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* ROM function prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int bl602_erase(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks);
|
||||
static ssize_t bl602_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR uint8_t *buffer);
|
||||
static ssize_t bl602_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR const uint8_t *buffer);
|
||||
static ssize_t bl602_read(FAR struct mtd_dev_s *dev, off_t offset,
|
||||
size_t nbytes, FAR uint8_t *buffer);
|
||||
static int bl602_ioctl(FAR struct mtd_dev_s *dev, int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct bl602_spiflash_config_s g_bl602_spiflash_config =
|
||||
{
|
||||
.flash_offset = 0,
|
||||
.flash_size = 0,
|
||||
.flash_offset_xip = 0,
|
||||
};
|
||||
|
||||
static struct bl602_spiflash_s g_bl602_spiflash =
|
||||
{
|
||||
.mtd =
|
||||
{
|
||||
.erase = bl602_erase,
|
||||
.bread = bl602_bread,
|
||||
.bwrite = bl602_bwrite,
|
||||
.read = bl602_read,
|
||||
.ioctl = bl602_ioctl,
|
||||
.name = "bl602_media"
|
||||
},
|
||||
.config = &g_bl602_spiflash_config,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_erase
|
||||
*
|
||||
* Description:
|
||||
* Erase SPI Flash designated sectors.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - bl602 MTD device data
|
||||
* startblock - start block number, it is not equal to SPI Flash's block
|
||||
* nblocks - blocks number
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or a negative value if fail.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int bl602_erase(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks)
|
||||
{
|
||||
int ret = 0;
|
||||
FAR struct bl602_spiflash_s *priv = MTD2PRIV(dev);
|
||||
uint32_t addr = priv->config->flash_offset \
|
||||
+ startblock * SPIFLASH_BLOCKSIZE;
|
||||
uint32_t size = nblocks * SPIFLASH_BLOCKSIZE;
|
||||
|
||||
syslog(LOG_INFO, "bl602_erase dev=%p, addr=0x%lx, size=0x%lx\r\n",
|
||||
dev, addr, size);
|
||||
|
||||
ret = bl602_flash_erase(addr, size);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = nblocks;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_read
|
||||
*
|
||||
* Description:
|
||||
* Read data from SPI Flash at designated address.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - bl602 MTD device data
|
||||
* offset - target address offset
|
||||
* nbytes - data number
|
||||
* buffer - data buffer pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* Read data bytes if success or a negative value if fail.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bl602_read(FAR struct mtd_dev_s *dev, off_t offset,
|
||||
size_t nbytes, FAR uint8_t *buffer)
|
||||
{
|
||||
int ret = 0;
|
||||
FAR struct bl602_spiflash_s *priv = MTD2PRIV(dev);
|
||||
uint32_t addr = priv->config->flash_offset + offset;
|
||||
uint32_t size = nbytes;
|
||||
|
||||
syslog(LOG_INFO, "bl602_read dev=%p, addr=0x%lx, size=0x%lx\r\n",
|
||||
dev, addr, size);
|
||||
|
||||
if (0 == bl602_flash_read(addr, buffer, size))
|
||||
{
|
||||
return ret = size;
|
||||
}
|
||||
|
||||
return (ssize_t)ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_bread
|
||||
*
|
||||
* Description:
|
||||
* Read data from designated blocks.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - bl602 MTD device data
|
||||
* startblock - start block number, it is not equal to SPI Flash's block
|
||||
* nblocks - blocks number
|
||||
* buffer - data buffer pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* Read block number if success or a negative value if fail.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bl602_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR uint8_t *buffer)
|
||||
{
|
||||
int ret = 0;
|
||||
FAR struct bl602_spiflash_s *priv = MTD2PRIV(dev);
|
||||
uint32_t addr = priv->config->flash_offset \
|
||||
+ startblock * SPIFLASH_BLOCKSIZE;
|
||||
uint32_t size = nblocks * SPIFLASH_BLOCKSIZE;
|
||||
|
||||
syslog(LOG_INFO, "bl602_bread dev=%p, addr=0x%lx, size=0x%lx\r\n",
|
||||
dev, addr, size);
|
||||
|
||||
if (0 == bl602_flash_read(addr, buffer, size))
|
||||
{
|
||||
ret = nblocks;
|
||||
}
|
||||
|
||||
return (ssize_t)ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_bwrite
|
||||
*
|
||||
* Description:
|
||||
* Write data to designated blocks.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - bl602 MTD device data
|
||||
* startblock - start MTD block number,
|
||||
* it is not equal to SPI Flash's block
|
||||
* nblocks - blocks number
|
||||
* buffer - data buffer pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* Writen block number if success or a negative value if fail.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t bl602_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR const uint8_t *buffer)
|
||||
{
|
||||
int ret = 0;
|
||||
FAR struct bl602_spiflash_s *priv = MTD2PRIV(dev);
|
||||
uint32_t addr = priv->config->flash_offset \
|
||||
+ startblock * SPIFLASH_BLOCKSIZE;
|
||||
uint32_t size = nblocks * SPIFLASH_BLOCKSIZE;
|
||||
|
||||
syslog(LOG_INFO, "bl602_bwrite dev=%p, addr=0x%lx, size=0x%lx\r\n",
|
||||
dev, addr, size);
|
||||
|
||||
if (0 == bl602_flash_write(addr, buffer, size))
|
||||
{
|
||||
ret = nblocks;
|
||||
}
|
||||
|
||||
return (ssize_t)ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_ioctl
|
||||
*
|
||||
* Description:
|
||||
* Set/Get option to/from bl602 SPI Flash MTD device data.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - bl602 MTD device data
|
||||
* cmd - operation command
|
||||
* arg - operation argument
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or a negative value if fail.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int bl602_ioctl(FAR struct mtd_dev_s *dev, int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
FAR struct bl602_spiflash_s *priv = MTD2PRIV(dev);
|
||||
FAR struct mtd_geometry_s *geo;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MTDIOC_GEOMETRY:
|
||||
{
|
||||
syslog(LOG_INFO, "cmd(0x%x) MTDIOC_GEOMETRY.\r\n", cmd);
|
||||
geo = (FAR struct mtd_geometry_s *)arg;
|
||||
if (geo)
|
||||
{
|
||||
geo->blocksize = SPIFLASH_BLOCKSIZE;
|
||||
geo->erasesize = SPIFLASH_BLOCKSIZE;
|
||||
geo->neraseblocks = (priv->config->flash_size) / \
|
||||
SPIFLASH_BLOCKSIZE;
|
||||
ret = OK;
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"blocksize: %ld erasesize: %ld neraseblocks: %ld\n",
|
||||
geo->blocksize, geo->erasesize, geo->neraseblocks);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MTDIOC_BULKERASE:
|
||||
{
|
||||
/* Erase the entire partition */
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"cmd(0x%x) MTDIOC_BULKERASE not support.\r\n", cmd);
|
||||
}
|
||||
break;
|
||||
case MTDIOC_XIPBASE:
|
||||
{
|
||||
/* Get the XIP base of the entire FLASH */
|
||||
|
||||
syslog(LOG_INFO,
|
||||
"cmd(0x%x) MTDIOC_XIPBASE not support.\r\n", cmd);
|
||||
}
|
||||
break;
|
||||
case BIOC_FLUSH:
|
||||
{
|
||||
syslog(LOG_INFO, "cmd(0x%x) BIOC_FLUSH.\r\n", cmd);
|
||||
ret = OK;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
syslog(LOG_INFO, "cmd(0x%x) not support.\r\n", cmd);
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_spiflash_alloc_mtdpart
|
||||
*
|
||||
* Description:
|
||||
* Alloc bl602 SPI Flash MTD
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* bl602 SPI Flash MTD data pointer if success or NULL if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *bl602_spiflash_alloc_mtdpart(void)
|
||||
{
|
||||
struct bl602_spiflash_s *priv = &g_bl602_spiflash;
|
||||
FAR struct mtd_dev_s *mtd_part = NULL;
|
||||
|
||||
priv->config->flash_offset = CONFIG_BL602_MTD_OFFSET;
|
||||
priv->config->flash_size = CONFIG_BL602_MTD_SIZE;
|
||||
|
||||
mtd_part = mtd_partition(&priv->mtd, 0,
|
||||
CONFIG_BL602_MTD_SIZE / SPIFLASH_BLOCKSIZE);
|
||||
if (!mtd_part)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: create MTD partition");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mtd_part;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_spiflash_get_mtd
|
||||
*
|
||||
* Description:
|
||||
* Get bl602 SPI Flash raw MTD.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* bl602 SPI Flash raw MTD data pointer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *bl602_spiflash_get_mtd(void)
|
||||
{
|
||||
struct bl602_spiflash_s *priv = &g_bl602_spiflash;
|
||||
|
||||
return &priv->mtd;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BL602_SPIFLASH */
|
87
arch/risc-v/src/bl602/bl602_spiflash.h
Normal file
87
arch/risc-v/src/bl602/bl602_spiflash.h
Normal file
@ -0,0 +1,87 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/bl602/bl602_spiflash.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_BL602_BL602_SPIFLASH_H
|
||||
#define __ARCH_RISCV_SRC_BL602_BL602_SPIFLASH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_spiflash_alloc_mtdpart
|
||||
*
|
||||
* Description:
|
||||
* Alloc BL602 SPI Flash MTD.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* BL602 SPI Flash MTD data pointer if success or NULL if fail.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *bl602_spiflash_alloc_mtdpart(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: bl602_spiflash_get_mtd
|
||||
*
|
||||
* Description:
|
||||
* Get BL602 SPI Flash raw MTD.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* BL602 SPI Flash raw MTD data pointer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *bl602_spiflash_get_mtd(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#undef EXTERN
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_BL602_BL602_SPIFLASH_H */
|
77
boards/risc-v/bl602/bl602evb/configs/spiflash/defconfig
Normal file
77
boards/risc-v/bl602/bl602evb/configs/spiflash/defconfig
Normal file
@ -0,0 +1,77 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NSH_DISABLEBG is not set
|
||||
# CONFIG_NSH_DISABLE_LOSMART is not set
|
||||
# CONFIG_NSH_DISABLE_UNAME is not set
|
||||
CONFIG_ARCH="risc-v"
|
||||
CONFIG_ARCH_BOARD="bl602evb"
|
||||
CONFIG_ARCH_BOARD_BL602EVB=y
|
||||
CONFIG_ARCH_CHIP="bl602"
|
||||
CONFIG_ARCH_CHIP_BL602=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=8192
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BINFMT_DISABLE=y
|
||||
CONFIG_BL602_HAVE_UART0=y
|
||||
CONFIG_BL602_SPIFLASH=y
|
||||
CONFIG_BL602_TIMER0=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=10000
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_FEATURES=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEFAULT_SMALL=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_DISABLE_MQUEUE=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_EXAMPLES_HELLO_STACKSIZE=8192
|
||||
CONFIG_EXAMPLES_TIMER=y
|
||||
CONFIG_FS_LITTLEFS=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=8192
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_PERROR_STDOUT=y
|
||||
CONFIG_LIBC_STRERROR=y
|
||||
CONFIG_MAX_TASKS=8
|
||||
CONFIG_NFILE_DESCRIPTORS=6
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_DISABLE_CD=y
|
||||
CONFIG_NSH_DISABLE_CP=y
|
||||
CONFIG_NSH_DISABLE_IFUPDOWN=y
|
||||
CONFIG_NSH_DISABLE_MKDIR=y
|
||||
CONFIG_NSH_DISABLE_RM=y
|
||||
CONFIG_NSH_DISABLE_RMDIR=y
|
||||
CONFIG_NSH_DISABLE_UMOUNT=y
|
||||
CONFIG_NSH_FILEIOSIZE=64
|
||||
CONFIG_NSH_STRERROR=y
|
||||
CONFIG_PREALLOC_TIMERS=0
|
||||
CONFIG_PTHREAD_STACK_DEFAULT=8192
|
||||
CONFIG_RAM_SIZE=134217728
|
||||
CONFIG_RAM_START=0xc0800000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_RV32IM_CUSTOM_IRQ_SUPPORT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_STACK_COLORATION=y
|
||||
CONFIG_START_DAY=20
|
||||
CONFIG_START_MONTH=3
|
||||
CONFIG_START_YEAR=2020
|
||||
CONFIG_STDIO_DISABLE_BUFFERING=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=12
|
||||
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=8192
|
||||
CONFIG_TESTING_GETPRIME=y
|
||||
CONFIG_TIMER=y
|
||||
CONFIG_TIMER_ARCH=y
|
||||
CONFIG_UART0_BAUD=2000000
|
||||
CONFIG_UART0_RXBUFSIZE=128
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_UART0_TXBUFSIZE=128
|
||||
CONFIG_USERMAIN_STACKSIZE=8192
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -29,6 +29,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
@ -38,6 +39,10 @@
|
||||
#include <bl602_pwm_lowerhalf.h>
|
||||
#include <bl602_wdt_lowerhalf.h>
|
||||
|
||||
#if defined(CONFIG_BL602_SPIFLASH)
|
||||
#include <bl602_spiflash.h>
|
||||
#endif
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -53,6 +58,10 @@ int bl602_bringup(void)
|
||||
#if defined(CONFIG_TIMER) && defined(CONFIG_ONESHOT) && \
|
||||
defined(CONFIG_BL602_TIMER1)
|
||||
struct oneshot_lowerhalf_s *os = NULL;
|
||||
#endif
|
||||
#if defined(CONFIG_BL602_SPIFLASH)
|
||||
FAR struct mtd_dev_s *mtd_part = NULL;
|
||||
const char *path = "/dev/mtdflash";
|
||||
#endif
|
||||
int ret = OK;
|
||||
|
||||
@ -62,8 +71,8 @@ int bl602_bringup(void)
|
||||
ret = mount(NULL, "/proc", "procfs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(
|
||||
LOG_ERR, "ERROR: Failed to mount procfs at %s: %d\n", "/proc", ret);
|
||||
syslog(LOG_DEBUG,
|
||||
"ERROR: Failed to mount procfs at %s: %d\n", "/proc", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@ -73,7 +82,8 @@ int bl602_bringup(void)
|
||||
ret = bl602_timer_initialize("/dev/timer0", 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize /dev/timer0 Driver: %d\n", ret);
|
||||
syslog(LOG_DEBUG,
|
||||
"Failed to initialize /dev/timer0 Driver: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@ -82,14 +92,15 @@ int bl602_bringup(void)
|
||||
ret = bl602_timer_initialize("/dev/timer1", 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize /dev/timer1 Driver: %d\n", ret);
|
||||
syslog(LOG_DEBUG,
|
||||
"Failed to initialize /dev/timer1 Driver: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#elif defined(CONFIG_BL602_TIMER1) && defined(CONFIG_ONESHOT)
|
||||
os = oneshot_initialize(1, 1);
|
||||
if (os == NULL)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: oneshot_initialize failed\n");
|
||||
syslog(LOG_DEBUG, "ERROR: oneshot_initialize failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -102,9 +113,8 @@ int bl602_bringup(void)
|
||||
ret = oneshot_register("/dev/oneshot", os);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register oneshot at /dev/oneshot: %d\n",
|
||||
ret);
|
||||
syslog(LOG_DEBUG,
|
||||
"ERROR: Failed to register oneshot at /dev/oneshot: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -114,19 +124,19 @@ int bl602_bringup(void)
|
||||
#ifdef CONFIG_PWM
|
||||
struct pwm_lowerhalf_s *pwm;
|
||||
|
||||
/* Initialize PWM and register the PWM driver. */
|
||||
/* Initialize PWM and register the PWM driver */
|
||||
|
||||
pwm = bl602_pwminitialize(0);
|
||||
if (pwm == NULL)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: bl602_pwminitialize failed\n");
|
||||
syslog(LOG_DEBUG, "ERROR: bl602_pwminitialize failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = pwm_register("/dev/pwm0", pwm);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
|
||||
syslog(LOG_DEBUG, "ERROR: pwm_register failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -135,9 +145,42 @@ int bl602_bringup(void)
|
||||
ret = bl602_wdt_initialize(CONFIG_WATCHDOG_DEVPATH);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: bl602_wdt_initialize failed: %d\n", ret);
|
||||
syslog(LOG_DEBUG, "ERROR: bl602_wdt_initialize failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BL602_SPIFLASH
|
||||
mtd_part = bl602_spiflash_alloc_mtdpart();
|
||||
|
||||
if (!mtd_part)
|
||||
{
|
||||
syslog(LOG_DEBUG,
|
||||
"ERROR: Failed to alloc MTD partition of SPI Flash\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Register the MTD driver so that it can be accessed from the VFS */
|
||||
|
||||
ret = register_mtddriver(path, mtd_part, 0777, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_DEBUG, "ERROR: Failed to regitser MTD: %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Mount the SPIFFS file system */
|
||||
|
||||
#ifdef CONFIG_FS_LITTLEFS
|
||||
ret = mount(path, "/mnt/lfs", "littlefs", 0, "autoformat");
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_DEBUG,
|
||||
"ERROR: Failed to mount littlefs at /mnt/llfs: %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FS_LITTLEFS */
|
||||
#endif /* CONFIG_BL602_SPIFLASH */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user