白高兴了一番,详细查了datasheet,竟然不支持SLCD,白瞎了我买的一块68的裸屏,后面还得折腾一块LCD驱动。
还是从最基础的开始,先把串口搞定,打印下基本的系统主要资源的频率。
用keil进行烧写和调试时,直接用GD-Link的话,调试器需要选择为:
CMSIS-DAP ARMv8-M Debugger
GDL233调试器配置
点击“Load”按钮,竟然出错了:
---------------------------
CMSIS-DAP - ARMv8-M Error
---------------------------
Cannot Load Flash Programming Algorithm!
C:\Keil_Packs\GigaDevice\GD32L23x_DFP\0.0.0\Flash\GD32L23x_256K.FLM
---------------------------
确定
---------------------------
找了下GD32L23x_256K.FLM这个文件,在呢!!!
刚开始怀疑是不是硬件的问题,用官方的软件试了一下,是可以读取到数据的。
GDLink读取结果上网找了半天,什么重启,BOOT启动项,修改Debug参数,等等方法都试过了,都不行。
最后发现,需要修改下Algorithm的ram大小就可以了。
把Size由 0x00001000
改成 0x00002000
就OK了。
建议官方修改下这里。
Cannot Load Flash Programming Algorithm解决方法用MiniUSB接到板子的串口上,可以看到驱动已经OK。
(如果电脑上没有装CH340驱动,应该需要装一个)
串口驱动串口的驱动代码:
void uart1_init(uint32_t baudrate)
{
uint32_t com = USART0;
usart_deinit(com);
rcu_periph_clock_enable(RCU_USART0);
rcu_periph_clock_enable(RCU_GPIOA);
///< USART1_TX PA.9
gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_9);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
///< USART1_RX PA.10
gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_10);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
usart_baudrate_set(com, baudrate);
usart_word_length_set(com, USART_WL_8BIT);
usart_stop_bit_set(com, USART_STB_1BIT);
usart_parity_config(com, USART_PM_NONE);
usart_hardware_flow_rts_config(com, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(com, USART_CTS_DISABLE);
usart_receive_config(com, USART_RECEIVE_ENABLE);
usart_transmit_config(com, USART_TRANSMIT_ENABLE);
usart_enable(com);
nvic_irq_enable(USART0_IRQn, 3);
}
串口打印重定向printf,没有用MicroLiB:
#define PRINTF_UART USART0
__ASM (".global __use_no_semihosting");
/* FILE is typedef’ d in stdio.h. */
FILE __stdout;
void _sys_exit(int x)
{
x = x;
}
void _ttywrch(int ch)
{
ch = ch;
}
void _sys_command_string(int ch)
{
ch = ch;
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(PRINTF_UART, (uint8_t)ch);
while(RESET == usart_flag_get(PRINTF_UART, USART_FLAG_TBE));
return ch;
}
直接调用API就行了:rcu_clock_freq_get
。
吐槽下官方给的api的不一致,M4的API的确少了点什么!!-_-
建议官方最好在一致性上做到保障。
rcu_clock_freq_get差异测试的代码比较简单:
static void freq_test(void)
{
#ifdef FREQ_TEST
uint32_t freq[5];
#ifdef STM32
RCC_ClocksTypeDef clock;
RCC_GetClocksFreq(&clock);
freq[0] = clock.SYSCLK_Frequency/1000000;
freq[1] = clock.HCLK_Frequency/1000000;
freq[2] = clock.PCLK1_Frequency/1000000;
freq[3] = clock.PCLK2_Frequency/1000000;
freq[4] = clock.ADCCLK_Frequency/1000000;
#endif
#ifdef GD32
freq[0] = rcu_clock_freq_get(CK_SYS)/1000000;
freq[1] = rcu_clock_freq_get(CK_AHB)/1000000;
freq[2] = rcu_clock_freq_get(CK_APB1)/1000000;
freq[3] = rcu_clock_freq_get(CK_APB2)/1000000;
#ifdef SUPPORT_ADC_FREQ_GET_API
freq[4] = rcu_clock_freq_get(CK_ADC)/1000000;
#else
freq[4] = freq[3] /((((ADC_SYNCCTL>>16)&0x07)+1)*2);
#endif
#endif
printf("freq: SYS[%d MHz] AHB[%d MHz] APB1[%d MHz] APB2[%d MHz] ADC[%d MHz]\r\n",
freq[0], freq[1], freq[2], freq[3], freq[4]);
#endif
}
1秒打印一次。
系统频率打印测试结果