Skip to content

Commit 0b24c51

Browse files
authored
Merge pull request probe-rs#3 from vccnfitingh/optional-functions-as-features
Make EraseChip optional
2 parents 3b4fc12 + 0bbc407 commit 0b24c51

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ repository = "https://github.com/probe-rs/flash-algorithm"
99
description = "A crate to write CMSIS-DAP flash algorithms for flashing embedded targets."
1010

1111
[dependencies]
12+
13+
[features]
14+
default = ["erase-chip"]
15+
erase-chip = []

src/lib.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub trait FlashAlgorithm: Sized + 'static {
3232
fn new(address: u32, clock: u32, function: Function) -> Result<Self, ErrorCode>;
3333

3434
/// Erase entire chip. Will only be called after [`FlashAlgorithm::new()`] with [`Function::Erase`].
35+
#[cfg(feature = "erase-chip")]
3536
fn erase_all(&mut self) -> Result<(), ErrorCode>;
3637

3738
/// Erase sector. Will only be called after [`FlashAlgorithm::new()`] with [`Function::Erase`].
@@ -110,18 +111,6 @@ macro_rules! algorithm {
110111
}
111112
#[no_mangle]
112113
#[link_section = ".entry"]
113-
pub unsafe extern "C" fn EraseChip() -> u32 {
114-
if !_IS_INIT {
115-
return 1;
116-
}
117-
let this = &mut *_ALGO_INSTANCE.as_mut_ptr();
118-
match <$type as FlashAlgorithm>::erase_all(this) {
119-
Ok(()) => 0,
120-
Err(e) => e.get(),
121-
}
122-
}
123-
#[no_mangle]
124-
#[link_section = ".entry"]
125114
pub unsafe extern "C" fn EraseSector(addr: u32) -> u32 {
126115
if !_IS_INIT {
127116
return 1;
@@ -145,6 +134,7 @@ macro_rules! algorithm {
145134
Err(e) => e.get(),
146135
}
147136
}
137+
$crate::erase_chip!($type);
148138

149139
#[allow(non_upper_case_globals)]
150140
#[no_mangle]
@@ -210,6 +200,32 @@ macro_rules! algorithm {
210200
};
211201
}
212202

203+
#[doc(hidden)]
204+
#[macro_export]
205+
#[cfg(not(feature = "erase-chip"))]
206+
macro_rules! erase_chip {
207+
($type:ty) => {}
208+
}
209+
#[doc(hidden)]
210+
#[macro_export]
211+
#[cfg(feature = "erase-chip")]
212+
macro_rules! erase_chip {
213+
($type:ty) => {
214+
#[no_mangle]
215+
#[link_section = ".entry"]
216+
pub unsafe extern "C" fn EraseChip() -> u32 {
217+
if !_IS_INIT {
218+
return 1;
219+
}
220+
let this = &mut *_ALGO_INSTANCE.as_mut_ptr();
221+
match <$type as FlashAlgorithm>::erase_all(this) {
222+
Ok(()) => 0,
223+
Err(e) => e.get(),
224+
}
225+
}
226+
}
227+
}
228+
213229
#[doc(hidden)]
214230
#[macro_export]
215231
macro_rules! count {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy