Skip to content

Commit 14851f2

Browse files
committed
fix itm::write_all
1 parent 3ab89d6 commit 14851f2

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
## [v0.2.8] - 2017-05-30
10+
## [v0.2.9] - 2017-05-30
11+
12+
### Fixed
13+
14+
- A bug in `itm::write_all` where it would ignore the length of the buffer and
15+
serialize contents that come after the buffer.
16+
17+
## [v0.2.8] - 2017-05-30 - YANKED
1118

1219
### Added
1320

@@ -279,7 +286,8 @@ fn main() {
279286
- Functions to get the vector table
280287
- Wrappers over miscellaneous instructions like `bkpt`
281288

282-
[Unreleased]: https://github.com/japaric/cortex-m/compare/v0.2.8...HEAD
289+
[Unreleased]: https://github.com/japaric/cortex-m/compare/v0.2.9...HEAD
290+
[v0.2.9]: https://github.com/japaric/cortex-m/compare/v0.2.8...v0.2.9
283291
[v0.2.8]: https://github.com/japaric/cortex-m/compare/v0.2.7...v0.2.8
284292
[v0.2.7]: https://github.com/japaric/cortex-m/compare/v0.2.6...v0.2.7
285293
[v0.2.6]: https://github.com/japaric/cortex-m/compare/v0.2.5...v0.2.6

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "register", "peripheral"]
77
license = "MIT OR Apache-2.0"
88
name = "cortex-m"
99
repository = "https://github.com/japaric/cortex-m"
10-
version = "0.2.8"
10+
version = "0.2.9"
1111

1212
[dependencies]
1313
aligned = "0.1.1"

src/itm.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ pub fn write_all(port: &Stim, buffer: &[u8]) {
3131
let mut len = buffer.len();
3232
let mut ptr = buffer.as_ptr();
3333

34+
if len == 0 {
35+
return;
36+
}
37+
3438
// 0x01 OR 0x03
3539
if ptr as usize % 2 == 1 {
3640
while !port.is_fifo_ready() {}
@@ -43,12 +47,23 @@ pub fn write_all(port: &Stim, buffer: &[u8]) {
4347

4448
// 0x02
4549
if ptr as usize % 4 == 2 {
46-
while !port.is_fifo_ready() {}
47-
port.write_u16(ptr::read(ptr as *const u16));
48-
49-
// 0x04
50-
ptr = ptr.offset(2);
51-
len -= 2;
50+
if len > 1 {
51+
// at least 2 bytes
52+
while !port.is_fifo_ready() {}
53+
port.write_u16(ptr::read(ptr as *const u16));
54+
55+
// 0x04
56+
ptr = ptr.offset(2);
57+
len -= 2;
58+
} else {
59+
if len == 1 {
60+
// last byte
61+
while !port.is_fifo_ready() {}
62+
port.write_u8(*ptr);
63+
}
64+
65+
return;
66+
}
5267
}
5368

5469
write_aligned(port, mem::transmute(slice::from_raw_parts(ptr, len)));

0 commit comments

Comments
 (0)