Skip to content

Commit 1473135

Browse files
authored
Allow non-aligned PSTR()
1 parent b326aa4 commit 1473135

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

newlib/libc/sys/xtensa/sys/pgmspace.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ extern "C" {
3131
#define PGM_VOID_P const void *
3232
#endif
3333

34-
// PSTR() macro modified to start on a 32-bit boundary. This adds on average
35-
// 1.5 bytes/string, but in return memcpy_P and strcpy_P will work 4~8x faster
34+
#ifndef PSTR_ALIGN
35+
// PSTR() macro starts by default on a 32-bit boundary. This adds on average
36+
// 1.5 bytes/string, but in return memcpy_P and strcpy_P will work 4~8x faster
37+
// Allow users to override the alignment with PSTR_ALIGN
38+
#define PSTR_ALIGN 4
39+
#endif
3640
#ifndef PSTR
3741
// Adapted from AVR-specific code at https://forum.arduino.cc/index.php?topic=194603.0
3842
// Uses C attribute section instead of ASM block to allow for C language string concatenation ("x" "y" === "xy")
39-
#define PSTR(s) (__extension__({static const char __pstr__[] __attribute__((__aligned__(4))) __attribute__((section( "\".irom0.pstr." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\", \"aSM\", @progbits, 1 #"))) = (s); &__pstr__[0];}))
43+
#define PSTR(s) (__extension__({static const char __pstr__[] __attribute__((__aligned__(PSTR_ALIGN))) __attribute__((section( "\".irom0.pstr." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\", \"aSM\", @progbits, 1 #"))) = (s); &__pstr__[0];}))
4044
#endif
4145

4246
// Flash memory must be read using 32 bit aligned addresses else a processor

0 commit comments

Comments
 (0)