Skip to content

Add Generic CMSIS Network Interface Template#1310

Draft
HTRamsey wants to merge 1 commit intoFreeRTOS:mainfrom
HTRamsey:dev-networkinterface-cmsis
Draft

Add Generic CMSIS Network Interface Template#1310
HTRamsey wants to merge 1 commit intoFreeRTOS:mainfrom
HTRamsey:dev-networkinterface-cmsis

Conversation

@HTRamsey
Copy link
Contributor

@HTRamsey HTRamsey commented Feb 8, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 8, 2026 03:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a generic CMSIS-based FreeRTOS+TCP NetworkInterface template and wires it into the build so FREERTOS_PLUS_TCP_NETWORK_IF=CMSIS can be selected.

Changes:

  • Added CMSIS network interface CMake integration (new subdir build + top-level selector).
  • Vendored CMSIS Core headers plus example MAC/PHY driver headers/templates for bring-up.
  • Added example Ethernet register/driver definitions for LAN91C111 and KSZ8851SNL.

Reviewed changes

Copilot reviewed 39 out of 81 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
source/portable/NetworkInterface/CMSIS/Driver/Examples/Ethernet/LAN91C111/ETH_LAN91C111.h Adds LAN91C111 register definitions and driver control struct.
source/portable/NetworkInterface/CMSIS/Driver/Examples/Ethernet/KSZ8851SNL/ETH_KSZ8851SNL.h Adds KSZ8851SNL register definitions and driver control struct.
source/portable/NetworkInterface/CMSIS/Driver/DriverTemplates/Driver_ETH_PHY.c Adds a CMSIS ETH PHY driver template (stub implementation).
source/portable/NetworkInterface/CMSIS/Driver/DriverTemplates/Driver_ETH_MAC.c Adds a CMSIS ETH MAC driver template (stub implementation).
source/portable/NetworkInterface/CMSIS/Core/Include/tz_context.h Adds TrustZone context management header from CMSIS Core.
source/portable/NetworkInterface/CMSIS/Core/Include/r-profile/cmsis_iccarm_r.h Adds CMSIS-Core(R) ICCARM compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/r-profile/cmsis_gcc_r.h Adds CMSIS-Core(R) GCC compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/r-profile/cmsis_clang_r.h Adds CMSIS-Core(R) clang compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/r-profile/cmsis_armclang_r.h Adds CMSIS-Core(R) armclang compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h Adds CMSIS-Core(M) ICCARM compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/m-profile/armv8m_pmu.h Adds Armv8.1-M PMU API header.
source/portable/NetworkInterface/CMSIS/Core/Include/m-profile/armv8m_mpu.h Adds Armv8-M / Armv8.1-M MPU API header.
source/portable/NetworkInterface/CMSIS/Core/Include/m-profile/armv81m_pac.h Adds Armv8.1-M PAC key access header.
source/portable/NetworkInterface/CMSIS/Core/Include/m-profile/armv7m_mpu.h Adds Armv7-M MPU API header.
source/portable/NetworkInterface/CMSIS/Core/Include/m-profile/armv7m_cachel1.h Adds Armv7-M L1 cache API header.
source/portable/NetworkInterface/CMSIS/Core/Include/cmsis_version.h Adds CMSIS version macros.
source/portable/NetworkInterface/CMSIS/Core/Include/cmsis_iccarm.h Adds CMSIS compiler abstraction for ICCARM across profiles.
source/portable/NetworkInterface/CMSIS/Core/Include/cmsis_compiler.h Adds CMSIS generic compiler dispatch header.
source/portable/NetworkInterface/CMSIS/Core/Include/a-profile/irq_ctrl.h Adds CMSIS-Core(A) IRQ controller API header.
source/portable/NetworkInterface/CMSIS/Core/Include/a-profile/cmsis_iccarm_a.h Adds CMSIS-Core(A) ICCARM compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/a-profile/cmsis_gcc_a.h Adds CMSIS-Core(A) GCC compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/a-profile/cmsis_cp15.h Adds CP15 accessor intrinsics for A-profile.
source/portable/NetworkInterface/CMSIS/Core/Include/a-profile/cmsis_clang_a.h Adds CMSIS-Core(A) LLVM/Clang compiler header.
source/portable/NetworkInterface/CMSIS/Core/Include/a-profile/cmsis_armclang_a.h Adds CMSIS-Core(A) armclang compiler header.
source/portable/NetworkInterface/CMSIS/CMakeLists.txt Adds CMSIS network interface target setup and extension points.
CMakeLists.txt Makes CMSIS selectable via FREERTOS_PLUS_TCP_NETWORK_IF.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +44
static int32_t ARM_ETH_PHY_Initialize(ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write)
{
}

static int32_t ARM_ETH_PHY_Uninitialize(void)
{
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several non-void functions have empty bodies or fall off the end without returning a value (Initialize, Uninitialize, SetInterface, SetMode, GetLinkState, GetLinkInfo). Even as templates, these will fail compilation (and/or trigger undefined behavior). Please return valid CMSIS driver status codes/values (for example ARM_DRIVER_ERROR/ARM_DRIVER_ERROR_UNSUPPORTED or ARM_DRIVER_OK, and sensible defaults for link state/info) so the template builds out-of-the-box.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +85
static int32_t ARM_ETH_PHY_SetInterface(uint32_t interface)
{
switch (interface)
{
case ARM_ETH_INTERFACE_MII:
break;
case ARM_ETH_INTERFACE_RMII:
break;
default:
return ARM_DRIVER_ERROR_UNSUPPORTED;
}
}

static int32_t ARM_ETH_PHY_SetMode(uint32_t mode)
{
switch (mode & ARM_ETH_PHY_SPEED_Msk)
{
case ARM_ETH_PHY_SPEED_10M:
break;
case ARM_ETH_PHY_SPEED_100M:
break;
default:
return ARM_DRIVER_ERROR_UNSUPPORTED;
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several non-void functions have empty bodies or fall off the end without returning a value (Initialize, Uninitialize, SetInterface, SetMode, GetLinkState, GetLinkInfo). Even as templates, these will fail compilation (and/or trigger undefined behavior). Please return valid CMSIS driver status codes/values (for example ARM_DRIVER_ERROR/ARM_DRIVER_ERROR_UNSUPPORTED or ARM_DRIVER_OK, and sensible defaults for link state/info) so the template builds out-of-the-box.

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +114
}

static ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState(void)
{
}

static ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo(void)
{
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several non-void functions have empty bodies or fall off the end without returning a value (Initialize, Uninitialize, SetInterface, SetMode, GetLinkState, GetLinkInfo). Even as templates, these will fail compilation (and/or trigger undefined behavior). Please return valid CMSIS driver status codes/values (for example ARM_DRIVER_ERROR/ARM_DRIVER_ERROR_UNSUPPORTED or ARM_DRIVER_OK, and sensible defaults for link state/info) so the template builds out-of-the-box.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +69
{
}

static int32_t ARM_ETH_MAC_Uninitialize(void)
{
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the PHY template, many non-void functions are empty and/or don’t return a value (including ARM_ETH_MAC_Control, which returns nothing on the non-default paths). This will break compilation. Please make the template consistently return ARM_DRIVER_OK for implemented stubs (or ARM_DRIVER_ERROR_UNSUPPORTED where appropriate) and ensure every non-void function returns on all control paths.

Suggested change
{
}
static int32_t ARM_ETH_MAC_Uninitialize(void)
{
{
(void)cb_event;
return ARM_DRIVER_OK;
}
static int32_t ARM_ETH_MAC_Uninitialize(void)
{
return ARM_DRIVER_OK;

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +90
static int32_t ARM_ETH_MAC_GetMacAddress(ARM_ETH_MAC_ADDR *ptr_addr)
{
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the PHY template, many non-void functions are empty and/or don’t return a value (including ARM_ETH_MAC_Control, which returns nothing on the non-default paths). This will break compilation. Please make the template consistently return ARM_DRIVER_OK for implemented stubs (or ARM_DRIVER_ERROR_UNSUPPORTED where appropriate) and ensure every non-void function returns on all control paths.

Copilot uses AI. Check for mistakes.
#define ARM_MPU_ATTR(O, I) ((((O) & 0xFU) << 4U) | ((((O) & 0xFU) != 0U) ? ((I) & 0xFU) : (((I) & 0x3U) << 2U)))

/* \brief Specifies MAIR_ATTR number */
#define MAIR_ATTR(x) ((x > 7 || x < 0) ? 0 : x)
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAIR_ATTR(x) checks x < 0, but x is a macro parameter and is commonly passed as an unsigned expression; this can trigger -Wtype-limits and is ineffective for unsigned values. Consider rewriting this so it doesn’t perform a signed-only comparison (for example, only validate the upper bound, or explicitly cast once in a way that won’t warn).

Suggested change
#define MAIR_ATTR(x) ((x > 7 || x < 0) ? 0 : x)
#define MAIR_ATTR(x) (((unsigned)(x) > 7U) ? 0U : (unsigned)(x))

Copilot uses AI. Check for mistakes.
\details writes the given PAC key to the PAC_KEY_P registers.
\param [in] pPacKey 128bit PAC key
*/
__STATIC_FORCEINLINE void __set_PAC_KEY_P (uint32_t* pPacKey) {
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PAC key “set” functions take a non-const pointer, but they only read the key material from memory. Using const uint32_t * better communicates intent and allows callers to pass const data without casts.

Copilot uses AI. Check for mistakes.
\details writes the given PAC key to the PAC_KEY_U registers.
\param [in] pPacKey 128bit PAC key
*/
__STATIC_FORCEINLINE void __set_PAC_KEY_U (uint32_t* pPacKey) {
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PAC key “set” functions take a non-const pointer, but they only read the key material from memory. Using const uint32_t * better communicates intent and allows callers to pass const data without casts.

Copilot uses AI. Check for mistakes.
#define IST_ALLOC_INT 0x08 // Tx ram Allocation interrupt
#define IST_TX_EMPTY 0x04 // Tx FIFO empty interrupt
#define IST_TX_INT 0x02 // Tx Complete interrupt
#define IST_RCV_INT 0x01 // Rx Complete intererupt
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct typo in comment: “intererupt” → “interrupt”.

Suggested change
#define IST_RCV_INT 0x01 // Rx Complete intererupt
#define IST_RCV_INT 0x01 // Rx Complete interrupt

Copilot uses AI. Check for mistakes.
#define REG_PHY1ILR 0xE8 // PHY 1 PHY ID Low Register
#define REG_PHY1IHR 0xEA // PHY 1 PHY ID High Register
#define REG_P1ANAR 0xEC // PHY 1 Auto-Negotiation Advertisement Register
#define REG_P1ANLPR 0xEE // PHY 1 Auto-Negotiation Ling Partner Ability Register
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct typo in comment: “Ling Partner” → “Link Partner”.

Suggested change
#define REG_P1ANLPR 0xEE // PHY 1 Auto-Negotiation Ling Partner Ability Register
#define REG_P1ANLPR 0xEE // PHY 1 Auto-Negotiation Link Partner Ability Register

Copilot uses AI. Check for mistakes.
@HTRamsey HTRamsey force-pushed the dev-networkinterface-cmsis branch from e9a722c to 09e6585 Compare February 8, 2026 03:28
@HTRamsey HTRamsey marked this pull request as draft February 8, 2026 15:49
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