[N32G45x] 基于N32G457QEL7开发Systick配置

[复制链接]
24|1
小海师 发表于 2026-3-12 07:07 | 显示全部楼层 |阅读模式
一、在SYSTEM文件夹下增加system_cortex_m_systick.c/n32g45x_it.c和system_cortex_m_systick.h/n32g45x_it.h,SystemTypedef.h文件,并添加之项目工程中;

302269b1194a43a4d.png

2786469b119423fea0.png

二、实现Systick的软件配置;
system_cortex_m_systick.c

#include "system_cortex_m_systick.h"
#include "n32g45x.h"

volatile static u32 g_systick = 0;

/*!
    \brief      this function handles SysTick exception
    \param[in]  none
    \param[out] none
    \retval     none
*/
void SysTick_Handler(void)
{
    g_systick++;
}


/*!
    \brief      configure systick  1ms
    \param[in]  none
    \param[out] none
    \retval     none
*/
void System_SystickConfig(void)
{
    /* setup systick timer for 1000Hz interrupts */
    if(SysTick_Config(SystemCoreClock / 1000U)) {
        /* capture error */
        while(1) {
        }
    }
    /* configure the systick handler priority */
    NVIC_SetPriority(SysTick_IRQn, 0x00U);
}

/*!
    \brief      delay a time in milliseconds
    \param[in]  count: count in milliseconds
    \param[out] none
    \retval     none
*/
void System_SystickDelay_ms(u32 n_ms)
{
    u32 cur_tick = g_systick;
    while((g_systick-cur_tick) <= n_ms){}
}




system_cortex_m_systick.h

#ifndef __SYSTEM_CORTEX_M_SYSTICK_H_
#define __SYSTEM_CORTEX_M_SYSTICK_H_

#include "SystemTypedef.h"

/*!
    \brief      configure systick  1ms
    \param[in]  none
    \param[out] none
    \retval     none
*/
void System_SystickConfig(void);

/*!
    \brief      delay a time in milliseconds
    \param[in]  count: count in milliseconds
    \param[out] none
    \retval     none
*/
void System_SystickDelay_ms(u32 n_ms);

#endif



SystemTypedef.h

#ifndef __SYSTEM_TYPEDEF_H
#define __SYSTEM_TYPEDEF_H

#ifndef NULL
#define NULL 0
#endif

#ifndef Myself_DATA_TYPE
typedef unsigned long long u64;
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef long long s64;
typedef int s32;
typedef short s16;
typedef const unsigned char uc8;
typedef volatile unsigned int vu32;
#endif

#endif





n32g45x_it.c

/**
* @file n32g45x_it.c
* @author Nations
* @version v1.0.1
*
* @CopyRight Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#include "n32g45x_it.h"
#include "n32g45x.h"

/** @addtogroup N32G45X_StdPeriph_Template
* @{
*/


/******************************************************************************/
/*            Cortex-M4 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
* @brief  This function handles NMI exception.
*/
void NMI_Handler(void)
{
}

/**
* @brief  This function handles Hard Fault exception.
*/
void HardFault_Handler(void)
{
    /* Go to infinite loop when Hard Fault exception occurs */
    while (1)
    {
    }
}

/**
* @brief  This function handles Memory Manage exception.
*/
void MemManage_Handler(void)
{
    /* Go to infinite loop when Memory Manage exception occurs */
    while (1)
    {
    }
}

/**
* @brief  This function handles Bus Fault exception.
*/
void BusFault_Handler(void)
{
    /* Go to infinite loop when Bus Fault exception occurs */
    while (1)
    {
    }
}

/**
* @brief  This function handles Usage Fault exception.
*/
void UsageFault_Handler(void)
{
    /* Go to infinite loop when Usage Fault exception occurs */
    while (1)
    {
    }
}

/**
* @brief  This function handles SVCall exception.
*/
void SVC_Handler(void)
{
}

/**
* @brief  This function handles Debug Monitor exception.
*/
void DebugMon_Handler(void)
{
}


/******************************************************************************/
/*                 N32G45X Peripherals Interrupt Handlers                     */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (startup_n32g45x.s).                                                 */
/******************************************************************************/

/**
* @brief  This function handles PPP interrupt request.
*/
/*void PPP_IRQHandler(void)
{
}*/

/**
* @}
*/







n32g45x_it.h

/**
* @file n32g45x_it.h
* @author Nations
* @version v1.0.0
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#ifndef __N32G45X_IT_H__
#define __N32G45X_IT_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "n32g45x.h"

void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);

#ifdef __cplusplus
}
#endif

#endif /* __N32G45X_IT_H__ */
/**
* @}
*/

/**
* @}
*/

/**
* @}
*/



main.c

#include "n32g45x.h"
#include "system_cortex_m_systick.h"
int main(void)
{
    System_SystickConfig();
    while(1)
    {

    }
    return 0;

}



三,进行软件代码的编译,下载验证;

2064069b1190f8247e.png

2566169b1190adda1f.png

四,仿真运行软件后,可以查看到systick每间隔1ms自增1;

492669b11906190f1.png

将软件断点设置在SysTick_Handler也能够正常触发;

8204069b1190035087.png

软件运行均正常,说明配置成功;
————————————————
版权声明:本文为CSDN博主「小吴同学啊」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43647919/article/details/157978520

OKAKAKO 发表于 2026-7-29 23:46 | 显示全部楼层
基于N32G457QEL7开发Systick配置很详细的教程
您需要登录后才可以回帖 登录 | 注册

本版积分规则

242

主题

624

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部
0