Skip to content

Commit 0e42a69

Browse files
committed
fix: remove SDA/SCL/TX/RX intermediate macros from nRF52 board headers
The nRF52840 board headers were defining SDA, SCL, TX and RX as numeric preprocessor macros (with #ifndef guards) and then assigning them to the BOARD_I2C_SDA / BOARD_UART_RX aliases. This caused a cascade of parse errors because board_config.h is included before Arduino.h, and the nRF52 SDK header nrf52.h declares struct members named SDA, SCL and RX — the preprocessor replaces those identifiers with their numeric values, turning valid struct declarations into syntax errors. Fix: assign pin numbers directly to the BOARD_* macros so that SDA, SCL, TX and RX are never defined as macros. The nRF52 platform variant still exposes them as const uint8_t variables after Arduino.h is processed, which is fine because our code only references the BOARD_* names. Both nRF52840-DK and nRF52840 Feather headers are updated. https://claude.ai/code/session_01KcwgryFgMCJubfjtwqMnUc
1 parent 48c7183 commit 0e42a69

2 files changed

Lines changed: 23 additions & 42 deletions

File tree

include/boards/board_nrf52840_dk.h

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,21 @@
2424
// ── I2C ──────────────────────────────────────────────────────────────────────
2525
// Arduino Wire on nRF52 uses the pins defined by the board variant.
2626
// nRF52840-DK default: P0.26 = SDA, P0.27 = SCL.
27-
// The macros SDA / SCL are provided by the nordicnrf52 platform variant; the
28-
// fallback values below match the DK schematic in case they are not defined.
29-
#ifndef SDA
30-
# define SDA 26
31-
#endif
32-
#ifndef SCL
33-
# define SCL 27
34-
#endif
35-
#define BOARD_I2C_SDA SDA
36-
#define BOARD_I2C_SCL SCL
27+
// Do NOT define SDA/SCL as macros here — nrf52.h has struct members with
28+
// those names and the preprocessor would clobber them.
29+
#define BOARD_I2C_SDA 26
30+
#define BOARD_I2C_SCL 27
3731
#define BOARD_I2C_FREQ 400000UL
3832

3933
// ── UART ─────────────────────────────────────────────────────────────────────
4034
// Serial is USB CDC (no physical pins needed).
41-
// Serial1 is on the Arduino header; TX and RX macros come from the variant.
42-
#ifndef TX
43-
# define TX 6 // P0.06
44-
#endif
45-
#ifndef RX
46-
# define RX 8 // P0.08
47-
#endif
48-
#define BOARD_UART_TX TX
49-
#define BOARD_UART_RX RX
50-
#define BOARD_UART1_TX TX
51-
#define BOARD_UART1_RX RX
35+
// Serial1 is on the Arduino header; P0.06 = TX, P0.08 = RX.
36+
// TX and RX are also struct-member names in the nRF52 SDK; define only the
37+
// BOARD_ aliases to avoid clashes.
38+
#define BOARD_UART_TX 6 // P0.06
39+
#define BOARD_UART_RX 8 // P0.08
40+
#define BOARD_UART1_TX 6
41+
#define BOARD_UART1_RX 8
5242

5343
// ── Status LED ───────────────────────────────────────────────────────────────
5444
// LED1–LED4 are active LOW on the nRF52840-DK.

include/boards/board_nrf52840_feather.h

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,21 @@
1616

1717
// ── I2C ──────────────────────────────────────────────────────────────────────
1818
// SDA and SCL are labelled on the Feather silkscreen.
19-
// Adafruit nRF52 Arduino core maps: SDA = P0.12, SCL = P0.11.
20-
// The SDA/SCL macros are defined by the Adafruit nRF52 platform variant.
21-
#ifndef SDA
22-
# define SDA 25 // Adafruit nRF52 Arduino pin 25 → P0.12
23-
#endif
24-
#ifndef SCL
25-
# define SCL 26 // Adafruit nRF52 Arduino pin 26 → P0.11
26-
#endif
27-
#define BOARD_I2C_SDA SDA
28-
#define BOARD_I2C_SCL SCL
19+
// Adafruit nRF52 Arduino core maps: SDA = P0.12 (pin 25), SCL = P0.11 (pin 26).
20+
// Do NOT define SDA/SCL as macros — nrf52.h has struct members with those
21+
// names and the preprocessor would clobber them.
22+
#define BOARD_I2C_SDA 25 // Adafruit nRF52 Arduino pin 25 → P0.12
23+
#define BOARD_I2C_SCL 26 // Adafruit nRF52 Arduino pin 26 → P0.11
2924
#define BOARD_I2C_FREQ 400000UL
3025

3126
// ── UART ─────────────────────────────────────────────────────────────────────
32-
// Serial is USB CDC. Serial1 maps to the Feather TX/RX pads.
33-
#ifndef TX
34-
# define TX 25 // P0.25
35-
#endif
36-
#ifndef RX
37-
# define RX 24 // P0.24
38-
#endif
39-
#define BOARD_UART_TX TX
40-
#define BOARD_UART_RX RX
41-
#define BOARD_UART1_TX TX
42-
#define BOARD_UART1_RX RX
27+
// Serial is USB CDC. Serial1 maps to the Feather TX/RX pads (P0.25/P0.24).
28+
// TX and RX are also struct-member names in the nRF52 SDK; define only the
29+
// BOARD_ aliases.
30+
#define BOARD_UART_TX 25 // P0.25
31+
#define BOARD_UART_RX 24 // P0.24
32+
#define BOARD_UART1_TX 25
33+
#define BOARD_UART1_RX 24
4334

4435
// ── Status LEDs ──────────────────────────────────────────────────────────────
4536
// Red LED and Blue LED both active LOW.

0 commit comments

Comments
 (0)