summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-05-30 19:18:09 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-05-30 19:18:09 -0500
commit14851f2ad78b5675cb253915ce21e58dfb75a020 (patch)
tree9edbb74dda9be50c6b6758b4409b84447f4f6f04
parent3ab89d6894ca18342846a2cd8748ac3059449b09 (diff)
downloadcortex-m-14851f2ad78b5675cb253915ce21e58dfb75a020.tar.gz
cortex-m-14851f2ad78b5675cb253915ce21e58dfb75a020.tar.zst
cortex-m-14851f2ad78b5675cb253915ce21e58dfb75a020.zip
fix itm::write_allv0.2.9
-rw-r--r--CHANGELOG.md12
-rw-r--r--Cargo.toml2
-rw-r--r--src/itm.rs27
3 files changed, 32 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0839b6e..d13b59c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
-## [v0.2.8] - 2017-05-30
+## [v0.2.9] - 2017-05-30
+
+### Fixed
+
+- A bug in `itm::write_all` where it would ignore the length of the buffer and
+ serialize contents that come after the buffer.
+
+## [v0.2.8] - 2017-05-30 - YANKED
### Added
@@ -279,7 +286,8 @@ fn main() {
- Functions to get the vector table
- Wrappers over miscellaneous instructions like `bkpt`
-[Unreleased]: https://github.com/japaric/cortex-m/compare/v0.2.8...HEAD
+[Unreleased]: https://github.com/japaric/cortex-m/compare/v0.2.9...HEAD
+[v0.2.9]: https://github.com/japaric/cortex-m/compare/v0.2.8...v0.2.9
[v0.2.8]: https://github.com/japaric/cortex-m/compare/v0.2.7...v0.2.8
[v0.2.7]: https://github.com/japaric/cortex-m/compare/v0.2.6...v0.2.7
[v0.2.6]: https://github.com/japaric/cortex-m/compare/v0.2.5...v0.2.6
diff --git a/Cargo.toml b/Cargo.toml
index a24d5a3..805f06a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "register", "peripheral"]
license = "MIT OR Apache-2.0"
name = "cortex-m"
repository = "https://github.com/japaric/cortex-m"
-version = "0.2.8"
+version = "0.2.9"
[dependencies]
aligned = "0.1.1"
diff --git a/src/itm.rs b/src/itm.rs
index a8a7be4..80de99c 100644
--- a/src/itm.rs
+++ b/src/itm.rs
@@ -31,6 +31,10 @@ pub fn write_all(port: &Stim, buffer: &[u8]) {
let mut len = buffer.len();
let mut ptr = buffer.as_ptr();
+ if len == 0 {
+ return;
+ }
+
// 0x01 OR 0x03
if ptr as usize % 2 == 1 {
while !port.is_fifo_ready() {}
@@ -43,12 +47,23 @@ pub fn write_all(port: &Stim, buffer: &[u8]) {
// 0x02
if ptr as usize % 4 == 2 {
- while !port.is_fifo_ready() {}
- port.write_u16(ptr::read(ptr as *const u16));
-
- // 0x04
- ptr = ptr.offset(2);
- len -= 2;
+ if len > 1 {
+ // at least 2 bytes
+ while !port.is_fifo_ready() {}
+ port.write_u16(ptr::read(ptr as *const u16));
+
+ // 0x04
+ ptr = ptr.offset(2);
+ len -= 2;
+ } else {
+ if len == 1 {
+ // last byte
+ while !port.is_fifo_ready() {}
+ port.write_u8(*ptr);
+ }
+
+ return;
+ }
}
write_aligned(port, mem::transmute(slice::from_raw_parts(ptr, len)));