mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Adding DIO for flash access
This commit is contained in:
+19
-63
@@ -11,11 +11,18 @@
|
|||||||
// DE62B415D3155829
|
// DE62B415D3155829
|
||||||
// JEDEC-ID: ef 40 16
|
// JEDEC-ID: ef 40 16
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void flash_init()
|
* Initializes the flash controller for programmed control
|
||||||
|
* The configuration options are not really understood, the SPI speed
|
||||||
|
* seems to be directly linked to the CPU frequency
|
||||||
|
* This configures uses fast double IO at 20.8 MHz when the CPU clock is at 20.8MHz
|
||||||
|
* and 62.5MHz when the CPU clock is configured at 125MHz
|
||||||
|
*/
|
||||||
|
void flash_init_dio()
|
||||||
{
|
{
|
||||||
// Configure fast read via divider = 4 and read-cmd being 0xbb (for mmio)
|
// Configure fast DIO via divider/DIO/SIOconfig = 4 and read-cmd being 0xbb (for mmio)
|
||||||
SFR_FLASH_CONFIG = 9;
|
SFR_FLASH_CONFIG = 9; // There may be a chip-select in here
|
||||||
SFR_FLASH_CONF_RCMD = 0xbb;
|
SFR_FLASH_CONF_RCMD = 0xbb;
|
||||||
SFR_FLASH_CONF_DIV = 4;
|
SFR_FLASH_CONF_DIV = 4;
|
||||||
|
|
||||||
@@ -36,8 +43,14 @@ void flash_init()
|
|||||||
SFR_FLASH_CMD_R = 0xbb; // By default we read with Dual speed
|
SFR_FLASH_CMD_R = 0xbb; // By default we read with Dual speed
|
||||||
SFR_FLASH_DUMMYCICLES = 4;
|
SFR_FLASH_DUMMYCICLES = 4;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initializes the flash controller for programmed control
|
||||||
|
* The configuration options are not really understood, the SPI speed
|
||||||
|
* seems to be directly linked to the CPU frequency
|
||||||
|
* This configures uses fast single IO at 20.8 MHz when the CPU clock is at 20.8MHz
|
||||||
|
* and 62.5MHz when the CPU clock is configured at 125MHz
|
||||||
|
*/
|
||||||
void flash_init(void)
|
void flash_init(void)
|
||||||
{
|
{
|
||||||
// Configure fast read via divider = 8 and read-cmd being 0xb (for mmio)
|
// Configure fast read via divider = 8 and read-cmd being 0xb (for mmio)
|
||||||
@@ -83,7 +96,6 @@ uint8_t flash_read_status(void)
|
|||||||
void flash_read_uid(void)
|
void flash_read_uid(void)
|
||||||
{
|
{
|
||||||
while (flash_read_status() & 0x1);
|
while (flash_read_status() & 0x1);
|
||||||
print_string("\r\n -uid- \r\n");
|
|
||||||
|
|
||||||
// Set slow read mode for UID
|
// Set slow read mode for UID
|
||||||
SFR_FLASH_MODEB = 0x0;
|
SFR_FLASH_MODEB = 0x0;
|
||||||
@@ -123,57 +135,7 @@ void flash_read_uid(void)
|
|||||||
void flash_read_jedecid(void)
|
void flash_read_jedecid(void)
|
||||||
{
|
{
|
||||||
while (flash_read_status() & 0x1);
|
while (flash_read_status() & 0x1);
|
||||||
print_string("\r\n -jedec- \r\n");
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Set slow read mode for UID
|
|
||||||
SFR_FLASH_MODEB = 0x0;
|
|
||||||
SFR_FLASH_CMD_R = 0x9f;
|
|
||||||
SFR_FLASH_DUMMYCICLES = 8;
|
|
||||||
|
|
||||||
// Transfer 3 bytes back
|
|
||||||
SFR_FLASH_TLEN = 0x3;
|
|
||||||
|
|
||||||
SFR_FLASH_EXEC_GO = 1;
|
|
||||||
while(SFR_FLASH_EXEC_BUSY);
|
|
||||||
|
|
||||||
print_byte(SFR_FLASH_DATA0);
|
|
||||||
print_byte(SFR_FLASH_DATA8);
|
|
||||||
print_byte(SFR_FLASH_DATA16);
|
|
||||||
print_byte(SFR_FLASH_DATA24);
|
|
||||||
|
|
||||||
// Reset slow read mode
|
|
||||||
SFR_FLASH_MODEB = 0x0;
|
|
||||||
SFR_FLASH_CMD_R = 0xb;
|
|
||||||
SFR_FLASH_DUMMYCICLES = 8;
|
|
||||||
|
|
||||||
while (flash_read_status() & 0x1);
|
|
||||||
print_string("\r\n -jedec- b- \r\n");
|
|
||||||
|
|
||||||
// Set slow read mode for UID
|
|
||||||
SFR_FLASH_MODEB = 0x0;
|
|
||||||
SFR_FLASH_CMD_R = 0x9f;
|
|
||||||
SFR_FLASH_DUMMYCICLES = 8;
|
|
||||||
|
|
||||||
// Transfer 3 bytes back
|
|
||||||
SFR_FLASH_TLEN = 0x13;
|
|
||||||
|
|
||||||
SFR_FLASH_EXEC_GO = 1;
|
|
||||||
while(SFR_FLASH_EXEC_BUSY);
|
|
||||||
|
|
||||||
print_byte(SFR_FLASH_DATA0);
|
|
||||||
print_byte(SFR_FLASH_DATA8);
|
|
||||||
print_byte(SFR_FLASH_DATA16);
|
|
||||||
print_byte(SFR_FLASH_DATA24);
|
|
||||||
|
|
||||||
// Reset slow read mode
|
|
||||||
SFR_FLASH_MODEB = 0x0;
|
|
||||||
SFR_FLASH_CMD_R = 0xb;
|
|
||||||
SFR_FLASH_DUMMYCICLES = 8;
|
|
||||||
|
|
||||||
while (flash_read_status() & 0x1);
|
|
||||||
print_string("\r\n -jedec- c \r\n");
|
|
||||||
*/
|
|
||||||
// Set read mode for JEDEC ID
|
// Set read mode for JEDEC ID
|
||||||
SFR_FLASH_MODEB = 0x0;
|
SFR_FLASH_MODEB = 0x0;
|
||||||
SFR_FLASH_CMD_R = 0x9f;
|
SFR_FLASH_CMD_R = 0x9f;
|
||||||
@@ -219,17 +181,14 @@ void flash_write_enable(void)
|
|||||||
} while (!(status & 0x2));
|
} while (!(status & 0x2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void flash_dump(uint32_t addr, uint8_t len)
|
void flash_dump_dio(uint32_t addr, uint8_t len)
|
||||||
{
|
{
|
||||||
short status;
|
short status;
|
||||||
print_string("\r\n -a- \r\n");
|
|
||||||
do {
|
do {
|
||||||
status = flash_read_status();
|
status = flash_read_status();
|
||||||
print_short(status);
|
print_short(status);
|
||||||
} while (status & 0x1);
|
} while (status & 0x1);
|
||||||
// while (flash_read_status() & 0x1);
|
|
||||||
print_string("\r\n -b- \r\n");
|
|
||||||
|
|
||||||
// Set fast read mode
|
// Set fast read mode
|
||||||
SFR_FLASH_MODEB = 0x18;
|
SFR_FLASH_MODEB = 0x18;
|
||||||
@@ -261,13 +220,11 @@ void flash_dump(uint32_t addr, uint8_t len)
|
|||||||
len -= 4;
|
len -= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void flash_read_security(uint32_t addr, uint8_t len)
|
void flash_read_security(uint32_t addr, uint8_t len)
|
||||||
{
|
{
|
||||||
while (flash_read_status() & 0x1);
|
while (flash_read_status() & 0x1);
|
||||||
print_string("\r\n -b- \r\n");
|
|
||||||
|
|
||||||
// Set slow read mode
|
// Set slow read mode
|
||||||
SFR_FLASH_MODEB = 0x0;
|
SFR_FLASH_MODEB = 0x0;
|
||||||
@@ -304,7 +261,6 @@ void flash_read_security(uint32_t addr, uint8_t len)
|
|||||||
void flash_dump(uint32_t addr, uint8_t len)
|
void flash_dump(uint32_t addr, uint8_t len)
|
||||||
{
|
{
|
||||||
while (flash_read_status() & 0x1);
|
while (flash_read_status() & 0x1);
|
||||||
print_string("\r\n -b- \r\n");
|
|
||||||
|
|
||||||
// Set slow read mode
|
// Set slow read mode
|
||||||
SFR_FLASH_MODEB = 0x0;
|
SFR_FLASH_MODEB = 0x0;
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
uint8_t flash_read_status(void);
|
uint8_t flash_read_status(void);
|
||||||
void flash_init(void);
|
void flash_init(void);
|
||||||
|
void flash_init_dio(void);
|
||||||
void flash_read_uid(void);
|
void flash_read_uid(void);
|
||||||
void flash_write_enable(void);
|
void flash_write_enable(void);
|
||||||
void flash_dump(uint32_t addr, uint8_t len);
|
void flash_dump(uint32_t addr, uint8_t len);
|
||||||
|
void flash_dump_dio(uint32_t addr, uint8_t len);
|
||||||
void flash_read_jedecid(void);
|
void flash_read_jedecid(void);
|
||||||
void flash_read_security(uint32_t addr, uint8_t len);
|
void flash_read_security(uint32_t addr, uint8_t len);
|
||||||
|
|
||||||
|
|||||||
@@ -798,6 +798,13 @@ void bootloader(void)
|
|||||||
print_string("\r\nUNIQUE ID\n\n");
|
print_string("\r\nUNIQUE ID\n\n");
|
||||||
flash_read_uid();
|
flash_read_uid();
|
||||||
}
|
}
|
||||||
|
// Switch to flash 62.5 MHz mode
|
||||||
|
if (cmd_compare(0, "flash") && cmd_words_b[1] > 0 && sbuf[cmd_words_b[1]] == 's') {
|
||||||
|
print_string("\r\nFLASH FAST MODE\n\n");
|
||||||
|
flash_init_fast();
|
||||||
|
print_string("\r\nNow dumping flash\n\n");
|
||||||
|
flash_dump_fast(0, 255);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print_string("\r\n> ");
|
print_string("\r\n> ");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user