感谢雅特力及21IC论坛提供开发板进行评测学习。F423系列芯片外设资源十分丰富,DAC,USB-OTG,CAN控制器应有尽有,256K/48K存储满足大多数仪表产品开发应用。
1、作为资源丰富的MCU,要充分发挥MCU实时性,使用操作系统是最好的选择,本次测试采用RTX系统,arm官方出品,是当前arm芯片上可用的速度最快的RTOS。
项目添加如下文件即可:
RTX的启动十分简单,如下所示:
osKernelInitialize(); // Initialize CMSIS-RTOS
thread_init();
if (osKernelGetState() == osKernelReady)
{
osKernelStart(); // Start thread execution
}
while (1)
{
}
2、为了调试方便,给程序添加一个SHELL接口,可以通过串口进行人机交互。底层移植主要是串口初始化和数据收发:
static void com_hal_init(uint8_t comMode, uint32_t ulBaudRate, com_parity_type eParity)
{
uint32_t us10TimerSv;
uint32_t ClocksPer2ms;
usart_data_bit_num_type dat_bits;
usart_stop_bit_num_type stop_bits;
usart_parity_selection_type parity;
com_pin_cfg();
set_u8(&ComObj, 0, sizeof(ComObj));
if (eParity == COM_PAR_ODD)
{
dat_bits = USART_DATA_9BITS;
stop_bits = USART_STOP_1_BIT;
parity = USART_PARITY_ODD;
}
else if (eParity == COM_PAR_EVEN)
{
dat_bits = USART_DATA_9BITS;
stop_bits = USART_STOP_1_BIT;
parity = USART_PARITY_EVEN;
}
else if (eParity == COM_PAR_NONE_2S)
{
dat_bits = USART_DATA_8BITS;
stop_bits = USART_STOP_2_BIT;
parity = USART_PARITY_NONE;
}
else
{
dat_bits = USART_DATA_8BITS;
stop_bits = USART_STOP_1_BIT;
parity = USART_PARITY_NONE;
}
// 11*3.5*(1E6)/ba/50 = 77*1E4/ba
if (ulBaudRate > 19200)
{
ClocksPer2ms = 1800 * ulBaudRate / 1000000 + 1;
if (ClocksPer2ms < 41)
ClocksPer2ms = 41;
else if (ClocksPer2ms > 255)
ClocksPer2ms = 255;
// TOI 时间设置
}
else
{
// Time-out Register ,TX-DLY=0, TX-TIMEOUT=40
// TOI 时间设置
}
// 报文通知延时
us10TimerSv = com_timer_cal(ulBaudRate, 11 * 5, 300, 20000);
ComObj.rcv_end_time_sv = us10TimerSv / 100;
if (comMode > 0)
{
ComObj.rcv_end_time_sv++;
}
usart_init(comPORT, ulBaudRate, dat_bits, stop_bits);
usart_parity_selection_config(comPORT, parity);
usart_enable(comPORT, TRUE);
nvic_irq_set(COM_IRQn, 0x06, 1);
com_fun_init(comMode);
com_rx_enable(TRUE);
UART_TX_EN();
}
SHELL测试结果如下:
下面附上工程源码,有兴趣的小伙伴可以下载测试:
AT32F423_EVAL-LED.rar
(4.54 MB)
|