Odd (and incorrect) code generation from SVD

Aperta
#966 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-embedded/svd2rust

Tutte le issue di rust-embedded/svd2rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.