Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Claude Code configuration
.claude/
.specify/
.spec-workflow

# Common IDE files
.vscode/
Expand Down
30 changes: 30 additions & 0 deletions L1_MCU/GD32F470ZGT6/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# GD32头文件
set(GD_Include_Dir
${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc
${CMAKE_CURRENT_SOURCE_DIR}/Driver/Inc
${CMAKE_CURRENT_SOURCE_DIR}/Driver/CMSIS/Device/GD/GD32F4xx/Include
${CMAKE_CURRENT_SOURCE_DIR}/Driver/CMSIS/Include
)

# 收集源文件
file(GLOB GD_Start_S ${CMAKE_CURRENT_SOURCE_DIR}/*.s)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Core/Src GD_Core_Src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Driver/Src GD_Std_Src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Driver/CMSIS/Device/GD/GD32F4xx/Source GD_CMSIS_Src)

target_sources(l1_mcu PRIVATE
${GD_Start_S}
${GD_Core_Src}
${GD_Std_Src}
${GD_CMSIS_Src}
)

target_include_directories(l1_mcu PUBLIC
${GD_Include_Dir}
)

target_compile_definitions(l1_mcu PUBLIC
GD32F470
GD32F470ZGT6
$<$<CONFIG:Debug>:DEBUG>
)
26 changes: 26 additions & 0 deletions L1_MCU/GD32F470ZGT6/Core/Inc/gd32f4xx_it.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef GD32F4XX_IT_H
#define GD32F4XX_IT_H

#include "gd32f4xx.h"

/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);

#endif /* GD32F4XX_IT_H */
82 changes: 82 additions & 0 deletions L1_MCU/GD32F470ZGT6/Core/Inc/gd32f4xx_libopt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*!
\file gd32f4xx_libopt.h
\brief library optional for gd32f4xx

\version 2016-08-15, V1.0.0, firmware for GD32F4xx
\version 2018-12-12, V2.0.0, firmware for GD32F4xx
\version 2020-09-30, V2.1.0, firmware for GD32F4xx
\version 2022-03-09, V3.0.0, firmware for GD32F4xx
*/

/*
Copyright (c) 2022, GigaDevice Semiconductor Inc.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/

#ifndef __GD32F4XX_LIBOPT_H
#define __GD32F4XX_LIBOPT_H

#if defined(GD32F450) || defined(GD32F405) || defined(GD32F407) || defined(GD32F470) || defined(GD32F425) || \
defined(GD32F427)
#include "gd32f4xx_rcu.h"
#include "gd32f4xx_adc.h"
#include "gd32f4xx_can.h"
#include "gd32f4xx_crc.h"
#include "gd32f4xx_ctc.h"
#include "gd32f4xx_dac.h"
#include "gd32f4xx_dbg.h"
#include "gd32f4xx_dci.h"
#include "gd32f4xx_dma.h"
#include "gd32f4xx_exti.h"
#include "gd32f4xx_fmc.h"
#include "gd32f4xx_fwdgt.h"
#include "gd32f4xx_gpio.h"
#include "gd32f4xx_syscfg.h"
#include "gd32f4xx_i2c.h"
#include "gd32f4xx_iref.h"
#include "gd32f4xx_pmu.h"
#include "gd32f4xx_rtc.h"
#include "gd32f4xx_sdio.h"
#include "gd32f4xx_spi.h"
#include "gd32f4xx_timer.h"
#include "gd32f4xx_trng.h"
#include "gd32f4xx_usart.h"
#include "gd32f4xx_wwdgt.h"
#include "gd32f4xx_misc.h"
#endif

#if defined(GD32F450) || defined(GD32F470)
#include "gd32f4xx_enet.h"
#include "gd32f4xx_exmc.h"
#include "gd32f4xx_ipa.h"
#include "gd32f4xx_tli.h"
#endif

#if defined(GD32F407) || defined(GD32F427)
#include "gd32f4xx_enet.h"
#include "gd32f4xx_exmc.h"
#endif /* __GD32F4XX_LIBOPT_H */

#endif /* __GD32F4XX_LIBOPT_H */
14 changes: 14 additions & 0 deletions L1_MCU/GD32F470ZGT6/Core/Inc/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __MAIN_H
#define __MAIN_H

#include "gd32f4xx.h"
#include "systick.h"
#include "gd32f4xx_libopt.h"

/* _assert */
#define _assert(X) while ((X) == 0)

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

_assert 宏展开为裸 while 语句,容易在 if/else 等场景触发“悬空 else/语句结合”问题,也不利于调试定位。建议改为 do { ... } while (0) 形式,并在断言失败时提供可选的 trap(如调用 Error_Handler() 或触发断点)以便定位。

Suggested change
#define _assert(X) while ((X) == 0)
#define _assert(X) \
do { \
if (!(X)) { \
Error_Handler(); \
} \
} while (0)

Copilot uses AI. Check for mistakes.
#define MAX_DELAY UINT32_MAX

void Error_Handler(void);

#endif /* __MAIN_H */
51 changes: 51 additions & 0 deletions L1_MCU/GD32F470ZGT6/Core/Inc/systick.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*!
\file systick.h
\brief the header file of systick

\version 2016-08-15, V1.0.0, firmware for GD32F4xx
\version 2018-12-12, V2.0.0, firmware for GD32F4xx
\version 2020-09-30, V2.1.0, firmware for GD32F4xx
\version 2022-03-09, V3.0.0, firmware for GD32F4xx
*/

/*
Copyright (c) 2022, GigaDevice Semiconductor Inc.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/

#ifndef __SYSTICK_H
#define __SYSTICK_H

#include <stdint.h>
#include "gd32f4xx.h"

extern volatile uint32_t uwTick;

void SysTick_Init(void);
void Delay(uint32_t xms);
uint32_t GetTick(void);
void Tick_Inc(void);

#endif /* __SYSTICK_H */
79 changes: 79 additions & 0 deletions L1_MCU/GD32F470ZGT6/Core/Src/gd32f4xx_it.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "gd32f4xx_it.h"
#include "main.h"
#include "systick.h"

/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}

/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1)
{
}
}

/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1)
{
}
}

/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1)
{
}
}

/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1)
{
}
}

/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

gd32f4xx_it.h 声明了 SysTick_Handler/SVC_Handler/PendSV_Handler,但本文件目前只实现到 DebugMon_Handler;如果启动文件未提供这些中断的弱定义,可能直接导致链接错误;即使有弱定义,SysTick 也可能无法驱动 Delay()/GetTick() 的逻辑。建议在本文件补齐至少 SysTick_Handler()(并按需补齐其它声明)。

Suggested change
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick interrupt
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
}

Copilot uses AI. Check for mistakes.
23 changes: 23 additions & 0 deletions L1_MCU/GD32F470ZGT6/Core/Src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "main.h"

extern void ek_main(void);

int main(void)
{
// NVIC Group
nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
SysTick_Init();

ek_main();

while (1)
{
}
}

void Error_Handler(void)
{
while (1)
{
}
}
Loading