@@ -2,12 +2,12 @@ use crate::svd::{array::names, Device, Peripheral};
22use proc_macro2:: { Span , TokenStream } ;
33use quote:: { quote, ToTokens } ;
44
5- use log:: debug;
5+ use log:: { debug, warn } ;
66use std:: fs:: File ;
77use std:: io:: Write ;
88use std:: path:: Path ;
99
10- use crate :: config:: { Config , Settings , Target } ;
10+ use crate :: config:: { Config , Target } ;
1111use crate :: util:: { self , ident} ;
1212use anyhow:: { Context , Result } ;
1313
@@ -31,9 +31,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
3131 let settings = match config. settings . as_ref ( ) {
3232 Some ( settings) => {
3333 let file = std:: fs:: read_to_string ( settings) . context ( "could not read settings file" ) ?;
34- serde_yaml:: from_str ( & file) . context ( "could not parse settings file" ) ?
34+ Some ( serde_yaml:: from_str ( & file) . context ( "could not parse settings file" ) ?)
3535 }
36- None => Settings :: default ( ) ,
36+ None => None ,
3737 } ;
3838
3939 if config. target == Target :: Msp430 {
@@ -197,8 +197,23 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
197197
198198 match config. target {
199199 Target :: RISCV => {
200- debug ! ( "Rendering RISC-V specific code" ) ;
201- out. extend ( riscv:: render ( & d. peripherals , device_x, & settings) ?) ;
200+ if settings. is_none ( ) {
201+ warn ! ( "No settings file provided for RISC-V target. Using legacy interrupts rendering" ) ;
202+ warn ! ( "Please, consider migrating your PAC to riscv 0.12.0 or later" ) ;
203+ out. extend ( interrupt:: render (
204+ config. target ,
205+ & d. peripherals ,
206+ device_x,
207+ config,
208+ ) ?) ;
209+ } else {
210+ debug ! ( "Rendering RISC-V specific code" ) ;
211+ out. extend ( riscv:: render (
212+ & d. peripherals ,
213+ device_x,
214+ settings. as_ref ( ) . unwrap ( ) ,
215+ ) ?) ;
216+ }
202217 }
203218 _ => {
204219 debug ! ( "Rendering interrupts" ) ;
@@ -219,7 +234,10 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
219234 // Core peripherals are handled above
220235 continue ;
221236 }
222- if config. target == Target :: RISCV && riscv:: is_riscv_peripheral ( p, & settings) {
237+ if config. target == Target :: RISCV
238+ && settings. is_some ( )
239+ && riscv:: is_riscv_peripheral ( p, settings. as_ref ( ) . unwrap ( ) )
240+ {
223241 // RISC-V specific peripherals are handled above
224242 continue ;
225243 }
0 commit comments