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

Subversion Repositories neorv32

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

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

powered by: WebSVN 2.1.0

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