From ed21f8f4b26c96080bf10e82afe5cca30cf70bf4 Mon Sep 17 00:00:00 2001 From: gephaistos Date: Tue, 23 Jul 2024 15:11:39 +0300 Subject: [PATCH 1/5] Generate unique id for device peripherals --- src/generate/device.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/generate/device.rs b/src/generate/device.rs index dd601ada..6dcf3d9e 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -1,6 +1,7 @@ use crate::svd::{array::names, Device, Peripheral}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; +use syn::Ident; use log::debug; use std::fs::File; @@ -270,12 +271,24 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Result Option { critical_section::with(|_| { // SAFETY: We are in a critical section, so we have exclusive access - // to `DEVICE_PERIPHERALS`. - if unsafe { DEVICE_PERIPHERALS } { + // to `#taken`. + if unsafe { #taken } { return None } - // SAFETY: `DEVICE_PERIPHERALS` is set to `true` by `Peripherals::steal`, + // SAFETY: `#taken` is set to `true` by `Peripherals::steal`, // ensuring the peripherals can only be returned once. Some(unsafe { Peripherals::steal() }) }) @@ -308,7 +321,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Self { - DEVICE_PERIPHERALS = true; + #taken = true; Peripherals { #exprs From b2cf6eb0f3c19ee9bbfd133b111ea84b7ed14d9c Mon Sep 17 00:00:00 2001 From: gephaistos Date: Tue, 23 Jul 2024 15:29:07 +0300 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca2152d..02b0dd76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - Fix `enumeratedValues` with `isDefault` only +- Generate unique identifier instead of `DEVICE_PERIPHERALS` to solve + the link time issue when multiple devices used ## [v0.33.4] - 2024-06-16 From 42c0dadf52d44af74f64f1116799ba679b5c5fe5 Mon Sep 17 00:00:00 2001 From: gephaistos Date: Fri, 26 Jul 2024 10:23:15 +0300 Subject: [PATCH 3/5] Use regex to replace symbols --- src/generate/device.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/generate/device.rs b/src/generate/device.rs index 6dcf3d9e..8786d374 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -1,6 +1,7 @@ use crate::svd::{array::names, Device, Peripheral}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; +use regex::Regex; use syn::Ident; use log::debug; @@ -273,12 +274,10 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Date: Fri, 26 Jul 2024 12:19:20 +0300 Subject: [PATCH 4/5] Revert changes and remove `#[no_mangle]` attribute --- CHANGELOG.md | 2 +- src/generate/device.rs | 26 +++++--------------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b0dd76..9af87bd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - Fix `enumeratedValues` with `isDefault` only -- Generate unique identifier instead of `DEVICE_PERIPHERALS` to solve +- Remove `#[no_mangle]` attribute of `DEVICE_PERIPHERALS` to solve the link time issue when multiple devices used ## [v0.33.4] - 2024-06-16 diff --git a/src/generate/device.rs b/src/generate/device.rs index 8786d374..9a785602 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -1,8 +1,6 @@ use crate::svd::{array::names, Device, Peripheral}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; -use regex::Regex; -use syn::Ident; use log::debug; use std::fs::File; @@ -272,22 +270,8 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Result Option { critical_section::with(|_| { // SAFETY: We are in a critical section, so we have exclusive access - // to `#taken`. - if unsafe { #taken } { + // to `DEVICE_PERIPHERALS`. + if unsafe { DEVICE_PERIPHERALS } { return None } - // SAFETY: `#taken` is set to `true` by `Peripherals::steal`, + // SAFETY: `DEVICE_PERIPHERALS` is set to `true` by `Peripherals::steal`, // ensuring the peripherals can only be returned once. Some(unsafe { Peripherals::steal() }) }) @@ -320,7 +304,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Self { - #taken = true; + DEVICE_PERIPHERALS = true; Peripherals { #exprs From 14c365a12621ea019efac5b4f1b0f49dc9de9bd5 Mon Sep 17 00:00:00 2001 From: gephaistos Date: Mon, 29 Jul 2024 13:30:14 +0300 Subject: [PATCH 5/5] Revert "Revert changes and remove `#[no_mangle]` attribute" This reverts commit e927cf1f936026c3263b9d23ee75dbb640fd8866. --- CHANGELOG.md | 2 +- src/generate/device.rs | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af87bd3..02b0dd76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - Fix `enumeratedValues` with `isDefault` only -- Remove `#[no_mangle]` attribute of `DEVICE_PERIPHERALS` to solve +- Generate unique identifier instead of `DEVICE_PERIPHERALS` to solve the link time issue when multiple devices used ## [v0.33.4] - 2024-06-16 diff --git a/src/generate/device.rs b/src/generate/device.rs index 9a785602..8786d374 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -1,6 +1,8 @@ use crate::svd::{array::names, Device, Peripheral}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; +use regex::Regex; +use syn::Ident; use log::debug; use std::fs::File; @@ -270,8 +272,22 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Result Option { critical_section::with(|_| { // SAFETY: We are in a critical section, so we have exclusive access - // to `DEVICE_PERIPHERALS`. - if unsafe { DEVICE_PERIPHERALS } { + // to `#taken`. + if unsafe { #taken } { return None } - // SAFETY: `DEVICE_PERIPHERALS` is set to `true` by `Peripherals::steal`, + // SAFETY: `#taken` is set to `true` by `Peripherals::steal`, // ensuring the peripherals can only be returned once. Some(unsafe { Peripherals::steal() }) }) @@ -304,7 +320,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result Self { - DEVICE_PERIPHERALS = true; + #taken = true; Peripherals { #exprs