1.外部晶振使用8M
2.修改例程gd32f4xx.h
/* define value of high speed crystal oscillator (HXTAL) in Hz */
#if !defined (HXTAL_VALUE)
#define HXTAL_VALUE ((uint32_t)8000000)
将系统默认的25000000改为8000000
2.在system_gd32f4xx.c中修改为如下代码
#include "gd32f4xx.h"
/* system frequency define */
#define __IRC16M (IRC8M_VALUE) /* internal 16 MHz RC oscillator frequency */
#define __HXTAL (HXTAL_VALUE) /* high speed crystal oscillator frequency */
//#define __SYS_OSC_CLK (__IRC16M) /* main oscillator frequency */
#define __SYS_OSC_CLK (__HXTAL)
/* select a system clock by uncommenting the following line */
//#define __SYSTEM_CLOCK_IRC16M (uint32_t)(__IRC16M)
//#define __SYSTEM_CLOCK_HXTAL (uint32_t)(__HXTAL)
//#define __SYSTEM_CLOCK_120M_PLL_IRC16M (uint32_t)(120000000)
//#define __SYSTEM_CLOCK_120M_PLL_8M_HXTAL (uint32_t)(120000000)
//#define __SYSTEM_CLOCK_120M_PLL_25M_HXTAL (uint32_t)(120000000)
//#define __SYSTEM_CLOCK_168M_PLL_IRC16M (uint32_t)(168000000)
#define __SYSTEM_CLOCK_168M_PLL_8M_HXTAL (uint32_t)(168000000)
//#define __SYSTEM_CLOCK_168M_PLL_25M_HXTAL (uint32_t)(168000000)
//#define __SYSTEM_CLOCK_200M_PLL_IRC16M (uint32_t)(200000000)
//#define __SYSTEM_CLOCK_200M_PLL_8M_HXTAL (uint32_t)(200000000)
//#define __SYSTEM_CLOCK_200M_PLL_25M_HXTAL (uint32_t)(200000000)
测试代码:
int main(void)
{
/* configure systick */
systick_config();
/* enable the LEDs GPIO clock */
rcu_periph_clock_enable(RCU_GPIOC);
/* configure LED1 GPIO port */
gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_9);//GPIOC_9
gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_8);//GPIOC_9
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_8);
/* reset LED1 GPIO pin */
gpio_bit_reset(GPIOC, GPIO_PIN_9);
gpio_bit_set(GPIOC, GPIO_PIN_8);
while(1){
/* turn on LED1 */
gpio_bit_set(GPIOC, GPIO_PIN_9);
gpio_bit_reset(GPIOC, GPIO_PIN_8);
delay_1ms(100);
/* turn off LED1 */
gpio_bit_reset(GPIOC, GPIO_PIN_9);
gpio_bit_set(GPIOC, GPIO_PIN_8);
delay_1ms(100);
}
}
以上GPIO8和GPIO9将产生100ms的方波.