URL
https://opencores.org/ocsvn/neorv32/neorv32/trunk
Subversion Repositories neorv32
Compare Revisions
- This comparison shows the changes necessary to convert path
/neorv32/trunk/sw/lib
- from Rev 69 to Rev 70
- ↔ Reverse comparison
Rev 69 → Rev 70
/include/neorv32.h
3,7 → 3,7
// # ********************************************************************************************* # |
// # BSD 3-Clause License # |
// # # |
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. # |
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. # |
// # # |
// # Redistribution and use in source and binary forms, with or without modification, are # |
// # permitted provided that the following conditions are met: # |
60,7 → 60,7
enum NEORV32_CSR_enum { |
CSR_FFLAGS = 0x001, /**< 0x001 - fflags (r/w): Floating-point accrued exception flags */ |
CSR_FRM = 0x002, /**< 0x002 - frm (r/w): Floating-point dynamic rounding mode */ |
CSR_FCSR = 0x003, /**< 0x003 - fcsr (r/w): Floating-point control/staturs register (frm + fflags) */ |
CSR_FCSR = 0x003, /**< 0x003 - fcsr (r/w): Floating-point control/status register (frm + fflags) */ |
|
CSR_MSTATUS = 0x300, /**< 0x300 - mstatus (r/w): Machine status register */ |
CSR_MISA = 0x301, /**< 0x301 - misa (r/-): CPU ISA and extensions (read-only in NEORV32) */ |
827,6 → 827,47
|
|
/**********************************************************************//** |
* @name IO Device: Execute In Place Module (XIP) |
**************************************************************************/ |
/**@{*/ |
/** XIP module prototype */ |
typedef struct __attribute__((packed,aligned(4))) { |
uint32_t CTRL; /**< offset 0: control register (#NEORV32_XIP_CTRL_enum) */ |
const uint32_t reserved; /**< offset 4: reserved */ |
uint32_t DATA_LO; /**< offset 8: SPI data register low */ |
uint32_t DATA_HI; /**< offset 12: SPI data register high */ |
} neorv32_xip_t; |
|
/** XIP module hardware access (#neorv32_xip_t) */ |
#define NEORV32_XIP (*((volatile neorv32_xip_t*) (0xFFFFFF40UL))) |
|
/** XIP control/data register bits */ |
enum NEORV32_XIP_CTRL_enum { |
XIP_CTRL_EN = 0, /**< XIP control register( 0) (r/w): XIP module enable */ |
XIP_CTRL_PRSC0 = 1, /**< XIP control register( 1) (r/w): Clock prescaler select bit 0 */ |
XIP_CTRL_PRSC1 = 2, /**< XIP control register( 2) (r/w): Clock prescaler select bit 1 */ |
XIP_CTRL_PRSC2 = 3, /**< XIP control register( 3) (r/w): Clock prescaler select bit 2 */ |
XIP_CTRL_CPOL = 4, /**< XIP control register( 4) (r/w): SPI (idle) clock polarity */ |
XIP_CTRL_CPHA = 5, /**< XIP control register( 5) (r/w): SPI clock phase */ |
XIP_CTRL_SPI_NBYTES_LSB = 6, /**< XIP control register( 6) (r/w): Number of bytes in SPI transmission, LSB */ |
XIP_CTRL_SPI_NBYTES_MSB = 9, /**< XIP control register( 9) (r/w): Number of bytes in SPI transmission, MSB */ |
XIP_CTRL_XIP_EN = 10, /**< XIP control register(10) (r/w): XIP access enable */ |
XIP_CTRL_XIP_ABYTES_LSB = 11, /**< XIP control register(11) (r/w): Number XIP address bytes (minus 1), LSB */ |
XIP_CTRL_XIP_ABYTES_MSB = 12, /**< XIP control register(12) (r/w): Number XIP address bytes (minus 1), MSB */ |
XIP_CTRL_RD_CMD_LSB = 13, /**< XIP control register(13) (r/w): SPI flash read command, LSB */ |
XIP_CTRL_RD_CMD_MSB = 20, /**< XIP control register(20) (r/w): SPI flash read command, MSB */ |
XIP_CTRL_PAGE_LSB = 21, /**< XIP control register(21) (r/w): XIP memory page, LSB */ |
XIP_CTRL_PAGE_MSB = 24, /**< XIP control register(24) (r/w): XIP memory page, MSB */ |
XIP_CTRL_SPI_CSEN = 25, /**< XIP control register(25) (r/w): SPI chip-select enable */ |
XIP_CTRL_HIGHSPEED = 26, /**< XIP control register(26) (r/w): SPI high-speed mode enable (ignoring XIP_CTRL_PRSC) */ |
|
XIP_CTRL_PHY_BUSY = 30, /**< XIP control register(20) (r/-): SPI PHY is busy */ |
XIP_CTRL_XIP_BUSY = 31 /**< XIP control register(31) (r/-): XIP access in progress */ |
}; |
/**@}*/ |
|
|
/**********************************************************************//** |
* @name IO Device: General Purpose Timer (GPTMR) |
**************************************************************************/ |
/**@{*/ |
866,8 → 907,9
|
/** BUSKEEPER control/data register bits */ |
enum NEORV32_BUSKEEPER_CTRL_enum { |
BUSKEEPER_ERR_TYPE = 0, /**< BUSKEEPER control register(0) (r/-): Bus error type: 0=device error, 1=access timeout */ |
BUSKEEPER_ERR_FLAG = 31 /**< BUSKEEPER control register(31) (r/c): Sticky error flag, clears after read or write access */ |
BUSKEEPER_ERR_TYPE = 0, /**< BUSKEEPER control register( 0) (r/-): Bus error type: 0=device error, 1=access timeout */ |
BUSKEEPER_NULL_CHECK_EN = 16, /**< BUSKEEPER control register(16) (r/w): Enable NULL address check */ |
BUSKEEPER_ERR_FLAG = 31 /**< BUSKEEPER control register(31) (r/-): Sticky error flag, clears after read or write access */ |
}; |
/**@}*/ |
|
1007,24 → 1049,25
|
/** SPI control register bits */ |
enum NEORV32_SPI_CTRL_enum { |
SPI_CTRL_CS0 = 0, /**< SPI control register(0) (r/w): Direct chip select line 0 (output is low when set) */ |
SPI_CTRL_CS1 = 1, /**< SPI control register(1) (r/w): Direct chip select line 1 (output is low when set) */ |
SPI_CTRL_CS2 = 2, /**< SPI control register(2) (r/w): Direct chip select line 2 (output is low when set) */ |
SPI_CTRL_CS3 = 3, /**< SPI control register(3) (r/w): Direct chip select line 3 (output is low when set) */ |
SPI_CTRL_CS4 = 4, /**< SPI control register(4) (r/w): Direct chip select line 4 (output is low when set) */ |
SPI_CTRL_CS5 = 5, /**< SPI control register(5) (r/w): Direct chip select line 5 (output is low when set) */ |
SPI_CTRL_CS6 = 6, /**< SPI control register(6) (r/w): Direct chip select line 6 (output is low when set) */ |
SPI_CTRL_CS7 = 7, /**< SPI control register(7) (r/w): Direct chip select line 7 (output is low when set) */ |
SPI_CTRL_EN = 8, /**< SPI control register(8) (r/w): SPI unit enable */ |
SPI_CTRL_CPHA = 9, /**< SPI control register(9) (r/w): Clock phase */ |
SPI_CTRL_PRSC0 = 10, /**< SPI control register(10) (r/w): Clock prescaler select bit 0 */ |
SPI_CTRL_PRSC1 = 11, /**< SPI control register(11) (r/w): Clock prescaler select bit 1 */ |
SPI_CTRL_PRSC2 = 12, /**< SPI control register(12) (r/w): Clock prescaler select bit 2 */ |
SPI_CTRL_SIZE0 = 13, /**< SPI control register(13) (r/w): Transfer data size lsb (00: 8-bit, 01: 16-bit, 10: 24-bit, 11: 32-bit) */ |
SPI_CTRL_SIZE1 = 14, /**< SPI control register(14) (r/w): Transfer data size msb (00: 8-bit, 01: 16-bit, 10: 24-bit, 11: 32-bit) */ |
SPI_CTRL_CPOL = 15, /**< SPI control register(15) (r/w): Clock polarity */ |
SPI_CTRL_CS0 = 0, /**< SPI control register(0) (r/w): Direct chip select line 0 (output is low when set) */ |
SPI_CTRL_CS1 = 1, /**< SPI control register(1) (r/w): Direct chip select line 1 (output is low when set) */ |
SPI_CTRL_CS2 = 2, /**< SPI control register(2) (r/w): Direct chip select line 2 (output is low when set) */ |
SPI_CTRL_CS3 = 3, /**< SPI control register(3) (r/w): Direct chip select line 3 (output is low when set) */ |
SPI_CTRL_CS4 = 4, /**< SPI control register(4) (r/w): Direct chip select line 4 (output is low when set) */ |
SPI_CTRL_CS5 = 5, /**< SPI control register(5) (r/w): Direct chip select line 5 (output is low when set) */ |
SPI_CTRL_CS6 = 6, /**< SPI control register(6) (r/w): Direct chip select line 6 (output is low when set) */ |
SPI_CTRL_CS7 = 7, /**< SPI control register(7) (r/w): Direct chip select line 7 (output is low when set) */ |
SPI_CTRL_EN = 8, /**< SPI control register(8) (r/w): SPI unit enable */ |
SPI_CTRL_CPHA = 9, /**< SPI control register(9) (r/w): Clock phase */ |
SPI_CTRL_PRSC0 = 10, /**< SPI control register(10) (r/w): Clock prescaler select bit 0 */ |
SPI_CTRL_PRSC1 = 11, /**< SPI control register(11) (r/w): Clock prescaler select bit 1 */ |
SPI_CTRL_PRSC2 = 12, /**< SPI control register(12) (r/w): Clock prescaler select bit 2 */ |
SPI_CTRL_SIZE0 = 13, /**< SPI control register(13) (r/w): Transfer data size lsb (00: 8-bit, 01: 16-bit, 10: 24-bit, 11: 32-bit) */ |
SPI_CTRL_SIZE1 = 14, /**< SPI control register(14) (r/w): Transfer data size msb (00: 8-bit, 01: 16-bit, 10: 24-bit, 11: 32-bit) */ |
SPI_CTRL_CPOL = 15, /**< SPI control register(15) (r/w): Clock polarity */ |
SPI_CTRL_HIGHSPEED = 16, /**< SPI control register(16) (r/w): SPI high-speed mode enable (ignoring SPI_CTRL_PRSC) */ |
|
SPI_CTRL_BUSY = 31 /**< SPI control register(31) (r/-): SPI busy flag */ |
SPI_CTRL_BUSY = 31 /**< SPI control register(31) (r/-): SPI busy flag */ |
}; |
/**@}*/ |
|
1122,8 → 1165,8
/**@{*/ |
/** GPIO module prototype */ |
typedef struct __attribute__((packed,aligned(4))) { |
const uint32_t INPUT_LO; /**< offset 0: parallel input port lower 32-bit */ |
const uint32_t INPUT_HI; /**< offset 4: parallel input port upper 32-bit */ |
const uint32_t INPUT_LO; /**< offset 0: parallel input port lower 32-bit, read-only */ |
const uint32_t INPUT_HI; /**< offset 4: parallel input port upper 32-bit, read-only */ |
uint32_t OUTPUT_LO; /**< offset 8: parallel output port lower 32-bit */ |
uint32_t OUTPUT_HI; /**< offset 12: parallel output port upper 32-bit */ |
} neorv32_gpio_t; |
1191,7 → 1234,7
* @name IO Device: System Configuration Information Memory (SYSINFO) |
**************************************************************************/ |
/**@{*/ |
/** SYSINFO module prototype */ |
/** SYSINFO module prototype - whole module is read-only */ |
typedef struct __attribute__((packed,aligned(4))) { |
const uint32_t CLK; /**< offset 0: clock speed in Hz */ |
const uint32_t CPU; /**< offset 4: CPU core features (#NEORV32_SYSINFO_CPU_enum) */ |
1249,7 → 1292,8
SYSINFO_SOC_IO_UART1 = 26, /**< SYSINFO_FEATURES (26) (r/-): Secondary universal asynchronous receiver/transmitter 1 implemented when 1 (via IO_UART1_EN generic) */ |
SYSINFO_SOC_IO_NEOLED = 27, /**< SYSINFO_FEATURES (27) (r/-): NeoPixel-compatible smart LED interface implemented when 1 (via IO_NEOLED_EN generic) */ |
SYSINFO_SOC_IO_XIRQ = 28, /**< SYSINFO_FEATURES (28) (r/-): External interrupt controller implemented when 1 (via XIRQ_NUM_IO generic) */ |
SYSINFO_SOC_IO_GPTMR = 29 /**< SYSINFO_FEATURES (29) (r/-): General purpose timer implemented when 1 (via IO_GPTMR_EN generic) */ |
SYSINFO_SOC_IO_GPTMR = 29, /**< SYSINFO_FEATURES (29) (r/-): General purpose timer implemented when 1 (via IO_GPTMR_EN generic) */ |
SYSINFO_SOC_IO_XIP = 30 /**< SYSINFO_FEATURES (30) (r/-): Execute in place module implemented when 1 (via IO_XIP_EN generic) */ |
}; |
|
/** NEORV32_SYSINFO.CACHE (r/-): Cache configuration */ |
1302,6 → 1346,7
#include "neorv32_twi.h" |
#include "neorv32_uart.h" |
#include "neorv32_wdt.h" |
#include "neorv32_xip.h" |
#include "neorv32_xirq.h" |
|
#ifdef __cplusplus |
/include/neorv32_spi.h
3,7 → 3,7
// # ********************************************************************************************* # |
// # BSD 3-Clause License # |
// # # |
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. # |
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. # |
// # # |
// # Redistribution and use in source and binary forms, with or without modification, are # |
// # permitted provided that the following conditions are met: # |
49,6 → 49,8
void neorv32_spi_setup(uint8_t prsc, uint8_t clk_phase, uint8_t clk_polarity, uint8_t data_size); |
void neorv32_spi_disable(void); |
void neorv32_spi_enable(void); |
void neorv32_spi_highspeed_enable(void); |
void neorv32_spi_highspeed_disable(void); |
void neorv32_spi_cs_en(uint8_t cs); |
void neorv32_spi_cs_dis(uint8_t cs); |
uint32_t neorv32_spi_trans(uint32_t tx_data); |
/include/neorv32_xip.h
0,0 → 1,55
// ################################################################################################# |
// # << NEORV32: neorv32_xip.h - Execute In Place (XIP) Module HW Driver (Header) >> # |
// # ********************************************************************************************* # |
// # BSD 3-Clause License # |
// # # |
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. # |
// # # |
// # Redistribution and use in source and binary forms, with or without modification, are # |
// # permitted provided that the following conditions are met: # |
// # # |
// # 1. Redistributions of source code must retain the above copyright notice, this list of # |
// # conditions and the following disclaimer. # |
// # # |
// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of # |
// # conditions and the following disclaimer in the documentation and/or other materials # |
// # provided with the distribution. # |
// # # |
// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to # |
// # endorse or promote products derived from this software without specific prior written # |
// # permission. # |
// # # |
// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS # |
// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # |
// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # |
// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # |
// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # |
// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # |
// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # |
// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # |
// # OF THE POSSIBILITY OF SUCH DAMAGE. # |
// # ********************************************************************************************* # |
// # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting # |
// ################################################################################################# |
|
|
/**********************************************************************//** |
* @file neorv32_xip.h |
* @author Stephan Nolting |
* @brief Execute in place module (XIP) HW driver header file. |
* |
* @note These functions should only be used if the XIP module was synthesized (IO_XIP_EN = true). |
**************************************************************************/ |
|
#ifndef neorv32_xip_h |
#define neorv32_xip_h |
|
// prototypes |
int neorv32_xip_available(void); |
int neorv32_xip_init(uint8_t prsc, uint8_t cpol, uint8_t cpha, uint8_t rd_cmd); |
int neorv32_xip_start(uint8_t abytes, uint32_t page_base); |
void neorv32_xip_highspeed_enable(void); |
void neorv32_xip_highspeed_disable(void); |
int neorv32_xip_spi_trans(uint8_t nbytes, uint64_t *rtx_data); |
|
#endif // neorv32_xip_h |
/source/neorv32_rte.c
3,7 → 3,7
// # ********************************************************************************************* # |
// # BSD 3-Clause License # |
// # # |
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. # |
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. # |
// # # |
// # Redistribution and use in source and binary forms, with or without modification, are # |
// # permitted provided that the following conditions are met: # |
272,7 → 272,7
// additional info |
neorv32_uart0_print(", MTVAL="); |
__neorv32_rte_print_hex_word(neorv32_cpu_csr_read(CSR_MTVAL)); |
neorv32_uart0_print(" </RTE>"); |
neorv32_uart0_print(" </RTE>\n"); |
} |
|
|
479,6 → 479,7
__neorv32_rte_print_checkbox(tmp & (1 << SYSINFO_SOC_IO_NEOLED)); neorv32_uart0_printf(" NEOLED\n"); |
__neorv32_rte_print_checkbox(tmp & (1 << SYSINFO_SOC_IO_XIRQ)); neorv32_uart0_printf(" XIRQ\n"); |
__neorv32_rte_print_checkbox(tmp & (1 << SYSINFO_SOC_IO_GPTMR)); neorv32_uart0_printf(" GPTMR\n"); |
__neorv32_rte_print_checkbox(tmp & (1 << SYSINFO_SOC_IO_XIP)); neorv32_uart0_printf(" XIP\n"); |
} |
|
|
/source/neorv32_spi.c
3,7 → 3,7
// # ********************************************************************************************* # |
// # BSD 3-Clause License # |
// # # |
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. # |
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. # |
// # # |
// # Redistribution and use in source and binary forms, with or without modification, are # |
// # permitted provided that the following conditions are met: # |
111,6 → 111,28
|
|
/**********************************************************************//** |
* Enable high-speed SPI mode (running at half of the processor clock). |
* |
* @note High-speed SPI mode ignores the programmed clock prescaler configuration. |
**************************************************************************/ |
void neorv32_spi_highspeed_enable(void) { |
|
NEORV32_SPI.CTRL |= 1 << SPI_CTRL_HIGHSPEED; |
} |
|
|
/**********************************************************************//** |
* Disable high-speed SPI mode. |
* |
* @note High-speed SPI mode ignores the programmed clock prescaler configuration. |
**************************************************************************/ |
void neorv32_spi_highspeed_disable(void) { |
|
NEORV32_SPI.CTRL &= ~(1 << SPI_CTRL_HIGHSPEED); |
} |
|
|
/**********************************************************************//** |
* Activate SPI chip select signal. |
* |
* @note The chip select output lines are LOW when activated. |
/source/neorv32_xip.c
0,0 → 1,216
// ################################################################################################# |
// # << NEORV32: neorv32_xip.c - Execute In Place (XIP) Module HW Driver (Source) >> # |
// # ********************************************************************************************* # |
// # BSD 3-Clause License # |
// # # |
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. # |
// # # |
// # Redistribution and use in source and binary forms, with or without modification, are # |
// # permitted provided that the following conditions are met: # |
// # # |
// # 1. Redistributions of source code must retain the above copyright notice, this list of # |
// # conditions and the following disclaimer. # |
// # # |
// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of # |
// # conditions and the following disclaimer in the documentation and/or other materials # |
// # provided with the distribution. # |
// # # |
// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to # |
// # endorse or promote products derived from this software without specific prior written # |
// # permission. # |
// # # |
// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS # |
// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # |
// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # |
// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # |
// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # |
// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # |
// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # |
// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # |
// # OF THE POSSIBILITY OF SUCH DAMAGE. # |
// # ********************************************************************************************* # |
// # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting # |
// ################################################################################################# |
|
|
/**********************************************************************//** |
* @file neorv32_xip.c |
* @author Stephan Nolting |
* @brief Execute in place module (XIP) HW driver source file. |
* |
* @note These functions should only be used if the XIP module was synthesized (IO_XIP_EN = true). |
**************************************************************************/ |
|
#include "neorv32.h" |
#include "neorv32_xip.h" |
|
|
/**********************************************************************//** |
* Check if XIP module was synthesized. |
* |
* @return 0 if XIP was not synthesized, 1 if XIP is available. |
**************************************************************************/ |
int neorv32_xip_available(void) { |
|
if (NEORV32_SYSINFO.SOC & (1 << SYSINFO_SOC_IO_XIP)) { |
return 1; |
} |
else { |
return 0; |
} |
} |
|
|
/**********************************************************************//** |
* Configure XIP module: configure SPI properties. |
* |
* @warning This will reset the XIP module overriding the CTRL register. |
* @note This function will also send 64 dummy clocks via the SPI port (with chip-select disabled). |
* |
* @param[in] prsc SPI clock prescaler select (0..7). |
* @param[in] cpol SPI clock polarity (0/1). |
* @param[in] cpha SPI clock phase(0/1). |
* @param[in] rd_cmd SPI flash read command. |
* @return 0 if configuration is OK, 1 if configuration error. |
**************************************************************************/ |
int neorv32_xip_init(uint8_t prsc, uint8_t cpol, uint8_t cpha, uint8_t rd_cmd) { |
|
// configuration check |
if ((prsc > 7) || (cpol > 1) || (cpha > 1)) { |
return 1; |
} |
|
// reset module |
NEORV32_XIP.CTRL = 0; |
|
uint32_t ctrl = 0; |
|
ctrl |= ((uint32_t)(1 )) << XIP_CTRL_EN; // enable module |
ctrl |= ((uint32_t)(prsc & 0x07)) << XIP_CTRL_PRSC0; |
ctrl |= ((uint32_t)(cpol & 0x01)) << XIP_CTRL_CPOL; |
ctrl |= ((uint32_t)(cpha & 0x01)) << XIP_CTRL_CPHA; |
ctrl |= ((uint32_t)(8 )) << XIP_CTRL_SPI_NBYTES_LSB; // set 8 bytes transfer size as default |
ctrl |= ((uint32_t)(rd_cmd & 0xff)) << XIP_CTRL_RD_CMD_LSB; |
|
NEORV32_XIP.CTRL = ctrl; |
|
// send 64 dummy clocks |
NEORV32_XIP.DATA_LO = 0; |
NEORV32_XIP.DATA_HI = 0; // trigger SPI transfer |
|
// wait for transfer to complete |
while(NEORV32_XIP.CTRL & (1 << XIP_CTRL_PHY_BUSY)); |
|
NEORV32_XIP.CTRL |= 1 << XIP_CTRL_SPI_CSEN; // finally enable SPI chip-select |
|
return 0; |
} |
|
|
/**********************************************************************//** |
* Enable XIP mode (to allow CPU to _transparently_ fetch instructions). |
* |
* @warning This function is blocking until the XIP mode is ready. |
* |
* @param[in] abytes Number of address bytes used to access the SPI flash (1,2,3,4). |
* @param[in] page_base XIP memory page base address (top 4 address bits, 0..15). |
* @return 0 if XIP configuration is OK, 1 if configuration error. |
**************************************************************************/ |
int neorv32_xip_start(uint8_t abytes, uint32_t page_base) { |
|
if ((abytes < 1) || (abytes > 4)) { |
return 1; |
} |
|
if (page_base & 0x0FFFFFFF) { |
return 1; |
} |
page_base >>= 28; |
|
|
uint32_t ctrl = NEORV32_XIP.CTRL; |
|
// address bytes send to SPI flash |
ctrl &= ~(3 << XIP_CTRL_XIP_ABYTES_LSB); // clear old configuration |
ctrl |= ((uint32_t)(abytes-1)) << XIP_CTRL_XIP_ABYTES_LSB; // set new configuration |
|
// total number of bytes to transfer via SPI |
// 'abytes' address bytes + 1 command byte + 4 bytes RX data (one 32-bit word) |
ctrl &= ~(0xF << XIP_CTRL_SPI_NBYTES_LSB); // clear old configuration |
ctrl |= ((uint32_t)(abytes+1+4)) << XIP_CTRL_SPI_NBYTES_LSB; // set new configuration |
|
// XIP memory page |
ctrl &= ~(0xF << XIP_CTRL_PAGE_LSB); // clear old configuration |
ctrl |= ((uint32_t)(page_base & 0xf)) << XIP_CTRL_PAGE_LSB; // set new configuration |
|
ctrl |= 1 << XIP_CTRL_XIP_EN; // enable XIP mode |
|
NEORV32_XIP.CTRL = ctrl; |
|
return 0; |
} |
|
|
/**********************************************************************//** |
* Enable high-speed SPI mode (running at half of the processor clock). |
* |
* @note High-speed SPI mode ignores the programmed clock prescaler configuration. |
**************************************************************************/ |
void neorv32_xip_highspeed_enable(void) { |
|
NEORV32_XIP.CTRL |= 1 << XIP_CTRL_HIGHSPEED; |
} |
|
|
/**********************************************************************//** |
* Disable high-speed SPI mode. |
* |
* @note High-speed SPI mode ignores the programmed clock prescaler configuration. |
**************************************************************************/ |
void neorv32_xip_highspeed_disable(void) { |
|
NEORV32_XIP.CTRL &= ~(1 << XIP_CTRL_HIGHSPEED); |
} |
|
|
/**********************************************************************//** |
* Direct SPI access to the XIP flash. |
* |
* @warning This function can only be used BEFORE the XIP-mode is activated! |
* @note This function is blocking. |
* |
* @param[in] nbytes Number of bytes to transfer (1..8). |
* @param[in,out] rtx_data Pointer to 64-bit TX/RX data (MSB-aligned for sending, LSB-aligned for receiving (only 32-bit)). |
* @return 0 if valid transfer, 1 if transfer configuration error. |
**************************************************************************/ |
int neorv32_xip_spi_trans(uint8_t nbytes, uint64_t *rtx_data) { |
|
if ((nbytes == 0) || (nbytes > 8)) { |
return 1; |
} |
|
// configure number of bytes to transfer |
uint32_t ctrl = NEORV32_XIP.CTRL; |
ctrl &= ~(0xF << XIP_CTRL_SPI_NBYTES_LSB); // clear old configuration |
ctrl |= nbytes << XIP_CTRL_SPI_NBYTES_LSB; // set new configuration |
NEORV32_XIP.CTRL = ctrl; |
|
union { |
uint64_t uint64; |
uint32_t uint32[sizeof(uint64_t)/2]; |
} data; |
|
data.uint64 = *rtx_data; |
NEORV32_XIP.DATA_LO = data.uint32[0]; |
NEORV32_XIP.DATA_HI = data.uint32[1]; // trigger SPI transfer |
|
// wait for transfer to complete |
while(NEORV32_XIP.CTRL & (1 << XIP_CTRL_PHY_BUSY)); |
|
data.uint32[0] = NEORV32_XIP.DATA_LO; |
data.uint32[1] = 0; // RX data is always 32-bit |
*rtx_data = data.uint64; |
|
return 0; |
} |
|