Odd (and incorrect) code generation from SVD
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- embedded-iot, tooling
Direzione di ricerca
Riproducete il report con svd2rust 0.37.1 utilizzando l’estratto SVD bcm_aux.svd.jinja collegato, quindi esaminate il PAC generato intorno ai campi CTS_ASSERT e RTS_ASSERT. Tracciate la gestione di derivedFrom per enumeratedValues e verificate che la generazione non emetta più un pub use AssertLevel; duplicato prima dell’enum, preservando le API di lettura e scrittura previste.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I was in the process of updating a project that I am working on to new SVD's and when I generated the PAC I got some strange code. This first block is and excerpt from the relevant part of the SVD. The full thing can be found here:
<field>
<name>CTS_ASSERT</name>
<description>CTS assert level</description>
<bitOffset>7</bitOffset>
<bitWidth>1</bitWidth>
<enumeratedValues>
<name>ASSERT_LEVEL</name>
<enumeratedValue>
<name>HIGH</name>
<description>Assert high</description>
<value>0</value>
</enumeratedValue>
<enumeratedValue>
<name>LOW</name>
<description>Assert low</description>
<value>1</value>
</enumeratedValue>
</enumeratedValues>
</field>
<field>
<name>RTS_ASSERT</name>
<description>RTS assert level</description>
<bitOffset>6</bitOffset>
<bitWidth>1</bitWidth>
<enumeratedValues derivedFrom="UART1.CNTL.CTS_ASSERT.ASSERT_LEVEL"></enumeratedValues>
</field>
Generated code is as follows:
#[doc = "RTS assert level"]
pub use AssertLevel;
#[doc = "Field `RTS_ASSERT` reader - RTS assert level"]
pub use CtsAssertR as RtsAssertR;
#[doc = "Field `RTS_ASSERT` writer - RTS assert level"]
pub use CtsAssertW as RtsAssertW;
#[doc = "CTS assert level\n\nValue on reset: 0"]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AssertLevel {
#[doc = "0: Assert high"]
High = 0,
#[doc = "1: Assert low"]
Low = 1,
}
impl From<AssertLevel> for bool {
#[inline(always)]
fn from(variant: AssertLevel) -> Self {
variant as u8 != 0
}
}
#[doc = "Field `CTS_ASSERT` reader - CTS assert level"]
pub type CtsAssertR = crate::BitReader<AssertLevel>;
impl CtsAssertR {
#[doc = "Get enumerated values variant"]
#[inline(always)]
pub const fn variant(&self) -> AssertLevel {
match self.bits {
false => AssertLevel::High,
true => AssertLevel::Low,
}
}
#[doc = "Assert high"]
#[inline(always)]
pub fn is_high(&self) -> bool {
*self == AssertLevel::High
}
#[doc = "Assert low"]
#[inline(always)]
pub fn is_low(&self) -> bool {
*self == AssertLevel::Low
}
}
#[doc = "Field `CTS_ASSERT` writer - CTS assert level"]
pub type CtsAssertW<'a, REG> = crate::BitWriter<'a, REG, AssertLevel>;
impl<'a, REG> CtsAssertW<'a, REG>
where
REG: crate::Writable + crate::RegisterSpec,
{
#[doc = "Assert high"]
#[inline(always)]
pub fn high(self) -> &'a mut crate::W<REG> {
self.variant(AssertLevel::High)
}
#[doc = "Assert low"]
#[inline(always)]
pub fn low(self) -> &'a mut crate::W<REG> {
self.variant(AssertLevel::Low)
}
}
The error here is that for some reason a pub use AssertLevel; was generated just before pub enum AssertLevel {...}. I am using svd2rust version 0.37.1 and rust version 1.92.0. I am running Ubuntu 24.04.
As to what the actual issue here is I'm not sure. However it is unlikely to be the SVD because that specific file has been the same for years.
Let me know if anymore information is needed.
- Lingua principale
- Rust
- Stelle
- 865
- Fork
- 164
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-embedded/svd2rust
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
rust-embedded/svd2rust#939 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
rust-embedded/svd2rust#938 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
rust-embedded/svd2rust#937 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
rust-embedded/svd2rust#925 · 8 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
rust-embedded/svd2rust#902 · 18 commenti ·
Tutte le issue di rust-embedded/svd2rust
Issue simili
-
A-linter
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
oxc-project/oxc#28783 ·
I maintainer di solito rispondono entro 1 giorno
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yamlApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
apache/datafusion#27059 ·
I maintainer di solito rispondono entro 1 giorno
-
Bump calamine to 0.38: RUSTSEC-2026-0436 (CFB/OLE2 panic and unbounded allocation) fails cargo auditAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
docling-project/docling.rs#979 ·
I maintainer di solito rispondono entro 1 giorno
-
llm translation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno