mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
Merge branch 'master' of https://github.com/m-labs/misoc
This commit is contained in:
commit
0c08055014
3 changed files with 39 additions and 18 deletions
|
@ -3,5 +3,6 @@
|
|||
|
||||
void write_to_flash_page(unsigned int addr, unsigned char *c, unsigned int len);
|
||||
void erase_flash_sector(unsigned int addr);
|
||||
void write_to_flash(unsigned int addr, unsigned char *c, unsigned int len);
|
||||
|
||||
#endif /* __SPIFLASH_H */
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
#include <generated/csr.h>
|
||||
|
||||
#if (defined CSR_SPIFLASH_BASE && defined SPIFLASH_PAGE_SIZE)
|
||||
|
||||
#include <spiflash.h>
|
||||
|
||||
#ifdef CSR_SPIFLASH_BASE
|
||||
#define PAGE_PROGRAM_CMD (0x02)
|
||||
#define WRDI_CMD (0x04)
|
||||
#define RDSR_CMD (0x05)
|
||||
#define WREN_CMD (0x06)
|
||||
#define SE_CMD (0x20)
|
||||
|
||||
#define PAGE_PROGRAM_CMD (0x02)
|
||||
#define WRDI_CMD (0x04)
|
||||
#define RDSR_CMD (0x05)
|
||||
#define WREN_CMD (0x06)
|
||||
#define SE_CMD (0x20)
|
||||
|
||||
#define BITBANG_CLK (1 << 1)
|
||||
#define BITBANG_CLK (1 << 1)
|
||||
#define BITBANG_CS_N (1 << 2)
|
||||
#define BITBANG_DQ_INPUT (1 << 3)
|
||||
|
||||
#define SR_WIP (1)
|
||||
|
||||
#define PAGE_SIZE (256)
|
||||
#define PAGE_MASK (PAGE_SIZE - 1)
|
||||
#define SECTOR_SIZE (4096)
|
||||
#define SECTOR_MASK (SECTOR_SIZE - 1)
|
||||
#define SR_WIP (1)
|
||||
|
||||
static void flash_write_byte(unsigned char b);
|
||||
static void flash_write_addr(unsigned int addr);
|
||||
|
@ -76,7 +71,7 @@ static void wait_for_device_ready(void)
|
|||
|
||||
void erase_flash_sector(unsigned int addr)
|
||||
{
|
||||
unsigned int sector_addr = addr & ~(SECTOR_MASK);
|
||||
unsigned int sector_addr = addr & ~(SPIFLASH_SECTOR_SIZE - 1);
|
||||
|
||||
spiflash_bitbang_en_write(1);
|
||||
|
||||
|
@ -98,8 +93,8 @@ void write_to_flash_page(unsigned int addr, unsigned char *c, unsigned int len)
|
|||
{
|
||||
unsigned int i;
|
||||
|
||||
if(len > PAGE_SIZE)
|
||||
len = PAGE_SIZE;
|
||||
if(len > SPIFLASH_PAGE_SIZE)
|
||||
len = SPIFLASH_PAGE_SIZE;
|
||||
|
||||
spiflash_bitbang_en_write(1);
|
||||
|
||||
|
@ -120,4 +115,27 @@ void write_to_flash_page(unsigned int addr, unsigned char *c, unsigned int len)
|
|||
spiflash_bitbang_en_write(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
#define SPIFLASH_PAGE_MASK (SPIFLASH_PAGE_SIZE - 1)
|
||||
|
||||
void write_to_flash(unsigned int addr, unsigned char *c, unsigned int len)
|
||||
{
|
||||
unsigned int written = 0;
|
||||
|
||||
if(addr & SPIFLASH_PAGE_MASK) {
|
||||
written = min(SPIFLASH_PAGE_SIZE - (addr & SPIFLASH_PAGE_MASK), len);
|
||||
write_to_flash_page(addr, c, written);
|
||||
c += written;
|
||||
addr += written;
|
||||
len -= written;
|
||||
}
|
||||
|
||||
while(len > 0) {
|
||||
written = min(len, SPIFLASH_PAGE_SIZE);
|
||||
write_to_flash_page(addr, c, written);
|
||||
c += written;
|
||||
addr += written;
|
||||
len -= written;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CSR_SPIFLASH_BASE && SPIFLASH_PAGE_SIZE */
|
||||
|
|
|
@ -98,6 +98,8 @@ class BaseSoC(SDRAMSoC):
|
|||
i_CLK=0, i_GSR=0, i_GTS=0, i_KEYCLEARB=0, i_PACK=0,
|
||||
i_USRCCLKO=spiflash_pads.clk, i_USRCCLKTS=0, i_USRDONEO=1, i_USRDONETS=1)
|
||||
self.submodules.spiflash = spiflash.SpiFlash(spiflash_pads, dummy=11, div=2)
|
||||
self.add_constant("SPIFLASH_PAGE_SIZE", 256)
|
||||
self.add_constant("SPIFLASH_SECTOR_SIZE", 0x10000)
|
||||
self.flash_boot_address = 0xb00000
|
||||
self.register_rom(self.spiflash.bus)
|
||||
|
||||
|
|
Loading…
Reference in a new issue