Develop/nn#2
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an “export/auto-init” mechanism and adds initial HAL scaffolding (tick/uart/spi/gpio), along with some cleanup/simplification of toolchain CMake files.
Changes:
- Add
EK_EXPORT_ENABLEand implementEK_EXPORT(...)+ek_export_init()to run registered init functions at startup. - Add new HAL modules (
tick,uart,spi,gpio) and wire startup tick/log + export init inek_main(). - Simplify toolchain CMake files and remove legacy toolchain/linker-script files.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| ek_conf.h | Adds EK_EXPORT_ENABLE feature toggle (currently enabled by default). |
| cmake/starm-clang.cmake | Toolchain config cleanup; sets default linker script path. |
| cmake/gcc-arm-none-eabi.cmake | Toolchain config cleanup; sets default linker script path. |
| cmake/arm-compile6.cmake | Removed legacy toolchain file. |
| L5_App/src/ek_app.c | Calls ek_export_init() and switches log tick to HAL ticker. |
| L2_Core/utils/src/ek_export.c | Implements exported init-function iteration using linker symbols. |
| L2_Core/utils/inc/ek_export.h | Defines EK_EXPORT(...) macro and integration notes. |
| L2_Core/hal/src/ek_hal_uart.c | Adds UART HAL driver stub + list registration. |
| L2_Core/hal/src/ek_hal_tick.c | Adds default ticker implementation (currently placeholder). |
| L2_Core/hal/src/ek_hal_spi.c | Adds SPI HAL driver stub and exports init function. |
| L2_Core/hal/src/ek_hal_gpio.c | Adds GPIO HAL driver stub and exports init function. |
| L2_Core/hal/inc/ek_hal_uart.h | Refactors UART HAL public interface. |
| L2_Core/hal/inc/ek_hal_tick.h | Adds tick HAL public interface. |
| L2_Core/hal/inc/ek_hal_spi.h | Adds SPI HAL public interface. |
| L2_Core/hal/inc/ek_hal_gpio.h | Adds GPIO HAL public interface. |
| L2_Core/hal/inc/ek_hal_base.h | Removed unused base HAL abstraction. |
| L1_MCU/STM32F429ZIT6_STARM/stm32f4xx_flash.ld | Removed legacy linker script file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const _ek_export_init_fn_t __init_##fn##prio __attribute__((used, section(".ek_export_fn." _EK_STR(prio)))) = fn | ||
|
|
||
| #else | ||
|
|
||
| # define EK_EXPORT(fn, prio) | ||
|
|
||
| #endif /* EK_EXPORT_ENABLE */ | ||
|
|
||
| void ek_export_init(void); | ||
|
|
There was a problem hiding this comment.
When EK_EXPORT_ENABLE is 0, this header does not declare ek_export_init(). Any call sites will fail to compile/link. Provide a no-op declaration/definition for ek_export_init() in the disabled branch, or require callers to guard calls with #if (EK_EXPORT_ENABLE == 1).
| const _ek_export_init_fn_t __init_##fn##prio __attribute__((used, section(".ek_export_fn." _EK_STR(prio)))) = fn | |
| #else | |
| # define EK_EXPORT(fn, prio) | |
| #endif /* EK_EXPORT_ENABLE */ | |
| void ek_export_init(void); | |
| const _ek_export_init_fn_t __init_##fn##prio __attribute__((used, section(".ek_export_fn." _EK_STR(prio)))) = fn | |
| void ek_export_init(void); | |
| #else | |
| # define EK_EXPORT(fn, prio) | |
| static inline void ek_export_init(void) | |
| { | |
| } | |
| #endif /* EK_EXPORT_ENABLE */ |
| * KEEP(*(SORT(.ek_export_fn*))) | ||
| * . = ALIGN(4); | ||
| * _ek_export_fn_end = .; | ||
| * } > flash |
There was a problem hiding this comment.
The example linker script uses > flash, but the STM32 linker scripts in this repo use an uppercase FLASH memory region name. As written, the example is likely to be copy-pasted and fail; consider using >FLASH (or explicitly note that it must match the target linker script’s region name).
| * } > flash | |
| * } > FLASH /* FLASH 必须与目标链接脚本中的内存区域名称一致 */ |
|
|
||
| static uint8_t uart1_rx_buffer[UART_RX_BUFFER_SIZE]; // 建议通过串口 + 空闲终端 + DMA将数据搬运到这个数组 | ||
| static void uart1_uart_init(void); |
There was a problem hiding this comment.
Function name uart1_uart_recieve_to_idle is misspelled (receive). This leaks into the .read binding and makes the API harder to search/maintain.
| static void spi1_init(void); | ||
| static bool spi1_send(uint8_t *txdata, size_t size); | ||
| static bool spi1_recieve(uint8_t *rxdata, size_t size); | ||
| static bool spi1_write_recieve(uint8_t *txdata, uint8_t *rxdata, size_t size); |
There was a problem hiding this comment.
Several identifiers are misspelled (spi1_recieve, spi1_write_recieve). This makes the HAL API harder to search/maintain and can propagate into public interfaces if exposed later. Consider renaming to receive / write_receive.
| * - EK_STACK_ENABLE: 使能栈模块 | ||
| * - EK_SHELL_ENABLE: 使能shell模块 | ||
| * ======================================================================== */ | ||
| #define EK_EXPORT_ENABLE (0) |
There was a problem hiding this comment.
EK_EXPORT_ENABLE is enabled by default, but the new export mechanism requires linker-provided symbols (_ek_export_fn_start/_ek_export_fn_end). As-is, enabling this will break the default build unless all linker scripts are updated. Consider defaulting this to 0 until linker scripts are updated, or ensure the required section/symbols are present in all supported .ld files.
| # 链接脚本路径 (可通过 -DLINKER_SCRIPT 覆盖) | ||
| set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/L1_MCU/STM32F429ZIT6/stm32f429xx_flash.ld" | ||
| CACHE FILEPATH "The path to the linker script") |
There was a problem hiding this comment.
Default LINKER_SCRIPT points to ${CMAKE_SOURCE_DIR}/L1_MCU/STM32F429ZIT6/stm32f429xx_flash.ld, but that path doesn’t exist in the repo. This will cause link failures when -T is applied. Update the default to an existing linker script (e.g. under L1_MCU/STM32F429ZIT6_GCC/) or require callers to pass -DLINKER_SCRIPT=... and fail fast if it’s unset/invalid.
| static void xxx_pin_set(vopd); | ||
| static void xxx_pin_reset(vopd); | ||
| static void xxx_pin_toggle(vopd); |
There was a problem hiding this comment.
vopd is not a valid type and will not compile. These GPIO callbacks should likely be declared as void xxx_pin_set(void)/void xxx_pin_reset(void)/void xxx_pin_toggle(void) (or another concrete signature used by the HAL API).
| extern _ek_export_init_fn_t _ek_export_fn_start; | ||
| extern _ek_export_init_fn_t _ek_export_fn_end; |
There was a problem hiding this comment.
_ek_export_fn_start/_ek_export_fn_end are linker-provided symbols, but there is no linker script in the repo defining them. With EK_EXPORT_ENABLE==1 and ek_export_init() referenced, this will fail to link. Add the required section/symbol definitions to the supported .ld files (or change to a mechanism that doesn’t require linker-script edits).
| extern _ek_export_init_fn_t _ek_export_fn_start; | |
| extern _ek_export_init_fn_t _ek_export_fn_end; | |
| _ek_export_init_fn_t _ek_export_fn_start __attribute__((weak)) = 0; | |
| _ek_export_init_fn_t _ek_export_fn_end __attribute__((weak)) = 0; |
| #if (EK_EXPORT_ENABLE == 1) | ||
|
|
||
| /* | ||
| * @note 使用这个模块请在对应的 .ld 中 SECTOINS 部分添加下列的部分: |
There was a problem hiding this comment.
Typo in the linker-script integration note: SECTOINS should be SECTIONS.
| * @note 使用这个模块请在对应的 .ld 中 SECTOINS 部分添加下列的部分: | |
| * @note 使用这个模块请在对应的 .ld 中 SECTIONS 部分添加下列的部分: |
| ek_default_ticker.tick_to_wait = ek_default_ticker.get() + xticks; | ||
|
|
||
| while (ek_default_ticker.tick_to_wait >= ek_default_ticker.get()); |
There was a problem hiding this comment.
As implemented, default_delay() can spin forever because the default get() implementation returns a constant 0. Either implement get() with a real tick source, or make the default delay a safe no-op/assert until the ticker is configured.
| ek_default_ticker.tick_to_wait = ek_default_ticker.get() + xticks; | |
| while (ek_default_ticker.tick_to_wait >= ek_default_ticker.get()); | |
| /* If the ticker is still using the default stub, avoid spinning forever. */ | |
| if (ek_default_ticker.get == defualt_get_tick) | |
| { | |
| (void)xticks; | |
| return; | |
| } | |
| ek_default_ticker.tick_to_wait = ek_default_ticker.get() + xticks; | |
| while (ek_default_ticker.tick_to_wait >= ek_default_ticker.get()) | |
| { | |
| /* busy wait until tick_to_wait is reached */ | |
| } |
No description provided.