Skip to content

Commit 4ed18bc

Browse files
committed
Fix _SFR_IO8 macro definition -- use volatile keyword to prevent optimization
1 parent 6814bc2 commit 4ed18bc

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
### Fixed
2222
- Don't define `ostream& operator<<(nullptr_t)` if already defined by Apple
2323
- `CppLibrary.in_tests_dir?` no longer produces an error if there is no tests directory
24+
- The definition of the `_SFR_IO8` macro no longer produces errors about rvalues
2425

2526
### Deprecated
2627
- `arduino_ci_remote.rb` CLI switch `--skip-compilation`

SampleProjects/TestSomething/test/defines.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ unittest(binary)
88
assertEqual(100, B1100100);
99
}
1010

11+
#define DDRE _SFR_IO8(0x02)
12+
13+
unittest(SFR_IO8)
14+
{
15+
// in normal arduino code, you can do this. in arduino_ci, you might get an
16+
// error like: cannot take the address of an rvalue of type 'int'
17+
//
18+
// this tests that directly
19+
&DDRE;
20+
}
21+
1122
unittest_main()

cpp/arduino/avr/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
#ifndef _AVR_IO_H_
9797
#define _AVR_IO_H_
9898

99-
#define _SFR_IO8(io_addr) (io_addr) // this macro is all we need from the sfr file
99+
#define _SFR_IO8(io_addr) (*(volatile uint8_t *)(io_addr)) // this macro is all we need from the sfr file
100100

101101
#if defined (__AVR_AT94K__)
102102
# include "ioat94k.h"

0 commit comments

Comments
 (0)