OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [docs/] [datasheet/] [soc_xip.adoc] - Blame information for rev 72

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 70 zero_gravi
<<<
2
:sectnums:
3
==== Execute In Place Module (XIP)
4
 
5
[cols="<3,<3,<4"]
6
[frame="topbot",grid="none"]
7
|=======================
8
| Hardware source file(s): | neorv32_xip.vhd |
9
| Software driver file(s): | neorv32_xip.c |
10
|                          | neorv32_xip.h |
11
| Top entity port:         | `xip_csn_o` | 1-bit chip select, low-active
12
|                          | `xip_clk_o` | 1-bit serial clock output
13
|                          | `xip_sdi_i` | 1-bit serial data input
14
|                          | `xip_sdo_o` | 1-bit serial data output
15
| Configuration generics:  | _IO_XIP_EN_ | implement XIP module when _true_
16
| CPU interrupts:          | none |
17
|=======================
18
 
19
 
20
**Overview**
21
 
22
The execute in place (XIP) module is probably one of the more complicated modules of the NEORV32. The module
23
allows to execute code (and read constant data) directly from a SPI flash memory. Hence, it uses the standard
24
serial peripheral interface (SPI) as transfer protocol under the hood.
25
 
26
The XIP flash is not mapped to a specific region of the processor's address space. Instead, the XIP module
27
provides a programmable mapping scheme to allow a flexible user-defined mapping of the flash to _any section_
28
of the address space.
29
 
30
From the CPU side, the modules provides two different interfaces: one for transparently accessing the XIP flash and another
31
one for accessing the module's control and status registers. The first interface provides a _transparent_
32
gateway to the SPI flash, so the CPU can directly fetch and execute instructions (and/or read constant _data_).
33
Note that this interface is read-only. Any write access will raise a bus error exception.
34
The second interface is mapped to the processor's IO space and allows data accesses to the XIP module's
35
configuration registers.
36
 
37
[TIP]
38
An example program for the XIP module is available in `sw/example/demo_xip`.
39
 
40
[NOTE]
41
Quad-SPI (QSPI) support, which is about 4x times faster, is planned for the future. 😉
42
 
43
 
44
**SPI Protocol**
45
 
46
The XIP module accesses external flash using the standard SPI protocol. The module always sends data MSB-first and
47
provides all of the standard four clock modes (0..3), which are configured via the _XIP_CTRL_CPOL_ (clock polarity)
48
and _XIP_CTRL_CPHA_ (clock phase) control register bits, respectively. The clock speed of the interface (`xip_clk_o`)
49
is defined by a three-bit clock pre-scaler configured using the _XIP_CTRL_PRSCx_ bits:
50
 
51
.XIP prescaler configuration
52
[cols="<4,^1,^1,^1,^1,^1,^1,^1,^1"]
53
[options="header",grid="rows"]
54
|=======================
55
| **`XIP_CTRL_PRSCx`**        | `0b000` | `0b001` | `0b010` | `0b011` | `0b100` | `0b101` | `0b110` | `0b111`
56
| Resulting `clock_prescaler` |       2 |       4 |       8 |      64 |     128 |    1024 |    2048 |    4096
57
|=======================
58
 
59
Based on the _XIP_CTRL_PRSCx_ configuration the actual XIP SPI clock frequency f~XIP~ is derived from the processor's
60
main clock f~main~ and is determined by:
61
 
62
_**f~XIP~**_ = _f~main~[Hz]_ / (2 * `clock_prescaler`)
63
 
64
Hence, the maximum XIP clock speed is f~main~ / 4.
65
 
66
.High-Speed SPI mode
67
[TIP]
68
The module provides a "high-speed" SPI mode. In this mode the clock prescaler configuration (_XIP_CTRL_PRSCx_) is ignored
69
and the SPI clock operates at f~main~ / 2 (half of the processor's main clock). High speed SPI mode is enabled by setting
70
the control register's _XIP_CTRL_HIGHSPEED_ bit.
71
 
72
The flash's "read command", which initiates a read access, is defined by the _XIP_CTRL_RD_CMD_ control register bits.
73
For most SPI flash memories this is `0x03` for normal SPI mode.
74
 
75
 
76
**Direct SPI Access**
77
 
78
The XIP module allows to initiate _direct_ SPI transactions. This feature can be used to configure the attached SPI
79
flash or to perform direct read and write accesses to the flash memory. Two data registers `NEORV32_XIP.DATA_LO` and
80
`NEORV32_XIP.DATA_HI` are provided to send up to 64-bit of SPI data. The `NEORV32_XIP.DATA_HI` register is write-only,
81
so a total of 32-bit receive data is provided. Note that the module handles the chip-select
82
line (`xip_csn_o`) by itself so it is not possible to construct larger consecutive transfers.
83
 
84
The actual data transmission size in bytes is defined by the control register's _XIP_CTRL_SPI_NBYTES_ bits.
85
Any configuration from 1 byte to 8 bytes is valid. Other value will result in unpredictable behavior.
86
 
87
Since data is always transferred MSB-first, the data in `DATA_HI:DATA_LO` also has to be MSB-aligned. Receive data is
88
available in `DATA_LO` only - `DATA_HI` is write-only. Writing to `DATA_HI` triggers the actual SPI transmission.
89
The _XIP_CTRL_PHY_BUSY_ control register flag indicates a transmission being in progress.
90
 
91
The chip-select line of the XIP module (`xip_csn_o`) will only become asserted (enabled, pulled low) if the
92
_XIP_CTRL_SPI_CSEN_ control register bit is set. If this bit is cleared, `xip_csn_o` is always disabled
93
(pulled high).
94
 
95
[NOTE]
96
Direct SPI mode is only possible when the module is enabled (setting _XIP_CTRL_EN_) but **before** the actual
97
XIP mode is enabled via _XIP_CTRL_XIP_EN_.
98
 
99
[TIP]
100
When the XIP mode is not enabled, the XIP module can also be used as additional general purpose SPI controller
101
with a transfer size of up to 64 bits per transmission.
102
 
103
 
104
**Address Mapping**
105
 
106
The address mapping of the XIP flash is not fixed by design. It can be mapped to _any section_ within the processor's
107
address space. A _section_ refers to one out of 16 naturally aligned 256MB wide memory segments. This segment
108
is defined by the four most significant bits of the address (`31:28`) and the XIP's segment is programmed by the
109
four _XIP_CTRL_XIP_PAGE_ bits in the unit's control register. All accesses within this page will be mapped to the XIP flash.
110
 
111
[NOTE]
112
Care must be taken when programming the page mapping to prevent access collisions with other modules (like internal memories
113
or modules attached to the external memory interface).
114
 
115
Example: to map the XIP flash to the address space starting at `0x20000000` write a "2" (`0b0010`) to the _XIP_CTRL_XIP_PAGE_
116
control register bits. Any access within `0x20000000 .. 0x2fffffff` will be forwarded to the XIP flash.
117
Note that the SPI access address might wrap around.
118
 
119 72 zero_gravi
.Using the FPGA Bitstream Flash also for XIP
120
[TIP]
121
You can also use the FPGA's bitstream SPI flash for storing XIP programs. To prevent overriding the bitstream,
122
a certain offset needs to be added to the executable (which might require linker script modifications).
123
To execute the program stored in the SPI flash simply jump to the according base address. For example
124
if the executable starts at flash offset `0x8000` and the XIP flash is mapped to the base address `0x20000000`
125
then add the offset to the base address and use that as jump/call destination (=`0x20008000`).
126 70 zero_gravi
 
127 72 zero_gravi
 
128 70 zero_gravi
**Using the XIP Mode**
129
 
130
The XIP module is globally enabled by setting the _XIP_CTRL_EN_ bit in the device's `CTRL` control register.
131
Clearing this bit will reset the whole module and will also terminate any pending SPI transfer.
132
 
133
Since there is a wide variety of SPI flash components with different sizes, the XIP module allows to specify
134
the address width of the flash: the number of address bytes used for addressing flash memory content has to be
135
configured using the control register's _XIP_CTRL_XIP_ABYTES_ bits. These two bits contain the number of SPI
136
address bytes (**minus one**). For example for a SPI flash with 24-bit addresses these bits have to be set to
137
`0b10`.
138
 
139
The transparent XIP accesses are transformed into SPI transmissions with the following format (starting with the MSB):
140
 
141
* 8-bit command: configured by the _XIP_CTRL_RD_CMD_ control register bits ("SPI read command")
142
* 8 to 32 bits address: defined by the _XIP_CTRL_XIP_ABYTES_ control register bits ("number of address bytes")
143
* 32-bit data: sending zeros and receiving the according flash word (32-bit)
144
 
145
Hence, the maximum XIP transmission size is 72-bit, which has to be configured via the _XIP_CTRL_SPI_NBYTES_
146
control register bits. Note that the 72-bit transmission size is only available in XIP mode. The transmission
147
size of the direct SPI accesses is limited to 64-bit.
148
 
149
[NOTE]
150
There is no _continuous read_ feature (i.e. a burst SPI transmission fetching several data words at once) implemented yet.
151
 
152
[NOTE]
153
When using four SPI flash address bytes, the most significant 4 bits of the address are always hardwired
154
to zero allowing a maximum **accessible** flash size of 256MB.
155
 
156
After the SPI properties (including the amount of address bytes **and** the total amount of SPI transfer bytes)
157
and XIP address mapping are configured, the actual XIP mode can be enabled by setting
158
the control register's _XIP_CTRL_XIP_EN_ bit. This will enable the "transparent SPI access port" of the module and thus,
159
the _transparent_ conversion of access requests into proper SPI flash transmissions. Make sure _XIP_CTRL_SPI_CSEN_
160
is also set so the module can actually select/enable the attached SPI flash.
161
No more direct SPI accesses via `DATA_HI:DATA_LO` are possible when the XIP mode is enabled. However, the
162
XIP mode can be disabled at any time.
163
 
164
[NOTE]
165
If the XIP module is disabled (_XIP_CTRL_EN_ = `0`) any accesses to the programmed XIP memory segment are ignored
166
by the module and might be forwarded to the processor's external memory interface (if implemented) or will cause a bus
167
exception. If the XIP module is enabled (_XIP_CTRL_EN_ = `1`) but XIP mode is not enabled yet (_XIP_CTRL_XIP_EN_ = '0')
168
any access to the programmed XIP memory segment will raise a bus exception.
169
 
170
[TIP]
171
It is highly recommended to enable the <<_processor_internal_instruction_cache_icache>> to cover some
172
of the SPI access latency.
173
 
174
 
175
.XIP register map (`struct NEORV32_XIP`)
176
[cols="<2,<2,<4,^1,<7"]
177
[options="header",grid="all"]
178
|=======================
179
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
180
.16+<| `0xffffff40` .16+<| `NEORV32_XIP.CTRL` <|`0`  _XIP_CTRL_EN_    ^| r/w <| XIP module enable
181
                                              <|`1`  _XIP_CTRL_PRSC0_ ^| r/w .3+| 3-bit SPI clock prescaler select
182
                                              <|`2`  _XIP_CTRL_PRSC1_ ^| r/w
183
                                              <|`3`  _XIP_CTRL_PRSC2_ ^| r/w
184
                                              <|`4`  _XIP_CTRL_CPOL_  ^| r/w <| SPI clock polarity
185
                                              <|`5`  _XIP_CTRL_CPHA_  ^| r/w <| SPI clock phase
186
                                              <|`9:6`  _XIP_CTRL_SPI_NBYTES_MSB_ : _XIP_CTRL_SPI_NBYTES_LSB_ ^| r/w <| Number of bytes in SPI transaction (1..9)
187
                                              <|`10` _XIP_CTRL_XIP_EN_ ^| r/w <| XIP mode enable
188
                                              <|`12:11` _XIP_CTRL_XIP_ABYTES_MSB_ : _XIP_CTRL_XIP_ABYTES_LSB_ ^| r/w <| Number of address bytes for XIP flash (minus 1)
189
                                              <|`20:13` _XIP_CTRL_RD_CMD_MSB_ : _XIP_CTRL_RD_CMD_LSB_ ^| r/w <| Flash read command
190
                                              <|`24:21` _XIP_CTRL_XIP_PAGE_MSB_ : _XIP_CTRL_XIP_PAGE_LSB_ ^| r/w <| XIP memory page
191
                                              <|`25` _XIP_CTRL_SPI_CSEN_  ^| r/w <| Allow SPI chip-select to be actually asserted when set
192
                                              <|`26` _XIP_CTRL_HIGHSPEED_ ^| r/w <| enable SPI high-speed mode (ignoring _XIP_CTRL_PRSC_)
193
                                              <|`29:27`                   ^| r/- <| _reserved_, read as zero
194
                                              <|`30` _XIP_CTRL_PHY_BUSY_  ^| r/- <| SPI PHY busy when set
195
                                              <|`31` _XIP_CTRL_XIP_BUSY_  ^| r/- <| XIP access in progress when set
196
| `0xffffff44` | _reserved_            |`31:0` | r/- | _reserved_, read as zero
197
| `0xffffff48` | `NEORV32_XIP.DATA_LO` |`31:0` | r/w | Direct SPI access - data register low
198
| `0xffffff4C` | `NEORV32_XIP.DATA_HI` |`31:0` | -/w | Direct SPI access - data register high; write access triggers SPI transfer
199
|=======================

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.