Line 163... |
Line 163... |
void save_exe(void);
|
void save_exe(void);
|
uint32_t get_exe_word(int src, uint32_t addr);
|
uint32_t get_exe_word(int src, uint32_t addr);
|
void system_error(uint8_t err_code);
|
void system_error(uint8_t err_code);
|
void print_hex_word(uint32_t num);
|
void print_hex_word(uint32_t num);
|
|
|
// SPI flash access
|
// SPI flash driver functions
|
uint8_t spi_flash_read_byte(uint32_t addr);
|
uint8_t spi_flash_read_byte(uint32_t addr);
|
void spi_flash_write_byte(uint32_t addr, uint8_t wdata);
|
void spi_flash_write_byte(uint32_t addr, uint8_t wdata);
|
void spi_flash_write_word(uint32_t addr, uint32_t wdata);
|
void spi_flash_write_word(uint32_t addr, uint32_t wdata);
|
void spi_flash_erase_sector(uint32_t addr);
|
void spi_flash_erase_sector(uint32_t addr);
|
uint8_t spi_flash_read_status(void);
|
|
uint8_t spi_flash_read_1st_id(void);
|
uint8_t spi_flash_read_1st_id(void);
|
|
void spi_flash_write_wait(void);
|
void spi_flash_write_enable(void);
|
void spi_flash_write_enable(void);
|
void spi_flash_write_addr(uint32_t addr);
|
void spi_flash_write_addr(uint32_t addr);
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
Line 221... |
Line 221... |
// ------------------------------------------------
|
// ------------------------------------------------
|
// Show bootloader intro and system info
|
// Show bootloader intro and system info
|
// ------------------------------------------------
|
// ------------------------------------------------
|
neorv32_uart_print("\n\n\n\n<< NEORV32 Bootloader >>\n\n"
|
neorv32_uart_print("\n\n\n\n<< NEORV32 Bootloader >>\n\n"
|
"BLDV: "__DATE__"\nHWV: ");
|
"BLDV: "__DATE__"\nHWV: ");
|
neorv32_rte_print_hw_version();
|
print_hex_word(neorv32_cpu_csr_read(CSR_MIMPID));
|
neorv32_uart_print("\nCLK: ");
|
neorv32_uart_print("\nCLK: ");
|
print_hex_word(SYSINFO_CLK);
|
print_hex_word(SYSINFO_CLK);
|
neorv32_uart_print(" Hz\nUSER: ");
|
neorv32_uart_print(" Hz\nUSER: ");
|
print_hex_word(SYSINFO_USER_CODE);
|
print_hex_word(SYSINFO_USER_CODE);
|
neorv32_uart_print("\nMISA: ");
|
neorv32_uart_print("\nMISA: ");
|
Line 606... |
Line 606... |
}
|
}
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
// SPI flash functions
|
// SPI flash driver functions
|
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Read byte from SPI flash.
|
* Read byte from SPI flash.
|
*
|
*
|
Line 647... |
Line 647... |
spi_flash_write_addr(addr);
|
spi_flash_write_addr(addr);
|
neorv32_spi_trans(wdata);
|
neorv32_spi_trans(wdata);
|
|
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
|
|
while (1) {
|
spi_flash_write_wait(); // wait for write operation to finish
|
uint8_t tmp = spi_flash_read_status();
|
|
if ((tmp & 0x01) == 0) { // write in progress flag cleared?
|
|
break;
|
|
}
|
|
}
|
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Write word to SPI flash.
|
* Write word to SPI flash.
|
Line 694... |
Line 689... |
neorv32_spi_trans(SPI_FLASH_CMD_SECTOR_ERASE);
|
neorv32_spi_trans(SPI_FLASH_CMD_SECTOR_ERASE);
|
spi_flash_write_addr(addr);
|
spi_flash_write_addr(addr);
|
|
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
|
|
while (1) {
|
spi_flash_write_wait(); // wait for write operation to finish
|
uint8_t tmp = spi_flash_read_status();
|
|
if ((tmp & 0x01) == 0) { // write in progress flag cleared?
|
|
break;
|
|
}
|
|
}
|
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Read status register.
|
* Read first byte of ID (manufacturer ID), should be != 0x00.
|
*
|
*
|
* @return Status register.
|
* @note The first bit of the manufacturer ID is used to detect if a Flash is connected at all.
|
|
*
|
|
* @return First byte of ID.
|
**************************************************************************/
|
**************************************************************************/
|
uint8_t spi_flash_read_status(void) {
|
uint8_t spi_flash_read_1st_id(void) {
|
|
|
neorv32_spi_cs_en(SPI_FLASH_CS);
|
neorv32_spi_cs_en(SPI_FLASH_CS);
|
|
|
neorv32_spi_trans(SPI_FLASH_CMD_READ_STATUS);
|
neorv32_spi_trans(SPI_FLASH_CMD_READ_ID);
|
uint8_t status = (uint8_t)neorv32_spi_trans(0);
|
uint8_t id = (uint8_t)neorv32_spi_trans(0);
|
|
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
|
|
return status;
|
return id;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Read first byte of ID (manufacturer ID), should be != 0x00.
|
* Wait for flash write operation to finisch.
|
*
|
|
* @note The first bit of the manufacturer ID is used to detect if a Flash is connected at all.
|
|
*
|
|
* @return First byte of ID.
|
|
**************************************************************************/
|
**************************************************************************/
|
uint8_t spi_flash_read_1st_id(void) {
|
void spi_flash_write_wait(void) {
|
|
|
|
while(1) {
|
|
|
neorv32_spi_cs_en(SPI_FLASH_CS);
|
neorv32_spi_cs_en(SPI_FLASH_CS);
|
|
|
neorv32_spi_trans(SPI_FLASH_CMD_READ_ID);
|
neorv32_spi_trans(SPI_FLASH_CMD_READ_STATUS);
|
uint8_t id = (uint8_t)neorv32_spi_trans(0);
|
uint8_t status = (uint8_t)neorv32_spi_trans(0);
|
|
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
neorv32_spi_cs_dis(SPI_FLASH_CS);
|
|
|
return id;
|
if ((status & 0x01) == 0) { // write in progress flag cleared?
|
|
break;
|
|
}
|
|
}
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Enable flash write access.
|
* Enable flash write access.
|
Line 771... |
Line 764... |
neorv32_spi_trans(address.uint8[2]);
|
neorv32_spi_trans(address.uint8[2]);
|
neorv32_spi_trans(address.uint8[1]);
|
neorv32_spi_trans(address.uint8[1]);
|
neorv32_spi_trans(address.uint8[0]);
|
neorv32_spi_trans(address.uint8[0]);
|
}
|
}
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|