Skip to content

fix(rapi): size $GI buffers from MCU_ID_LEN, not the target name - #56

Draft
jeremypoulter wants to merge 1 commit into
OpenEVSE:devfrom
jeremypoulter:fix/buffer-sizing-by-mcu-id
Draft

fix(rapi): size $GI buffers from MCU_ID_LEN, not the target name#56
jeremypoulter wants to merge 1 commit into
OpenEVSE:devfrom
jeremypoulter:fix/buffer-sizing-by-mcu-id

Conversation

@jeremypoulter

Copy link
Copy Markdown
Collaborator

ESRAPI_BUFLEN and TMP_BUF_SIZE were selected with #ifdef TARGET_SAMD, while the #error guards that check them assert on MCU_ID_LEN. Any new target with a 16-byte MCU id therefore failed to build, even though the requirement it violated was expressed purely in terms of the id length.

This keys the selection on MCU_ID_LEN instead, so a target inherits the right buffer from the property that actually drives it.

Both existing targets are unchanged

A 16-byte id still selects 40/48 and a 10-byte id still selects 32/34, so AVR RAM cost stays zero — ESRAPI_BUFLEN sizes three buffers there (buffer[], g_rapiSerialBuffer, g_rapiI2ClBuffer).

#if (2*MCU_ID_LEN + 1) > 32
#define ESRAPI_BUFLEN 40      // MCU_ID_LEN 16 -> 40  (samd, unchanged)
#else
#define ESRAPI_BUFLEN 32      // MCU_ID_LEN 10 -> 32  (m328p, unchanged)
#endif

Verification

Temporary compile-time assertions pinned the expected values per target, including a deliberately wrong value to confirm the assertions could fail. Clean builds are byte-identical to baseline:

env text data bss
m328p_core 22752 256 684
m328p_LCD_WIFI 26834 348 698
samd 46716 560 4140

Both #error guards are retained. Include order was checked: target.h lands at open_evse.h:39 and rapi_proc.h is only included from open_evse.h:1442, so MCU_ID_LEN is defined before either block is evaluated. That mattered — if it were not, samd would silently drop to the 32-byte buffer and the guard would be skipped too.

Worth having on its own merits: it is a latent trap for whatever target comes next.

🤖 Generated with Claude Code

ESRAPI_BUFLEN and TMP_BUF_SIZE were selected with #ifdef TARGET_SAMD while
the #error guards that check them assert on MCU_ID_LEN. Any new target with
a 16-byte MCU id therefore failed to build, even though the requirement it
violated was expressed purely in terms of the id length.

Key the selection on MCU_ID_LEN so a target inherits the right buffer from
the property that actually drives it. Both existing targets are unchanged:
a 16-byte id still selects 40/48, a 10-byte id still selects 32/34, so AVR
RAM cost stays zero (ESRAPI_BUFLEN sizes three buffers there).

Verified with temporary compile-time assertions pinning the expected values
per target, including a deliberate wrong value to confirm the assertions
could fail. Clean builds of m328p_core, m328p_LCD_WIFI and samd are
byte-identical to baseline:

  m328p_core      text 22752  data 256  bss  684
  m328p_LCD_WIFI  text 26834  data 348  bss  698
  samd            text 46716  data 560  bss 4140

Both #error guards are retained. Include order was checked: target.h lands
at open_evse.h:39 and rapi_proc.h is only included from open_evse.h:1442,
so MCU_ID_LEN is defined before either block is evaluated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant