|
149 | 149 | //! The resulting crate must provide an opt-in `rt` feature and depend on these crates: |
150 | 150 | //! |
151 | 151 | //! - [`critical-section`](https://crates.io/crates/critical-section) v1.x |
152 | | -//! - [`riscv`](https://crates.io/crates/riscv) v0.12.x (if target is RISC-V) |
153 | | -//! - [`riscv-peripheral`](https://crates.io/crates/riscv-peripheral) v0.2.x (if target is RISC-V and has standard peripherals) |
154 | | -//! - [`riscv-rt`](https://crates.io/crates/riscv-rt) v0.13.x (if target is RISC-V) |
| 152 | +//! - [`riscv`](https://crates.io/crates/riscv) v0.16.x (if target is RISC-V) |
| 153 | +//! - [`riscv-peripheral`](https://crates.io/crates/riscv-peripheral) v0.5.x (if target is RISC-V and has standard peripherals) |
| 154 | +//! - [`riscv-rt`](https://crates.io/crates/riscv-rt) v0.18.x (if target is RISC-V) |
155 | 155 | //! - [`vcell`](https://crates.io/crates/vcell) v0.1.x |
156 | 156 | //! |
157 | 157 | //! The `*-rt` dependencies must be optional only enabled when the `rt` feature is enabled. |
|
160 | 160 | //! |
161 | 161 | //! ``` toml |
162 | 162 | //! [dependencies] |
163 | | -//! critical-section = { version = "1.0", optional = true } |
164 | | -//! riscv = "0.12.1" |
165 | | -//! riscv-peripheral = "0.2.0" |
166 | | -//! riscv-rt = { version = "0.13.0", optional = true } |
| 163 | +//! critical-section = { version = "1.2", optional = true } |
| 164 | +//! riscv = "0.16.1" |
| 165 | +//! riscv-peripheral = "0.5.1" |
| 166 | +//! riscv-rt = { version = "0.18.0", optional = true } |
167 | 167 | //! vcell = "0.1.0" |
168 | 168 | //! |
169 | 169 | //! [features] |
170 | 170 | //! rt = ["riscv-rt"] |
171 | 171 | //! v-trap = ["rt", "riscv-rt/v-trap"] |
172 | 172 | //! ``` |
173 | 173 | //! |
| 174 | +//! ## RISC-V specific settings |
| 175 | +//! |
| 176 | +//! When targeting the RISC-V architecture, `svd2rust` will expect also a settings file in YAML format to be passed with the `--settings` flag. |
| 177 | +//! This file is used to specify RISC-V specific settings that are not present in the SVD file. The command to generate the crate will look like this: |
| 178 | +//! |
| 179 | +//! ```text |
| 180 | +//! $ svd2rust -g --target riscv --settings my_device.yaml -i my_device.svd |
| 181 | +//! ``` |
| 182 | +//! |
| 183 | +//! This settings file expects the following fields: |
| 184 | +//! |
| 185 | +//! - `base_isa` (mandatory): The base RISC-V ISA of the target. Accepted values are `"rv32i"`, `"rv32e"`, `"rv64i"`, and `"rv64e"`. |
| 186 | +//! This is required for right generation of the `riscv-rt` trap handlers. |
| 187 | +//! |
| 188 | +//! - `mtvec_align` (mandatory for vectored mode): The alignment of the machine trap vector table (only needed if the target supports vectored mode). |
| 189 | +//! This determines the byte alignment of the interrupt vector and thus the value of the `mtvec` register. |
| 190 | +//! |
| 191 | +//! - `harts` (mandatory): The list of HARTs of the target. This is used to generate HART enums that implement the `riscv::HartId` trait. |
| 192 | +//! Each HART is specified with the following fields: |
| 193 | +//! - `name`: The name of the HART. This is used to generate the name of the HART enum variants. |
| 194 | +//! - `value`: The value of the HART ID. This is used to implement the `riscv::HartId` trait for the HART enum variants. |
| 195 | +//! - `description`: An optional description of the HART. This is used to generate documentation for the HART enum variants. |
| 196 | +//! |
| 197 | +//! - `core_interrupts` (optional): The list of core interrupts of the target. This is used to generate core interrupt enums that implement the `riscv::CoreInterrupt` trait. |
| 198 | +//! It also determines the core interrupt handlers generated in `riscv-rt` if the `rt` feature is enabled. |
| 199 | +//! In contrast to external interrupts, core interrupts are not included in the SVD file because they are not device specific but rather architecture specific. |
| 200 | +//! If not specified, the generated crate will use the standard core interrupts defined in `riscv::interrupt::Interrupt` |
| 201 | +//! Each core interrupt is specified with the following fields: |
| 202 | +//! - `name`: The name of the core interrupt. This is used to generate the name of the core interrupt enum variants. |
| 203 | +//! - `value`: The value of the core interrupt ID. This is used to implement the `riscv::CoreInterrupt` trait for the core interrupt enum variants. |
| 204 | +//! - `description`: An optional description of the core interrupt. This is used to generate documentation for the core interrupt enum variants. |
| 205 | +//! |
| 206 | +//! - `exceptions` (optional): The list of exceptions of the target. This is used to generate exception enums that implement the `riscv::Exception` trait. |
| 207 | +//! Like core interrupts, exceptions are not included in the SVD file because they are not device specific but rather architecture specific. |
| 208 | +//! If not specified, the generated crate will use the standard exceptions defined in `riscv::interrupt::Exception`. |
| 209 | +//! Each exception is specified with the following fields: |
| 210 | +//! - `name`: The name of the exception. This is used to generate the name of the exception enum variants. |
| 211 | +//! - `value`: The value of the exception ID. This is used to implement the `riscv::Exception` trait for the exception enum variants. |
| 212 | +//! - `description`: An optional description of the exception. This is used to generate documentation for the exception enum variants. |
| 213 | +//! |
| 214 | +//! - `priorities` (optional): The list of external interrupt priorities of the target. This is used to generate priority enums that implement the `riscv::Priority` trait. |
| 215 | +//! These are mandartory if you want to use the PLIC peripheral API provided by `riscv-peripheral`. |
| 216 | +//! Each priority is specified with the following fields: |
| 217 | +//! - `name`: The name of the priority. This is used to generate the name of the priority enum variants. |
| 218 | +//! - `value`: The value of the priority. This is used to implement the `riscv::Priority` trait for the priority enum variants. |
| 219 | +//! - `description`: An optional description of the priority. This is used to generate documentation for the priority enum variants. |
| 220 | +//! |
| 221 | +//! - `clint` (optional): The configuration of the CLINT peripheral, if the target has one. |
| 222 | +//! This is used to generate a standard CLINT API using the `riscv-peripheral` crate. |
| 223 | +//! The CLINT configuration expects the following fields: |
| 224 | +//! - `name`: The name of the CLINT peripheral as it appears in the SVD file. |
| 225 | +//! - `pub_new`: Optional boolean field that specifies whether the `new` method of the CLINT API should be public. Default is `false`. |
| 226 | +//! - `mtime_freq`: The frequency of the `mtime` register in Hz. If you target has a known fixed frecuency, you can specify it here |
| 227 | +//! to use a default implementation of `embedded_hal::Delay` trait for the CLINT API. |
| 228 | +//! |
| 229 | +//! - `plic`: The configuration of the PLIC peripheral if the target has one. |
| 230 | +//! This is used to generate a standard PLIC API using the `riscv-peripheral` crate. |
| 231 | +//! The PLIC configuration expects the following fields: |
| 232 | +//! - `name`: The name of the PLIC peripheral as it appears in the SVD file. |
| 233 | +//! - `pub_new`: Optional boolean field that specifies whether the `new` method of the PLIC API should be public. Default is `false`. |
| 234 | +//! - `core_interrupt`: ID of the core interrupt corresponding to external hardware interrupts managed by the PLIC. |
| 235 | +//! This is used to generate the correct interrupt handler for the PLIC in `riscv-rt`. |
| 236 | +//! - `hart_id` (optional): ID of the HART in charge of managing the external hardware interrupts. |
| 237 | +//! This is used to generate the correct interrupt handler for the PLIC in `riscv-rt`. |
| 238 | +//! If not specified, it will use the `mhartid` register to determine the HART ID at runtime and generate a generic interrupt handler for the PLIC that works for all HARTs. |
| 239 | +//! |
| 240 | +//! A settings file will look like this: |
| 241 | +//! |
| 242 | +//! ```yaml |
| 243 | +//! riscv_config: |
| 244 | +//! base_isa: "rv32i" |
| 245 | +//! mtvec_align: 64 |
| 246 | +//! harts: |
| 247 | +//! - name: "H0" |
| 248 | +//! value: 0 |
| 249 | +//! description: "HART 0" |
| 250 | +//! core_interrupts: |
| 251 | +//! - name: "MachineSoft" |
| 252 | +//! value: 3 |
| 253 | +//! description: "Machine software interrupt" |
| 254 | +//! - name: "MachineTimer" |
| 255 | +//! value: 7 |
| 256 | +//! description: "Machine timer interrupt" |
| 257 | +//! - name: "MachineExternal" |
| 258 | +//! value: 11 |
| 259 | +//! description: "Machine external interrupt" |
| 260 | +//! priorities: |
| 261 | +//! - name: "P0" |
| 262 | +//! value: 0 |
| 263 | +//! description: "Priority level 0" |
| 264 | +//! - name: "P1" |
| 265 | +//! value: 1 |
| 266 | +//! description: "Priority level 1" |
| 267 | +//! - name: "P2" |
| 268 | +//! value: 2 |
| 269 | +//! description: "Priority level 2" |
| 270 | +//! - name: "P3" |
| 271 | +//! value: 3 |
| 272 | +//! description: "Priority level 3" |
| 273 | +//! clint: |
| 274 | +//! - name: "CLINT" |
| 275 | +//! pub_new: true |
| 276 | +//! mtime_freq: 1000000 |
| 277 | +//! plic: |
| 278 | +//! - name: "PLIC" |
| 279 | +//! pub_new: true |
| 280 | +//! core_interrupt: "MachineExternal" |
| 281 | +//! ``` |
| 282 | +//! |
174 | 283 | //! ## Rust editions |
175 | 284 | //! |
176 | 285 | //! Default rust edition for generated code is 2021. Pass `--edition=2024` if you want to |
|
0 commit comments