Rename w25x20cl to xflash
This commit is contained in:
parent
cdcc06f376
commit
9454f9d8ec
|
|
@ -103,10 +103,10 @@
|
||||||
#include "tmc2130.h"
|
#include "tmc2130.h"
|
||||||
#endif //TMC2130
|
#endif //TMC2130
|
||||||
|
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
#include "w25x20cl.h"
|
#include "xflash.h"
|
||||||
#include "optiboot_w25x20cl.h"
|
#include "optiboot_xflash.h"
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
|
|
||||||
#ifdef BLINKM
|
#ifdef BLINKM
|
||||||
#include "BlinkM.h"
|
#include "BlinkM.h"
|
||||||
|
|
@ -910,7 +910,7 @@ uint8_t check_printer_version()
|
||||||
|
|
||||||
#if (LANG_MODE != 0) //secondary language support
|
#if (LANG_MODE != 0) //secondary language support
|
||||||
|
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
|
|
||||||
|
|
||||||
// language update from external flash
|
// language update from external flash
|
||||||
|
|
@ -936,7 +936,7 @@ void update_sec_lang_from_external_flash()
|
||||||
cli();
|
cli();
|
||||||
uint16_t size = header.size - state * LANGBOOT_BLOCKSIZE;
|
uint16_t size = header.size - state * LANGBOOT_BLOCKSIZE;
|
||||||
if (size > LANGBOOT_BLOCKSIZE) size = LANGBOOT_BLOCKSIZE;
|
if (size > LANGBOOT_BLOCKSIZE) size = LANGBOOT_BLOCKSIZE;
|
||||||
w25x20cl_rd_data(src_addr + state * LANGBOOT_BLOCKSIZE, (uint8_t*)LANGBOOT_RAMBUFFER, size);
|
xflash_rd_data(src_addr + state * LANGBOOT_BLOCKSIZE, (uint8_t*)LANGBOOT_RAMBUFFER, size);
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
{
|
{
|
||||||
//TODO - check header integrity
|
//TODO - check header integrity
|
||||||
|
|
@ -954,7 +954,7 @@ void update_sec_lang_from_external_flash()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_W25X20CL
|
#ifdef DEBUG_XFLASH
|
||||||
|
|
||||||
uint8_t lang_xflash_enum_codes(uint16_t* codes)
|
uint8_t lang_xflash_enum_codes(uint16_t* codes)
|
||||||
{
|
{
|
||||||
|
|
@ -964,7 +964,7 @@ uint8_t lang_xflash_enum_codes(uint16_t* codes)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
printf_P(_n("LANGTABLE%d:"), count);
|
printf_P(_n("LANGTABLE%d:"), count);
|
||||||
w25x20cl_rd_data(addr, (uint8_t*)&header, sizeof(lang_table_header_t));
|
xflash_rd_data(addr, (uint8_t*)&header, sizeof(lang_table_header_t));
|
||||||
if (header.magic != LANG_MAGIC)
|
if (header.magic != LANG_MAGIC)
|
||||||
{
|
{
|
||||||
puts_P(_n("NG!"));
|
puts_P(_n("NG!"));
|
||||||
|
|
@ -992,17 +992,17 @@ void list_sec_lang_from_external_flash()
|
||||||
printf_P(_n("XFlash lang count = %hhd\n"), count);
|
printf_P(_n("XFlash lang count = %hhd\n"), count);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //DEBUG_W25X20CL
|
#endif //DEBUG_XFLASH
|
||||||
|
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
|
|
||||||
#endif //(LANG_MODE != 0)
|
#endif //(LANG_MODE != 0)
|
||||||
|
|
||||||
|
|
||||||
static void w25x20cl_err_msg()
|
static void xflash_err_msg()
|
||||||
{
|
{
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_puts_P(_n("External SPI flash\nW25X20CL is not res-\nponding. Language\nswitch unavailable."));
|
lcd_puts_P(_n("External SPI flash\nXFLASH is not res-\nponding. Language\nswitch unavailable."));
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Setup" function is called by the Arduino framework on startup.
|
// "Setup" function is called by the Arduino framework on startup.
|
||||||
|
|
@ -1028,23 +1028,23 @@ void setup()
|
||||||
fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream
|
fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream
|
||||||
stdout = uartout;
|
stdout = uartout;
|
||||||
|
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
bool w25x20cl_success = w25x20cl_init();
|
bool xflash_success = xflash_init();
|
||||||
uint8_t optiboot_status = 1;
|
uint8_t optiboot_status = 1;
|
||||||
if (w25x20cl_success)
|
if (xflash_success)
|
||||||
{
|
{
|
||||||
optiboot_status = optiboot_w25x20cl_enter();
|
optiboot_status = optiboot_xflash_enter();
|
||||||
#if (LANG_MODE != 0) //secondary language support
|
#if (LANG_MODE != 0) //secondary language support
|
||||||
update_sec_lang_from_external_flash();
|
update_sec_lang_from_external_flash();
|
||||||
#endif //(LANG_MODE != 0)
|
#endif //(LANG_MODE != 0)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w25x20cl_err_msg();
|
xflash_err_msg();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const bool w25x20cl_success = true;
|
const bool xflash_success = true;
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
|
|
||||||
|
|
||||||
setup_killpin();
|
setup_killpin();
|
||||||
|
|
@ -1091,7 +1091,7 @@ void setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef W25X20CL
|
#ifndef XFLASH
|
||||||
SERIAL_PROTOCOLLNPGM("start");
|
SERIAL_PROTOCOLLNPGM("start");
|
||||||
#else
|
#else
|
||||||
if ((optiboot_status != 0) || (selectedSerialPort != 0))
|
if ((optiboot_status != 0) || (selectedSerialPort != 0))
|
||||||
|
|
@ -1172,7 +1172,7 @@ void setup()
|
||||||
#undef LT_PRINT_TEST
|
#undef LT_PRINT_TEST
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
w25x20cl_rd_data(0x25ba, (uint8_t*)&block_buffer, 1024);
|
xflash_rd_data(0x25ba, (uint8_t*)&block_buffer, 1024);
|
||||||
for (uint16_t i = 0; i < 1024; i++)
|
for (uint16_t i = 0; i < 1024; i++)
|
||||||
{
|
{
|
||||||
if ((i % 16) == 0) printf_P(_n("%04x:"), 0x25ba+i);
|
if ((i % 16) == 0) printf_P(_n("%04x:"), 0x25ba+i);
|
||||||
|
|
@ -1269,11 +1269,11 @@ void setup()
|
||||||
|
|
||||||
tp_init(); // Initialize temperature loop
|
tp_init(); // Initialize temperature loop
|
||||||
|
|
||||||
if (w25x20cl_success) lcd_splash(); // we need to do this again, because tp_init() kills lcd
|
if (xflash_success) lcd_splash(); // we need to do this again, because tp_init() kills lcd
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w25x20cl_err_msg();
|
xflash_err_msg();
|
||||||
puts_P(_n("W25X20CL not responding."));
|
puts_P(_n("XFLASH not responding."));
|
||||||
}
|
}
|
||||||
#ifdef EXTRUDER_ALTFAN_DETECT
|
#ifdef EXTRUDER_ALTFAN_DETECT
|
||||||
SERIAL_ECHORPGM(_n("Extruder fan type: "));
|
SERIAL_ECHORPGM(_n("Extruder fan type: "));
|
||||||
|
|
@ -1458,16 +1458,16 @@ void setup()
|
||||||
|
|
||||||
#if (LANG_MODE != 0) //secondary language support
|
#if (LANG_MODE != 0) //secondary language support
|
||||||
|
|
||||||
#ifdef DEBUG_W25X20CL
|
#ifdef DEBUG_XFLASH
|
||||||
W25X20CL_SPI_ENTER();
|
XFLASH_SPI_ENTER();
|
||||||
uint8_t uid[8]; // 64bit unique id
|
uint8_t uid[8]; // 64bit unique id
|
||||||
w25x20cl_rd_uid(uid);
|
xflash_rd_uid(uid);
|
||||||
puts_P(_n("W25X20CL UID="));
|
puts_P(_n("XFLASH UID="));
|
||||||
for (uint8_t i = 0; i < 8; i ++)
|
for (uint8_t i = 0; i < 8; i ++)
|
||||||
printf_P(PSTR("%02hhx"), uid[i]);
|
printf_P(PSTR("%02hhx"), uid[i]);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
list_sec_lang_from_external_flash();
|
list_sec_lang_from_external_flash();
|
||||||
#endif //DEBUG_W25X20CL
|
#endif //DEBUG_XFLASH
|
||||||
|
|
||||||
// lang_reset();
|
// lang_reset();
|
||||||
if (!lang_select(eeprom_read_byte((uint8_t*)EEPROM_LANG)))
|
if (!lang_select(eeprom_read_byte((uint8_t*)EEPROM_LANG)))
|
||||||
|
|
@ -4013,10 +4013,10 @@ void process_commands()
|
||||||
}
|
}
|
||||||
else if (code_seen_P(PSTR("RESET"))) { // PRUSA RESET
|
else if (code_seen_P(PSTR("RESET"))) { // PRUSA RESET
|
||||||
#ifdef WATCHDOG
|
#ifdef WATCHDOG
|
||||||
#if defined(W25X20CL) && defined(BOOTAPP)
|
#if defined(XFLASH) && defined(BOOTAPP)
|
||||||
boot_app_magic = BOOT_APP_MAGIC;
|
boot_app_magic = BOOT_APP_MAGIC;
|
||||||
boot_app_flags = BOOT_APP_FLG_RUN;
|
boot_app_flags = BOOT_APP_FLG_RUN;
|
||||||
#endif //defined(W25X20CL) && defined(BOOTAPP)
|
#endif //defined(XFLASH) && defined(BOOTAPP)
|
||||||
softReset();
|
softReset();
|
||||||
#elif defined(BOOTAPP) //this is a safety precaution. This is because the new bootloader turns off the heaters, but the old one doesn't. The watchdog should be used most of the time.
|
#elif defined(BOOTAPP) //this is a safety precaution. This is because the new bootloader turns off the heaters, but the old one doesn't. The watchdog should be used most of the time.
|
||||||
asm volatile("jmp 0x3E000");
|
asm volatile("jmp 0x3E000");
|
||||||
|
|
|
||||||
|
|
@ -54,14 +54,6 @@
|
||||||
#define TMC2130_SPCR SPI_SPCR(TMC2130_SPI_RATE, 1, 1, 1, 0)
|
#define TMC2130_SPCR SPI_SPCR(TMC2130_SPI_RATE, 1, 1, 1, 0)
|
||||||
#define TMC2130_SPSR SPI_SPSR(TMC2130_SPI_RATE)
|
#define TMC2130_SPSR SPI_SPSR(TMC2130_SPI_RATE)
|
||||||
|
|
||||||
//W25X20CL configuration
|
|
||||||
//pinout:
|
|
||||||
#define W25X20CL_PIN_CS 32
|
|
||||||
//spi:
|
|
||||||
#define W25X20CL_SPI_RATE 0 // fosc/4 = 4MHz
|
|
||||||
#define W25X20CL_SPCR SPI_SPCR(W25X20CL_SPI_RATE, 1, 1, 1, 0)
|
|
||||||
#define W25X20CL_SPSR SPI_SPSR(W25X20CL_SPI_RATE)
|
|
||||||
|
|
||||||
//LANG - Multi-language support
|
//LANG - Multi-language support
|
||||||
//#define LANG_MODE 0 // primary language only
|
//#define LANG_MODE 0 // primary language only
|
||||||
#define LANG_MODE 1 // sec. language support
|
#define LANG_MODE 1 // sec. language support
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
#include "w25x20cl.h"
|
#include "xflash.h"
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
|
|
||||||
// Currently active language selection.
|
// Currently active language selection.
|
||||||
uint8_t lang_selected = 0;
|
uint8_t lang_selected = 0;
|
||||||
|
|
@ -54,7 +54,7 @@ uint8_t lang_select(uint8_t lang)
|
||||||
lang_table = 0;
|
lang_table = 0;
|
||||||
lang_selected = lang;
|
lang_selected = lang;
|
||||||
}
|
}
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
if (lang_get_code(lang) == lang_get_code(LANG_ID_SEC)) lang = LANG_ID_SEC;
|
if (lang_get_code(lang) == lang_get_code(LANG_ID_SEC)) lang = LANG_ID_SEC;
|
||||||
if (lang == LANG_ID_SEC) //current secondary language
|
if (lang == LANG_ID_SEC) //current secondary language
|
||||||
{
|
{
|
||||||
|
|
@ -68,7 +68,7 @@ uint8_t lang_select(uint8_t lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else //W25X20CL
|
#else //XFLASH
|
||||||
if (lang == LANG_ID_SEC)
|
if (lang == LANG_ID_SEC)
|
||||||
{
|
{
|
||||||
uint16_t table = _SEC_LANG_TABLE;
|
uint16_t table = _SEC_LANG_TABLE;
|
||||||
|
|
@ -82,7 +82,7 @@ uint8_t lang_select(uint8_t lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
if (lang_selected == lang)
|
if (lang_selected == lang)
|
||||||
{
|
{
|
||||||
eeprom_update_byte((unsigned char*)EEPROM_LANG, lang_selected);
|
eeprom_update_byte((unsigned char*)EEPROM_LANG, lang_selected);
|
||||||
|
|
@ -107,19 +107,19 @@ uint8_t lang_get_count()
|
||||||
{
|
{
|
||||||
if (pgm_read_dword(((uint32_t*)(_PRI_LANG_SIGNATURE))) == 0xffffffff)
|
if (pgm_read_dword(((uint32_t*)(_PRI_LANG_SIGNATURE))) == 0xffffffff)
|
||||||
return 1; //signature not set - only primary language will be available
|
return 1; //signature not set - only primary language will be available
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
W25X20CL_SPI_ENTER();
|
XFLASH_SPI_ENTER();
|
||||||
uint8_t count = 2; //count = 1+n (primary + secondary + all in xflash)
|
uint8_t count = 2; //count = 1+n (primary + secondary + all in xflash)
|
||||||
uint32_t addr = 0x00000; //start of xflash
|
uint32_t addr = 0x00000; //start of xflash
|
||||||
lang_table_header_t header; //table header structure
|
lang_table_header_t header; //table header structure
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
w25x20cl_rd_data(addr, (uint8_t*)&header, sizeof(lang_table_header_t)); //read table header from xflash
|
xflash_rd_data(addr, (uint8_t*)&header, sizeof(lang_table_header_t)); //read table header from xflash
|
||||||
if (header.magic != LANG_MAGIC) break; //break if magic not valid
|
if (header.magic != LANG_MAGIC) break; //break if magic not valid
|
||||||
addr += header.size; //calc address of next table
|
addr += header.size; //calc address of next table
|
||||||
count++; //inc counter
|
count++; //inc counter
|
||||||
}
|
}
|
||||||
#else //W25X20CL
|
#else //XFLASH
|
||||||
uint16_t table = _SEC_LANG_TABLE;
|
uint16_t table = _SEC_LANG_TABLE;
|
||||||
uint8_t count = 1; //count = 1 (primary)
|
uint8_t count = 1; //count = 1 (primary)
|
||||||
while (pgm_read_dword(((uint32_t*)table)) == LANG_MAGIC) //magic valid
|
while (pgm_read_dword(((uint32_t*)table)) == LANG_MAGIC) //magic valid
|
||||||
|
|
@ -127,14 +127,14 @@ uint8_t lang_get_count()
|
||||||
table += pgm_read_word((uint16_t*)(table + 4));
|
table += pgm_read_word((uint16_t*)(table + 4));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* offset)
|
uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* offset)
|
||||||
{
|
{
|
||||||
if (lang == LANG_ID_PRI) return 0; //primary lang not supported for this function
|
if (lang == LANG_ID_PRI) return 0; //primary lang not supported for this function
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
if (lang == LANG_ID_SEC)
|
if (lang == LANG_ID_SEC)
|
||||||
{
|
{
|
||||||
uint16_t ui = _SEC_LANG_TABLE; //table pointer
|
uint16_t ui = _SEC_LANG_TABLE; //table pointer
|
||||||
|
|
@ -142,18 +142,18 @@ uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* off
|
||||||
if (offset) *offset = ui;
|
if (offset) *offset = ui;
|
||||||
return (header->magic == LANG_MAGIC)?1:0; //return 1 if magic valid
|
return (header->magic == LANG_MAGIC)?1:0; //return 1 if magic valid
|
||||||
}
|
}
|
||||||
W25X20CL_SPI_ENTER();
|
XFLASH_SPI_ENTER();
|
||||||
uint32_t addr = 0x00000; //start of xflash
|
uint32_t addr = 0x00000; //start of xflash
|
||||||
lang--;
|
lang--;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
w25x20cl_rd_data(addr, (uint8_t*)(header), sizeof(lang_table_header_t)); //read table header from xflash
|
xflash_rd_data(addr, (uint8_t*)(header), sizeof(lang_table_header_t)); //read table header from xflash
|
||||||
if (header->magic != LANG_MAGIC) break; //break if not valid
|
if (header->magic != LANG_MAGIC) break; //break if not valid
|
||||||
if (offset) *offset = addr;
|
if (offset) *offset = addr;
|
||||||
if (--lang == 0) return 1;
|
if (--lang == 0) return 1;
|
||||||
addr += header->size; //calc address of next table
|
addr += header->size; //calc address of next table
|
||||||
}
|
}
|
||||||
#else //W25X20CL
|
#else //XFLASH
|
||||||
if (lang == LANG_ID_SEC)
|
if (lang == LANG_ID_SEC)
|
||||||
{
|
{
|
||||||
uint16_t ui = _SEC_LANG_TABLE; //table pointer
|
uint16_t ui = _SEC_LANG_TABLE; //table pointer
|
||||||
|
|
@ -161,32 +161,32 @@ uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* off
|
||||||
if (offset) *offset = ui;
|
if (offset) *offset = ui;
|
||||||
return (header->magic == LANG_MAGIC)?1:0; //return 1 if magic valid
|
return (header->magic == LANG_MAGIC)?1:0; //return 1 if magic valid
|
||||||
}
|
}
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t lang_get_code(uint8_t lang)
|
uint16_t lang_get_code(uint8_t lang)
|
||||||
{
|
{
|
||||||
if (lang == LANG_ID_PRI) return LANG_CODE_EN; //primary lang = EN
|
if (lang == LANG_ID_PRI) return LANG_CODE_EN; //primary lang = EN
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
if (lang == LANG_ID_SEC)
|
if (lang == LANG_ID_SEC)
|
||||||
{
|
{
|
||||||
uint16_t ui = _SEC_LANG_TABLE; //table pointer
|
uint16_t ui = _SEC_LANG_TABLE; //table pointer
|
||||||
if (pgm_read_dword(((uint32_t*)(ui + 0))) != LANG_MAGIC) return LANG_CODE_XX; //magic not valid
|
if (pgm_read_dword(((uint32_t*)(ui + 0))) != LANG_MAGIC) return LANG_CODE_XX; //magic not valid
|
||||||
return pgm_read_word(((uint32_t*)(ui + 10))); //return lang code from progmem
|
return pgm_read_word(((uint32_t*)(ui + 10))); //return lang code from progmem
|
||||||
}
|
}
|
||||||
W25X20CL_SPI_ENTER();
|
XFLASH_SPI_ENTER();
|
||||||
uint32_t addr = 0x00000; //start of xflash
|
uint32_t addr = 0x00000; //start of xflash
|
||||||
lang_table_header_t header; //table header structure
|
lang_table_header_t header; //table header structure
|
||||||
lang--;
|
lang--;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
w25x20cl_rd_data(addr, (uint8_t*)&header, sizeof(lang_table_header_t)); //read table header from xflash
|
xflash_rd_data(addr, (uint8_t*)&header, sizeof(lang_table_header_t)); //read table header from xflash
|
||||||
if (header.magic != LANG_MAGIC) break; //break if not valid
|
if (header.magic != LANG_MAGIC) break; //break if not valid
|
||||||
if (--lang == 0) return header.code;
|
if (--lang == 0) return header.code;
|
||||||
addr += header.size; //calc address of next table
|
addr += header.size; //calc address of next table
|
||||||
}
|
}
|
||||||
#else //W25X20CL
|
#else //XFLASH
|
||||||
uint16_t table = _SEC_LANG_TABLE;
|
uint16_t table = _SEC_LANG_TABLE;
|
||||||
uint8_t count = 1; //count = 1 (primary)
|
uint8_t count = 1; //count = 1 (primary)
|
||||||
while (pgm_read_dword((uint32_t*)table) == LANG_MAGIC) //magic valid
|
while (pgm_read_dword((uint32_t*)table) == LANG_MAGIC) //magic valid
|
||||||
|
|
@ -195,7 +195,7 @@ uint16_t lang_get_code(uint8_t lang)
|
||||||
table += pgm_read_word((uint16_t*)(table + 4));
|
table += pgm_read_word((uint16_t*)(table + 4));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
return LANG_CODE_XX;
|
return LANG_CODE_XX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#ifndef OPTIBOOT_W25X20CL_H
|
|
||||||
#define OPTIBOOT_W25X20CL_H
|
|
||||||
|
|
||||||
extern uint8_t optiboot_w25x20cl_enter();
|
|
||||||
|
|
||||||
#endif /* OPTIBOOT_W25X20CL_H */
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
// Licence GLP 2 or later.
|
// Licence GLP 2 or later.
|
||||||
|
|
||||||
#include "Marlin.h"
|
#include "Marlin.h"
|
||||||
#include "w25x20cl.h"
|
#include "xflash.h"
|
||||||
#include "stk500.h"
|
#include "stk500.h"
|
||||||
#include "bootapp.h"
|
#include "bootapp.h"
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
|
|
@ -16,14 +16,14 @@ static unsigned const int __attribute__((section(".version")))
|
||||||
optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER;
|
optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define W25X20CL_SIGNATURE_0 9
|
#define XFLASH_SIGNATURE_0 9
|
||||||
#define W25X20CL_SIGNATURE_1 8
|
#define XFLASH_SIGNATURE_1 8
|
||||||
#define W25X20CL_SIGNATURE_2 7
|
#define XFLASH_SIGNATURE_2 7
|
||||||
#else
|
#else
|
||||||
//FIXME this is a signature of ATmega2560!
|
//FIXME this is a signature of ATmega2560!
|
||||||
#define W25X20CL_SIGNATURE_0 0x1E
|
#define XFLASH_SIGNATURE_0 0x1E
|
||||||
#define W25X20CL_SIGNATURE_1 0x98
|
#define XFLASH_SIGNATURE_1 0x98
|
||||||
#define W25X20CL_SIGNATURE_2 0x01
|
#define XFLASH_SIGNATURE_2 0x01
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define RECV_READY ((UCSR0A & _BV(RXC0)) != 0)
|
#define RECV_READY ((UCSR0A & _BV(RXC0)) != 0)
|
||||||
|
|
@ -78,7 +78,7 @@ extern struct block_t *block_buffer;
|
||||||
//! @brief Enter an STK500 compatible Optiboot boot loader waiting for flashing the languages to an external flash memory.
|
//! @brief Enter an STK500 compatible Optiboot boot loader waiting for flashing the languages to an external flash memory.
|
||||||
//! @return 1 if "start\n" was not sent. Optiboot was skipped
|
//! @return 1 if "start\n" was not sent. Optiboot was skipped
|
||||||
//! @return 0 if "start\n" was sent. Optiboot ran normally. No need to send "start\n" in setup()
|
//! @return 0 if "start\n" was sent. Optiboot ran normally. No need to send "start\n" in setup()
|
||||||
uint8_t optiboot_w25x20cl_enter()
|
uint8_t optiboot_xflash_enter()
|
||||||
{
|
{
|
||||||
// Make sure to check boot_app_magic as well. Since these bootapp flags are located right in the middle of the stack,
|
// Make sure to check boot_app_magic as well. Since these bootapp flags are located right in the middle of the stack,
|
||||||
// they can be unintentionally changed. As a workaround to the language upload problem, do not only check for one bit if it's set,
|
// they can be unintentionally changed. As a workaround to the language upload problem, do not only check for one bit if it's set,
|
||||||
|
|
@ -154,7 +154,7 @@ uint8_t optiboot_w25x20cl_enter()
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_init();
|
spi_init();
|
||||||
w25x20cl_init();
|
xflash_init();
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
|
|
||||||
/* Forever loop: exits by causing WDT reset */
|
/* Forever loop: exits by causing WDT reset */
|
||||||
|
|
@ -254,16 +254,16 @@ uint8_t optiboot_w25x20cl_enter()
|
||||||
// During a single bootloader run, only erase a 64kB block once.
|
// During a single bootloader run, only erase a 64kB block once.
|
||||||
// An 8bit bitmask 'pages_erased' covers 512kB of FLASH memory.
|
// An 8bit bitmask 'pages_erased' covers 512kB of FLASH memory.
|
||||||
if ((address == 0) && (pages_erased & (1 << (addr >> 16))) == 0) {
|
if ((address == 0) && (pages_erased & (1 << (addr >> 16))) == 0) {
|
||||||
w25x20cl_wait_busy();
|
xflash_wait_busy();
|
||||||
w25x20cl_enable_wr();
|
xflash_enable_wr();
|
||||||
w25x20cl_block64_erase(addr);
|
xflash_block64_erase(addr);
|
||||||
pages_erased |= (1 << (addr >> 16));
|
pages_erased |= (1 << (addr >> 16));
|
||||||
}
|
}
|
||||||
w25x20cl_wait_busy();
|
xflash_wait_busy();
|
||||||
w25x20cl_enable_wr();
|
xflash_enable_wr();
|
||||||
w25x20cl_page_program(addr, buff, savelength);
|
xflash_page_program(addr, buff, savelength);
|
||||||
w25x20cl_wait_busy();
|
xflash_wait_busy();
|
||||||
w25x20cl_disable_wr();
|
xflash_disable_wr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Read memory block mode, length is big endian. */
|
/* Read memory block mode, length is big endian. */
|
||||||
|
|
@ -279,8 +279,8 @@ uint8_t optiboot_w25x20cl_enter()
|
||||||
// Read the destination type. It should always be 'F' as flash. It is not checked.
|
// Read the destination type. It should always be 'F' as flash. It is not checked.
|
||||||
(void)getch();
|
(void)getch();
|
||||||
verifySpace();
|
verifySpace();
|
||||||
w25x20cl_wait_busy();
|
xflash_wait_busy();
|
||||||
w25x20cl_rd_data(addr, buff, length);
|
xflash_rd_data(addr, buff, length);
|
||||||
for (i = 0; i < length; ++ i)
|
for (i = 0; i < length; ++ i)
|
||||||
putch(buff[i]);
|
putch(buff[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -288,9 +288,9 @@ uint8_t optiboot_w25x20cl_enter()
|
||||||
else if(ch == STK_READ_SIGN) {
|
else if(ch == STK_READ_SIGN) {
|
||||||
// READ SIGN - return what Avrdude wants to hear
|
// READ SIGN - return what Avrdude wants to hear
|
||||||
verifySpace();
|
verifySpace();
|
||||||
putch(W25X20CL_SIGNATURE_0);
|
putch(XFLASH_SIGNATURE_0);
|
||||||
putch(W25X20CL_SIGNATURE_1);
|
putch(XFLASH_SIGNATURE_1);
|
||||||
putch(W25X20CL_SIGNATURE_2);
|
putch(XFLASH_SIGNATURE_2);
|
||||||
}
|
}
|
||||||
else if (ch == STK_LEAVE_PROGMODE) { /* 'Q' */
|
else if (ch == STK_LEAVE_PROGMODE) { /* 'Q' */
|
||||||
// Adaboot no-wait mod
|
// Adaboot no-wait mod
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef OPTIBOOT_XFLASH_H
|
||||||
|
#define OPTIBOOT_XFLASH_H
|
||||||
|
|
||||||
|
extern uint8_t optiboot_xflash_enter();
|
||||||
|
|
||||||
|
#endif /* OPTIBOOT_XFLASH_H */
|
||||||
|
|
@ -15,9 +15,11 @@
|
||||||
#define AMBIENT_THERMISTOR
|
#define AMBIENT_THERMISTOR
|
||||||
#define PINDA_THERMISTOR
|
#define PINDA_THERMISTOR
|
||||||
|
|
||||||
#define W25X20CL // external 256kB flash
|
#define XFLASH // external 256kB flash
|
||||||
#define BOOTAPP // bootloader support
|
#define BOOTAPP // bootloader support
|
||||||
|
|
||||||
|
#define XFLASH_PIN_CS 32
|
||||||
|
|
||||||
#define X_TMC2130_CS 41
|
#define X_TMC2130_CS 41
|
||||||
#define X_TMC2130_DIAG 64 // !!! changed from 40 (EINY03)
|
#define X_TMC2130_DIAG 64 // !!! changed from 40 (EINY03)
|
||||||
#define X_STEP_PIN 37
|
#define X_STEP_PIN 37
|
||||||
|
|
|
||||||
|
|
@ -4361,7 +4361,7 @@ void menu_setlang(unsigned char lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef COMMUNITY_LANG_SUPPORT
|
#ifdef COMMUNITY_LANG_SUPPORT
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
static void lcd_community_language_menu()
|
static void lcd_community_language_menu()
|
||||||
{
|
{
|
||||||
MENU_BEGIN();
|
MENU_BEGIN();
|
||||||
|
|
@ -4375,7 +4375,7 @@ static void lcd_community_language_menu()
|
||||||
}
|
}
|
||||||
MENU_END();
|
MENU_END();
|
||||||
}
|
}
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
#endif //COMMUNITY_LANG_SUPPORT && W52X20CL
|
#endif //COMMUNITY_LANG_SUPPORT && W52X20CL
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4390,7 +4390,7 @@ static void lcd_language_menu()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint8_t cnt = lang_get_count();
|
uint8_t cnt = lang_get_count();
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
if (cnt == 2) //display secondary language in case of clear xflash
|
if (cnt == 2) //display secondary language in case of clear xflash
|
||||||
{
|
{
|
||||||
if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
|
if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
|
||||||
|
|
@ -4401,9 +4401,9 @@ static void lcd_language_menu()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
|
for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
|
||||||
#else //W25X20CL
|
#else //XFLASH
|
||||||
for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
|
for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
|
if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
|
||||||
{
|
{
|
||||||
menu_setlang(i);
|
menu_setlang(i);
|
||||||
|
|
@ -4411,9 +4411,9 @@ static void lcd_language_menu()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef COMMUNITY_LANG_SUPPORT
|
#ifdef COMMUNITY_LANG_SUPPORT
|
||||||
#ifdef W25X20CL
|
#ifdef XFLASH
|
||||||
MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu); ////MSG_COMMUNITY_MADE c=18
|
MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu); ////MSG_COMMUNITY_MADE c=18
|
||||||
#endif //W25X20CL
|
#endif //XFLASH
|
||||||
#endif //COMMUNITY_LANG_SUPPORT && W52X20CL
|
#endif //COMMUNITY_LANG_SUPPORT && W52X20CL
|
||||||
|
|
||||||
MENU_END();
|
MENU_END();
|
||||||
|
|
@ -6323,15 +6323,15 @@ unsigned char lcd_choose_color() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "w25x20cl.h"
|
#include "xflash.h"
|
||||||
|
|
||||||
#ifdef LCD_TEST
|
#ifdef LCD_TEST
|
||||||
static void lcd_test_menu()
|
static void lcd_test_menu()
|
||||||
{
|
{
|
||||||
W25X20CL_SPI_ENTER();
|
XFLASH_SPI_ENTER();
|
||||||
w25x20cl_enable_wr();
|
xflash_enable_wr();
|
||||||
w25x20cl_chip_erase();
|
xflash_chip_erase();
|
||||||
w25x20cl_disable_wr();
|
xflash_disable_wr();
|
||||||
}
|
}
|
||||||
#endif //LCD_TEST
|
#endif //LCD_TEST
|
||||||
|
|
||||||
|
|
@ -6672,7 +6672,7 @@ static void lcd_main_menu()
|
||||||
}
|
}
|
||||||
MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT
|
MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT
|
||||||
#ifdef LCD_TEST
|
#ifdef LCD_TEST
|
||||||
MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT
|
MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_SUPPORT
|
||||||
#endif //LCD_TEST
|
#endif //LCD_TEST
|
||||||
|
|
||||||
MENU_END();
|
MENU_END();
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@
|
||||||
|
|
||||||
//#define DEBUG_BUILD
|
//#define DEBUG_BUILD
|
||||||
//#define DEBUG_SEC_LANG //secondary language debug output at startup
|
//#define DEBUG_SEC_LANG //secondary language debug output at startup
|
||||||
//#define DEBUG_W25X20CL //debug external spi flash
|
//#define DEBUG_XFLASH //debug external spi flash
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
//#define _NO_ASM
|
//#define _NO_ASM
|
||||||
#define DEBUG_DCODES //D codes
|
#define DEBUG_DCODES //D codes
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@
|
||||||
|
|
||||||
//#define DEBUG_BUILD
|
//#define DEBUG_BUILD
|
||||||
//#define DEBUG_SEC_LANG //secondary language debug output at startup
|
//#define DEBUG_SEC_LANG //secondary language debug output at startup
|
||||||
//#define DEBUG_W25X20CL //debug external spi flash
|
//#define DEBUG_XFLASH //debug external spi flash
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
//#define _NO_ASM
|
//#define _NO_ASM
|
||||||
#define DEBUG_DCODES //D codes
|
#define DEBUG_DCODES //D codes
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
//w25x20cl.h
|
|
||||||
#ifndef _W25X20CL_H
|
|
||||||
#define _W25X20CL_H
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include "config.h"
|
|
||||||
#include "spi.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define W25X20CL_STATUS_BUSY 0x01
|
|
||||||
#define W25X20CL_STATUS_WEL 0x02
|
|
||||||
#define W25X20CL_STATUS_BP0 0x04
|
|
||||||
#define W25X20CL_STATUS_BP1 0x08
|
|
||||||
#define W25X20CL_STATUS_TB 0x20
|
|
||||||
#define W25X20CL_STATUS_SRP 0x80
|
|
||||||
|
|
||||||
#define W25X20CL_SPI_ENTER() spi_setup(W25X20CL_SPCR, W25X20CL_SPSR)
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif //defined(__cplusplus)
|
|
||||||
|
|
||||||
|
|
||||||
extern int8_t w25x20cl_init(void);
|
|
||||||
extern void w25x20cl_enable_wr(void);
|
|
||||||
extern void w25x20cl_disable_wr(void);
|
|
||||||
extern uint8_t w25x20cl_rd_status_reg(void);
|
|
||||||
extern void w25x20cl_wr_status_reg(uint8_t val);
|
|
||||||
extern void w25x20cl_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt);
|
|
||||||
extern void w25x20cl_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
|
|
||||||
extern void w25x20cl_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt);
|
|
||||||
extern void w25x20cl_sector_erase(uint32_t addr);
|
|
||||||
extern void w25x20cl_block32_erase(uint32_t addr);
|
|
||||||
extern void w25x20cl_block64_erase(uint32_t addr);
|
|
||||||
extern void w25x20cl_chip_erase(void);
|
|
||||||
extern void w25x20cl_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
|
|
||||||
extern void w25x20cl_rd_uid(uint8_t* uid);
|
|
||||||
extern void w25x20cl_wait_busy(void);
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif //defined(__cplusplus)
|
|
||||||
#endif //_W25X20CL_H
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//w25x20cl.c
|
//xflash.c
|
||||||
|
|
||||||
#include "w25x20cl.h"
|
#include "xflash.h"
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
@ -31,8 +31,8 @@
|
||||||
#define _CMD_JEDEC_ID 0x9f
|
#define _CMD_JEDEC_ID 0x9f
|
||||||
#define _CMD_RD_UID 0x4b
|
#define _CMD_RD_UID 0x4b
|
||||||
|
|
||||||
#define _CS_LOW() WRITE(W25X20CL_PIN_CS, 0)
|
#define _CS_LOW() WRITE(XFLASH_PIN_CS, 0)
|
||||||
#define _CS_HIGH() WRITE(W25X20CL_PIN_CS, 1)
|
#define _CS_HIGH() WRITE(XFLASH_PIN_CS, 1)
|
||||||
|
|
||||||
//#define _SPI_TX swspi_tx
|
//#define _SPI_TX swspi_tx
|
||||||
//#define _SPI_RX swspi_rx
|
//#define _SPI_RX swspi_rx
|
||||||
|
|
@ -40,33 +40,33 @@
|
||||||
#define _SPI_RX() spi_txrx(0xff)
|
#define _SPI_RX() spi_txrx(0xff)
|
||||||
|
|
||||||
|
|
||||||
int w25x20cl_mfrid_devid(void);
|
int xflash_mfrid_devid(void);
|
||||||
|
|
||||||
|
|
||||||
int8_t w25x20cl_init(void)
|
int8_t xflash_init(void)
|
||||||
{
|
{
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
SET_OUTPUT(W25X20CL_PIN_CS);
|
SET_OUTPUT(XFLASH_PIN_CS);
|
||||||
W25X20CL_SPI_ENTER();
|
XFLASH_SPI_ENTER();
|
||||||
if (!w25x20cl_mfrid_devid()) return 0;
|
if (!xflash_mfrid_devid()) return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_enable_wr(void)
|
void xflash_enable_wr(void)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_ENABLE_WR); // send command 0x06
|
_SPI_TX(_CMD_ENABLE_WR); // send command 0x06
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_disable_wr(void)
|
void xflash_disable_wr(void)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_DISABLE_WR); // send command 0x04
|
_SPI_TX(_CMD_DISABLE_WR); // send command 0x04
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t w25x20cl_rd_status_reg(void)
|
uint8_t xflash_rd_status_reg(void)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_RD_STATUS_REG); // send command 0x90
|
_SPI_TX(_CMD_RD_STATUS_REG); // send command 0x90
|
||||||
|
|
@ -75,6 +75,7 @@ uint8_t w25x20cl_rd_status_reg(void)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void w25x20cl_wr_status_reg(uint8_t val)
|
void w25x20cl_wr_status_reg(uint8_t val)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
|
|
@ -82,8 +83,9 @@ void w25x20cl_wr_status_reg(uint8_t val)
|
||||||
_SPI_TX(val); // send value
|
_SPI_TX(val); // send value
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void w25x20cl_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt)
|
void xflash_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_RD_DATA); // send command 0x03
|
_SPI_TX(_CMD_RD_DATA); // send command 0x03
|
||||||
|
|
@ -95,7 +97,7 @@ void w25x20cl_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt)
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_page_program(uint32_t addr, uint8_t* data, uint16_t cnt)
|
void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
|
_SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
|
||||||
|
|
@ -107,7 +109,7 @@ void w25x20cl_page_program(uint32_t addr, uint8_t* data, uint16_t cnt)
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt)
|
void xflash_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
|
_SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
|
||||||
|
|
@ -119,7 +121,7 @@ void w25x20cl_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt)
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_erase(uint8_t cmd, uint32_t addr)
|
void xflash_erase(uint8_t cmd, uint32_t addr)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(cmd); // send command 0x20
|
_SPI_TX(cmd); // send command 0x20
|
||||||
|
|
@ -129,22 +131,22 @@ void w25x20cl_erase(uint8_t cmd, uint32_t addr)
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_sector_erase(uint32_t addr)
|
void xflash_sector_erase(uint32_t addr)
|
||||||
{
|
{
|
||||||
return w25x20cl_erase(_CMD_SECTOR_ERASE, addr);
|
return xflash_erase(_CMD_SECTOR_ERASE, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_block32_erase(uint32_t addr)
|
void xflash_block32_erase(uint32_t addr)
|
||||||
{
|
{
|
||||||
return w25x20cl_erase(_CMD_BLOCK32_ERASE, addr);
|
return xflash_erase(_CMD_BLOCK32_ERASE, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_block64_erase(uint32_t addr)
|
void xflash_block64_erase(uint32_t addr)
|
||||||
{
|
{
|
||||||
return w25x20cl_erase(_CMD_BLOCK64_ERASE, addr);
|
return xflash_erase(_CMD_BLOCK64_ERASE, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_chip_erase(void)
|
void xflash_chip_erase(void)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_CHIP_ERASE); // send command 0xc7
|
_SPI_TX(_CMD_CHIP_ERASE); // send command 0xc7
|
||||||
|
|
@ -152,7 +154,7 @@ void w25x20cl_chip_erase(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void w25x20cl_rd_uid(uint8_t* uid)
|
void xflash_rd_uid(uint8_t* uid)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_RD_UID); // send command 0x4b
|
_SPI_TX(_CMD_RD_UID); // send command 0x4b
|
||||||
|
|
@ -165,20 +167,20 @@ void w25x20cl_rd_uid(uint8_t* uid)
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
int w25x20cl_mfrid_devid(void)
|
int xflash_mfrid_devid(void)
|
||||||
{
|
{
|
||||||
_CS_LOW();
|
_CS_LOW();
|
||||||
_SPI_TX(_CMD_MFRID_DEVID); // send command 0x90
|
_SPI_TX(_CMD_MFRID_DEVID); // send command 0x90
|
||||||
uint8_t cnt = 3; // 3 address bytes
|
uint8_t cnt = 3; // 3 address bytes
|
||||||
while (cnt--) // send address bytes
|
while (cnt--) // send address bytes
|
||||||
_SPI_TX(0x00);
|
_SPI_TX(0x00);
|
||||||
uint8_t w25x20cl_mfrid = _SPI_RX(); // receive mfrid
|
uint8_t xflash_mfrid = _SPI_RX(); // receive mfrid
|
||||||
uint8_t w25x20cl_devid = _SPI_RX(); // receive devid
|
uint8_t xflash_devid = _SPI_RX(); // receive devid
|
||||||
_CS_HIGH();
|
_CS_HIGH();
|
||||||
return ((w25x20cl_mfrid == _MFRID) && (w25x20cl_devid == _DEVID));
|
return ((xflash_mfrid == _MFRID) && (xflash_devid == _DEVID));
|
||||||
}
|
}
|
||||||
|
|
||||||
void w25x20cl_wait_busy(void)
|
void xflash_wait_busy(void)
|
||||||
{
|
{
|
||||||
while (w25x20cl_rd_status_reg() & W25X20CL_STATUS_BUSY) ;
|
while (xflash_rd_status_reg() & XFLASH_STATUS_BUSY) ;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
//xflash.h
|
||||||
|
#ifndef _XFLASH_H
|
||||||
|
#define _XFLASH_H
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "config.h"
|
||||||
|
#include "spi.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define XFLASH_STATUS_BUSY 0x01
|
||||||
|
#define XFLASH_STATUS_WEL 0x02
|
||||||
|
#define XFLASH_STATUS_BP0 0x04
|
||||||
|
#define XFLASH_STATUS_BP1 0x08
|
||||||
|
#define XFLASH_STATUS_TB 0x20
|
||||||
|
#define XFLASH_STATUS_SRP 0x80
|
||||||
|
|
||||||
|
#define XFLASH_SPI_RATE 0 // fosc/4 = 4MHz
|
||||||
|
#define XFLASH_SPCR SPI_SPCR(XFLASH_SPI_RATE, 1, 1, 1, 0)
|
||||||
|
#define XFLASH_SPSR SPI_SPSR(XFLASH_SPI_RATE)
|
||||||
|
|
||||||
|
#define XFLASH_SPI_ENTER() spi_setup(XFLASH_SPCR, XFLASH_SPSR)
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif //defined(__cplusplus)
|
||||||
|
|
||||||
|
|
||||||
|
extern int8_t xflash_init(void);
|
||||||
|
extern void xflash_enable_wr(void);
|
||||||
|
extern void xflash_disable_wr(void);
|
||||||
|
extern uint8_t xflash_rd_status_reg(void);
|
||||||
|
#if 0
|
||||||
|
extern void w25x20cl_wr_status_reg(uint8_t val);
|
||||||
|
#endif
|
||||||
|
extern void xflash_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt);
|
||||||
|
extern void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
|
||||||
|
extern void xflash_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt);
|
||||||
|
extern void xflash_sector_erase(uint32_t addr);
|
||||||
|
extern void xflash_block32_erase(uint32_t addr);
|
||||||
|
extern void xflash_block64_erase(uint32_t addr);
|
||||||
|
extern void xflash_chip_erase(void);
|
||||||
|
extern void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
|
||||||
|
extern void xflash_rd_uid(uint8_t* uid);
|
||||||
|
extern void xflash_wait_busy(void);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif //defined(__cplusplus)
|
||||||
|
#endif //_XFLASH_H
|
||||||
Loading…
Reference in New Issue