feat: 增加简单串口通信帧发送解析功能
This commit is contained in:
@@ -30,7 +30,8 @@
|
|||||||
"activityBar.background": "#4B2301",
|
"activityBar.background": "#4B2301",
|
||||||
"titleBar.activeBackground": "#693002",
|
"titleBar.activeBackground": "#693002",
|
||||||
"titleBar.activeForeground": "#FFF9F4"
|
"titleBar.activeForeground": "#FFF9F4"
|
||||||
}
|
},
|
||||||
|
"cortex-debug.variableUseNaturalFormat": false
|
||||||
},
|
},
|
||||||
"extensions": {
|
"extensions": {
|
||||||
}
|
}
|
||||||
|
|||||||
166
app/by_frame.c
Normal file
166
app/by_frame.c
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#include "by_frame.h"
|
||||||
|
|
||||||
|
#include "at32f403a_407.h"
|
||||||
|
#include "lwrb.h"
|
||||||
|
#include "by_crc16.h"
|
||||||
|
|
||||||
|
uint8_t frame_buffer_recv[(2 * (4 + BY_FRAME_DATA_NUM * sizeof(uint32_t))) + 1];
|
||||||
|
uint8_t frame_buffer_send[4 + BY_FRAME_DATA_NUM * sizeof(uint32_t)];
|
||||||
|
uint8_t frame_parse_busy;
|
||||||
|
lwrb_t lwrb_ctx;
|
||||||
|
|
||||||
|
void by_frame_init(void)
|
||||||
|
{
|
||||||
|
lwrb_init(&lwrb_ctx, frame_buffer_recv, sizeof(frame_buffer_recv)); // lwrb 最大元素数量为 buff 大小减一
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_frame_send(uint8_t cmd, uint32_t *data_array)
|
||||||
|
{
|
||||||
|
uint16_t crc_cal = 0;
|
||||||
|
const uint8_t data_byte_num = BY_FRAME_DATA_NUM * sizeof(uint32_t);
|
||||||
|
|
||||||
|
frame_buffer_send[0] = BY_FRAME_HEAD;
|
||||||
|
frame_buffer_send[1] = cmd;
|
||||||
|
|
||||||
|
// 当传入数组不足时,会发生越界情况
|
||||||
|
memcpy(frame_buffer_send + 2, data_array, data_byte_num);
|
||||||
|
crc_cal = by_crc16_calculate(frame_buffer_send, 2 + data_byte_num);
|
||||||
|
// crc_cal = crc16_check(frame_buffer_send, 2 + data_byte_num);
|
||||||
|
|
||||||
|
frame_buffer_send[2 + data_byte_num] = (uint8_t)(crc_cal >> 8);
|
||||||
|
frame_buffer_send[3 + data_byte_num] = (uint8_t)(crc_cal);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 4 + data_byte_num; i++) {
|
||||||
|
while (RESET == usart_flag_get(BY_FRAME_UART_INDEX, USART_TDBE_FLAG))
|
||||||
|
;
|
||||||
|
usart_data_transmit(BY_FRAME_UART_INDEX, frame_buffer_send[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param data_num
|
||||||
|
* @param data_array
|
||||||
|
* @todo 将其中写死的数据长度按照宏定义给出
|
||||||
|
*/
|
||||||
|
uint8_t by_frame_parse(uint8_t *cmd, uint32_t *data_array)
|
||||||
|
{
|
||||||
|
uint32_t len = lwrb_get_full(&lwrb_ctx); // 缓冲区大小
|
||||||
|
uint8_t status = 0; // 状态 0-未找到帧头 1-找到帧头 2-校验
|
||||||
|
uint16_t frame_start = 0; // 帧起始位置
|
||||||
|
uint8_t frame_buf[4 + BY_FRAME_DATA_NUM * sizeof(uint32_t)] = {0}; // 帧
|
||||||
|
uint8_t buf[(4 + BY_FRAME_DATA_NUM * sizeof(uint32_t)) * 2] = {0}; // 用于解析的数据块
|
||||||
|
const uint8_t data_byte_num = BY_FRAME_DATA_NUM * sizeof(uint32_t);
|
||||||
|
|
||||||
|
// if (len < 2 * (4 + data_byte_num)) { // FIXME 当传递相对值时会出现问题
|
||||||
|
// // 当前要求缓冲区满
|
||||||
|
// // (x) 缓冲区内长度小于帧长度,直接返回
|
||||||
|
// // 要是每次读的时候缓冲区内就只有前一帧的尾部和后一帧的头部,岂不是很尴尬
|
||||||
|
// // 是不是应该正确解析之后再把过的部分清空?但是是异步操作,实际上缓冲区内已经是新数据了
|
||||||
|
// // 可是直接读取 fifo 的话也是异步操作
|
||||||
|
// // 发的慢的话就很有可能有同步问题,导致一直解析不出来
|
||||||
|
// // 喵的,为啥不直接丢中断里解析算了
|
||||||
|
|
||||||
|
// // 目前的解决办法大概是缓冲区开两帧长的大小,然后一次性读完
|
||||||
|
// // 读取的时候不清除,等待新帧覆盖
|
||||||
|
// // 用 lwrb 的话就只能清除了
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
lwrb_sz_t valid_num = 0;
|
||||||
|
lwrb_sz_t invalid_num = 0;
|
||||||
|
uint8_t frame_head = BY_FRAME_HEAD;
|
||||||
|
|
||||||
|
// lwrb_find(&lwrb_ctx, &frame_head, 1, 0, &invalid_num);
|
||||||
|
// lwrb_skip(&lwrb_ctx, invalid_num);
|
||||||
|
// // TODO 优化逻辑,先找 0xEF,判断缓冲区里帧头后的长度足够则进入解析
|
||||||
|
// // 从环形缓冲区里读取数据,仅读取一个帧长
|
||||||
|
// lwrb_read(&lwrb_ctx, buf, 4 + BY_FRAME_DATA_NUM * sizeof(uint32_t));
|
||||||
|
|
||||||
|
// 如果没找到帧头,跳出
|
||||||
|
if (!lwrb_find(&lwrb_ctx, &frame_head, 1, 0, &invalid_num)) {
|
||||||
|
lwrb_skip(&lwrb_ctx, len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_num = len - invalid_num; // 从帧头开始,剩下的数据长度
|
||||||
|
lwrb_skip(&lwrb_ctx, invalid_num);
|
||||||
|
|
||||||
|
// 如果没有足够的数据,跳出
|
||||||
|
if (valid_num < 4 + data_byte_num) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lwrb_read(&lwrb_ctx, buf, 4 + data_byte_num);
|
||||||
|
|
||||||
|
// 递归解析有效帧
|
||||||
|
while (1) {
|
||||||
|
if (0 == status) // 没找到帧头
|
||||||
|
{
|
||||||
|
// 读到最后一个元素还没找到帧头
|
||||||
|
if (frame_start >= len - 2) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
uint16_t temp = (buf[frame_start] | (buf[frame_start + 1] << 8));
|
||||||
|
frame_start++;
|
||||||
|
|
||||||
|
// 递归寻找帧头,现在只有一个帧头了,摆大烂不想改就这样了
|
||||||
|
if (BY_FRAME_HEAD == (uint8_t)(temp & 0xFF)) {
|
||||||
|
status = 1; // 找到了好耶
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始读数据
|
||||||
|
if (1 == status) {
|
||||||
|
// 剩下的数据不够组成一帧
|
||||||
|
if ((frame_start + 4 + data_byte_num - 1) > len) {
|
||||||
|
// 解析出错,缓冲区中没有有效帧
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
// 复制到帧缓冲区,减一是因为之前多加了一次
|
||||||
|
memcpy(frame_buf, buf + frame_start - 1, 4 + data_byte_num);
|
||||||
|
status = 2;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (2 == status) // 校验 CRC
|
||||||
|
{
|
||||||
|
uint16_t crc_cal = by_crc16_calculate(frame_buf, 2 + data_byte_num);
|
||||||
|
if ((frame_buf[2 + data_byte_num] << 8 | frame_buf[2 + data_byte_num + 1]) == crc_cal) {
|
||||||
|
// 解析成功了✌
|
||||||
|
|
||||||
|
// 复制数据
|
||||||
|
if (NULL != (frame_buf + 2)) {
|
||||||
|
*cmd = frame_buf[1];
|
||||||
|
memcpy(data_array, frame_buf + 2, data_byte_num);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
status = 0;
|
||||||
|
// 这样无法应对连续帧之间缺字节的的问题,但是减少了重新遍历寻找帧头的时间
|
||||||
|
// frame_start += (8 - 1);
|
||||||
|
// 从上一个帧头之后开始解析
|
||||||
|
frame_start += (2 - 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_frame_parse_uart_handle(uint8_t data)
|
||||||
|
{
|
||||||
|
lwrb_write(&lwrb_ctx, &data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 定时器回调,用于接收超时判断 1ms 调用一次
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void by_frame_parse_timer_handle(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
24
app/by_frame.h
Normal file
24
app/by_frame.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef _BY_FRAME_H__
|
||||||
|
#define _BY_FRAME_H__
|
||||||
|
|
||||||
|
/* BY_TINY_FRAME 的超级减配版本(好吧基本上完全没有关系)
|
||||||
|
* 主要是等应答还是挺慢的,写数据场景只需要下位机校验数据合理性即可,读数据等应答即可
|
||||||
|
* 并且需要同步的参数并不多,所以考虑直接使用定长的特定结构的帧,一帧全部下发
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "at32f403a_407.h"
|
||||||
|
|
||||||
|
#define BY_FRAME_HEAD (0XEB)
|
||||||
|
|
||||||
|
#define BY_FRAME_UART_INDEX (USART3)
|
||||||
|
|
||||||
|
#define BY_FRAME_DATA_NUM (3)
|
||||||
|
|
||||||
|
extern void by_frame_init(void);
|
||||||
|
void by_frame_send(uint8_t cmd, uint32_t *data_array);
|
||||||
|
uint8_t by_frame_parse(uint8_t *cmd, uint32_t *data_array);
|
||||||
|
extern void by_frame_parse_uart_handle(uint8_t data);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
/* private includes ----------------------------------------------------------*/
|
/* private includes ----------------------------------------------------------*/
|
||||||
/* add user code begin private includes */
|
/* add user code begin private includes */
|
||||||
#include "by_debug.h"
|
#include "by_debug.h"
|
||||||
|
#include "by_frame.h"
|
||||||
/* add user code end private includes */
|
/* add user code end private includes */
|
||||||
|
|
||||||
/* private typedef -----------------------------------------------------------*/
|
/* private typedef -----------------------------------------------------------*/
|
||||||
@@ -68,10 +69,10 @@
|
|||||||
/* add user code end external variables */
|
/* add user code end external variables */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles nmi exception.
|
* @brief this function handles nmi exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void NMI_Handler(void)
|
void NMI_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin NonMaskableInt_IRQ 0 */
|
/* add user code begin NonMaskableInt_IRQ 0 */
|
||||||
@@ -84,18 +85,17 @@ void NMI_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles hard fault exception.
|
* @brief this function handles hard fault exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void HardFault_Handler(void)
|
void HardFault_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin HardFault_IRQ 0 */
|
/* add user code begin HardFault_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end HardFault_IRQ 0 */
|
/* add user code end HardFault_IRQ 0 */
|
||||||
/* go to infinite loop when hard fault exception occurs */
|
/* go to infinite loop when hard fault exception occurs */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
/* add user code begin W1_HardFault_IRQ 0 */
|
/* add user code begin W1_HardFault_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end W1_HardFault_IRQ 0 */
|
/* add user code end W1_HardFault_IRQ 0 */
|
||||||
@@ -103,18 +103,17 @@ void HardFault_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles memory manage exception.
|
* @brief this function handles memory manage exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void MemManage_Handler(void)
|
void MemManage_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin MemoryManagement_IRQ 0 */
|
/* add user code begin MemoryManagement_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end MemoryManagement_IRQ 0 */
|
/* add user code end MemoryManagement_IRQ 0 */
|
||||||
/* go to infinite loop when memory manage exception occurs */
|
/* go to infinite loop when memory manage exception occurs */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
/* add user code begin W1_MemoryManagement_IRQ 0 */
|
/* add user code begin W1_MemoryManagement_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end W1_MemoryManagement_IRQ 0 */
|
/* add user code end W1_MemoryManagement_IRQ 0 */
|
||||||
@@ -122,18 +121,17 @@ void MemManage_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles bus fault exception.
|
* @brief this function handles bus fault exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void BusFault_Handler(void)
|
void BusFault_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin BusFault_IRQ 0 */
|
/* add user code begin BusFault_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end BusFault_IRQ 0 */
|
/* add user code end BusFault_IRQ 0 */
|
||||||
/* go to infinite loop when bus fault exception occurs */
|
/* go to infinite loop when bus fault exception occurs */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
/* add user code begin W1_BusFault_IRQ 0 */
|
/* add user code begin W1_BusFault_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end W1_BusFault_IRQ 0 */
|
/* add user code end W1_BusFault_IRQ 0 */
|
||||||
@@ -141,18 +139,17 @@ void BusFault_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles usage fault exception.
|
* @brief this function handles usage fault exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void UsageFault_Handler(void)
|
void UsageFault_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin UsageFault_IRQ 0 */
|
/* add user code begin UsageFault_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end UsageFault_IRQ 0 */
|
/* add user code end UsageFault_IRQ 0 */
|
||||||
/* go to infinite loop when usage fault exception occurs */
|
/* go to infinite loop when usage fault exception occurs */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
/* add user code begin W1_UsageFault_IRQ 0 */
|
/* add user code begin W1_UsageFault_IRQ 0 */
|
||||||
|
|
||||||
/* add user code end W1_UsageFault_IRQ 0 */
|
/* add user code end W1_UsageFault_IRQ 0 */
|
||||||
@@ -160,10 +157,10 @@ void UsageFault_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles svcall exception.
|
* @brief this function handles svcall exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void SVC_Handler(void)
|
void SVC_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin SVCall_IRQ 0 */
|
/* add user code begin SVCall_IRQ 0 */
|
||||||
@@ -175,10 +172,10 @@ void SVC_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles debug monitor exception.
|
* @brief this function handles debug monitor exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void DebugMon_Handler(void)
|
void DebugMon_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin DebugMonitor_IRQ 0 */
|
/* add user code begin DebugMonitor_IRQ 0 */
|
||||||
@@ -190,10 +187,10 @@ void DebugMon_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles pendsv_handler exception.
|
* @brief this function handles pendsv_handler exception.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void PendSV_Handler(void)
|
void PendSV_Handler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin PendSV_IRQ 0 */
|
/* add user code begin PendSV_IRQ 0 */
|
||||||
@@ -205,10 +202,10 @@ void PendSV_Handler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles USB Low Priority or CAN1 RX0 handler.
|
* @brief this function handles USB Low Priority or CAN1 RX0 handler.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void USBFS_L_CAN1_RX0_IRQHandler(void)
|
void USBFS_L_CAN1_RX0_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin USBFS_L_CAN1_RX0_IRQ 0 */
|
/* add user code begin USBFS_L_CAN1_RX0_IRQ 0 */
|
||||||
@@ -225,10 +222,10 @@ void USBFS_L_CAN1_RX0_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles USART1 handler.
|
* @brief this function handles USART1 handler.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void USART1_IRQHandler(void)
|
void USART1_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin USART1_IRQ 0 */
|
/* add user code begin USART1_IRQ 0 */
|
||||||
@@ -243,10 +240,10 @@ void USART1_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles USART2 handler.
|
* @brief this function handles USART2 handler.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void USART2_IRQHandler(void)
|
void USART2_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin USART2_IRQ 0 */
|
/* add user code begin USART2_IRQ 0 */
|
||||||
@@ -261,10 +258,10 @@ void USART2_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles USART3 handler.
|
* @brief this function handles USART3 handler.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void USART3_IRQHandler(void)
|
void USART3_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin USART3_IRQ 0 */
|
/* add user code begin USART3_IRQ 0 */
|
||||||
@@ -279,10 +276,10 @@ void USART3_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles TMR6 handler.
|
* @brief this function handles TMR6 handler.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void TMR6_GLOBAL_IRQHandler(void)
|
void TMR6_GLOBAL_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin TMR6_GLOBAL_IRQ 0 */
|
/* add user code begin TMR6_GLOBAL_IRQ 0 */
|
||||||
@@ -296,10 +293,10 @@ void TMR6_GLOBAL_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this function handles CAN2 RX0 handler.
|
* @brief this function handles CAN2 RX0 handler.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void CAN2_RX0_IRQHandler(void)
|
void CAN2_RX0_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* add user code begin CAN2_RX0_IRQ 0 */
|
/* add user code begin CAN2_RX0_IRQ 0 */
|
||||||
|
|||||||
@@ -62,23 +62,23 @@
|
|||||||
/* add user code end 0 */
|
/* add user code end 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief system clock config program
|
* @brief system clock config program
|
||||||
* @note the system clock is configured as follow:
|
* @note the system clock is configured as follow:
|
||||||
* system clock (sclk) = hick / 12 * pll_mult
|
* system clock (sclk) = hick / 12 * pll_mult
|
||||||
* system clock source = HICK_VALUE
|
* system clock source = HICK_VALUE
|
||||||
* - hext = HEXT_VALUE
|
* - hext = HEXT_VALUE
|
||||||
* - sclk = 240000000
|
* - sclk = 240000000
|
||||||
* - ahbdiv = 1
|
* - ahbdiv = 1
|
||||||
* - ahbclk = 240000000
|
* - ahbclk = 240000000
|
||||||
* - apb1div = 2
|
* - apb1div = 2
|
||||||
* - apb1clk = 120000000
|
* - apb1clk = 120000000
|
||||||
* - apb2div = 2
|
* - apb2div = 2
|
||||||
* - apb2clk = 120000000
|
* - apb2clk = 120000000
|
||||||
* - pll_mult = 60
|
* - pll_mult = 60
|
||||||
* - pll_range = GT72MHZ (greater than 72 mhz)
|
* - pll_range = GT72MHZ (greater than 72 mhz)
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_system_clock_config(void)
|
void wk_system_clock_config(void)
|
||||||
{
|
{
|
||||||
/* reset crm */
|
/* reset crm */
|
||||||
@@ -88,24 +88,21 @@ void wk_system_clock_config(void)
|
|||||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE);
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE);
|
||||||
|
|
||||||
/* wait till lick is ready */
|
/* wait till lick is ready */
|
||||||
while(crm_flag_get(CRM_LICK_STABLE_FLAG) != SET)
|
while (crm_flag_get(CRM_LICK_STABLE_FLAG) != SET) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable hext */
|
/* enable hext */
|
||||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
|
||||||
|
|
||||||
/* wait till hext is ready */
|
/* wait till hext is ready */
|
||||||
while(crm_hext_stable_wait() == ERROR)
|
while (crm_hext_stable_wait() == ERROR) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable hick */
|
/* enable hick */
|
||||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE);
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE);
|
||||||
|
|
||||||
/* wait till hick is ready */
|
/* wait till hick is ready */
|
||||||
while(crm_flag_get(CRM_HICK_STABLE_FLAG) != SET)
|
while (crm_flag_get(CRM_HICK_STABLE_FLAG) != SET) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config pll clock resource */
|
/* config pll clock resource */
|
||||||
@@ -115,8 +112,7 @@ void wk_system_clock_config(void)
|
|||||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
||||||
|
|
||||||
/* wait till pll is ready */
|
/* wait till pll is ready */
|
||||||
while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
|
while (crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config ahbclk */
|
/* config ahbclk */
|
||||||
@@ -135,8 +131,7 @@ void wk_system_clock_config(void)
|
|||||||
crm_sysclk_switch(CRM_SCLK_PLL);
|
crm_sysclk_switch(CRM_SCLK_PLL);
|
||||||
|
|
||||||
/* wait till pll is used as system clock source */
|
/* wait till pll is used as system clock source */
|
||||||
while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
|
while (crm_sysclk_switch_status_get() != CRM_SCLK_PLL) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disable auto step mode */
|
/* disable auto step mode */
|
||||||
@@ -147,10 +142,10 @@ void wk_system_clock_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief config periph clock
|
* @brief config periph clock
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_periph_clock_config(void)
|
void wk_periph_clock_config(void)
|
||||||
{
|
{
|
||||||
/* enable crc periph clock */
|
/* enable crc periph clock */
|
||||||
@@ -206,10 +201,10 @@ void wk_periph_clock_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init debug function.
|
* @brief init debug function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_debug_config(void)
|
void wk_debug_config(void)
|
||||||
{
|
{
|
||||||
/* jtag-dp disabled and sw-dp enabled */
|
/* jtag-dp disabled and sw-dp enabled */
|
||||||
@@ -217,10 +212,10 @@ void wk_debug_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief nvic config
|
* @brief nvic config
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_nvic_config(void)
|
void wk_nvic_config(void)
|
||||||
{
|
{
|
||||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||||
@@ -234,10 +229,10 @@ void wk_nvic_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init gpio_input/gpio_output/gpio_analog/eventout function.
|
* @brief init gpio_input/gpio_output/gpio_analog/eventout function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_gpio_config(void)
|
void wk_gpio_config(void)
|
||||||
{
|
{
|
||||||
/* add user code begin gpio_config 0 */
|
/* add user code begin gpio_config 0 */
|
||||||
@@ -271,10 +266,10 @@ void wk_gpio_config(void)
|
|||||||
gpio_bits_reset(GPIOC, GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3);
|
gpio_bits_reset(GPIOC, GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3);
|
||||||
|
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3;
|
gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
/* add user code begin gpio_config 2 */
|
/* add user code begin gpio_config 2 */
|
||||||
@@ -283,10 +278,10 @@ void wk_gpio_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init i2c1 function.
|
* @brief init i2c1 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_i2c1_init(void)
|
void wk_i2c1_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin i2c1_init 0 */
|
/* add user code begin i2c1_init 0 */
|
||||||
@@ -302,19 +297,19 @@ void wk_i2c1_init(void)
|
|||||||
/* add user code end i2c1_init 1 */
|
/* add user code end i2c1_init 1 */
|
||||||
|
|
||||||
/* configure the SCL pin */
|
/* configure the SCL pin */
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_6;
|
gpio_init_struct.gpio_pins = GPIO_PINS_6;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the SDA pin */
|
/* configure the SDA pin */
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_7;
|
gpio_init_struct.gpio_pins = GPIO_PINS_7;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
i2c_init(I2C1, I2C_FSMODE_DUTY_2_1, 100000);
|
i2c_init(I2C1, I2C_FSMODE_DUTY_2_1, 100000);
|
||||||
@@ -331,10 +326,10 @@ void wk_i2c1_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init i2c2 function.
|
* @brief init i2c2 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_i2c2_init(void)
|
void wk_i2c2_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin i2c2_init 0 */
|
/* add user code begin i2c2_init 0 */
|
||||||
@@ -350,19 +345,19 @@ void wk_i2c2_init(void)
|
|||||||
/* add user code end i2c2_init 1 */
|
/* add user code end i2c2_init 1 */
|
||||||
|
|
||||||
/* configure the SCL pin */
|
/* configure the SCL pin */
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the SDA pin */
|
/* configure the SDA pin */
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
i2c_init(I2C2, I2C_FSMODE_DUTY_2_1, 100000);
|
i2c_init(I2C2, I2C_FSMODE_DUTY_2_1, 100000);
|
||||||
@@ -379,10 +374,10 @@ void wk_i2c2_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init usart1 function
|
* @brief init usart1 function
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_usart1_init(void)
|
void wk_usart1_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin usart1_init 0 */
|
/* add user code begin usart1_init 0 */
|
||||||
@@ -398,18 +393,18 @@ void wk_usart1_init(void)
|
|||||||
|
|
||||||
/* configure the TX pin */
|
/* configure the TX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_9;
|
gpio_init_struct.gpio_pins = GPIO_PINS_9;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the RX pin */
|
/* configure the RX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure param */
|
/* configure param */
|
||||||
@@ -431,15 +426,15 @@ void wk_usart1_init(void)
|
|||||||
usart_enable(USART1, TRUE);
|
usart_enable(USART1, TRUE);
|
||||||
|
|
||||||
/* add user code begin usart1_init 2 */
|
/* add user code begin usart1_init 2 */
|
||||||
|
usart_interrupt_enable(USART1, USART_RDBF_INT, TRUE);
|
||||||
/* add user code end usart1_init 2 */
|
/* add user code end usart1_init 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init usart2 function
|
* @brief init usart2 function
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_usart2_init(void)
|
void wk_usart2_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin usart2_init 0 */
|
/* add user code begin usart2_init 0 */
|
||||||
@@ -455,18 +450,18 @@ void wk_usart2_init(void)
|
|||||||
|
|
||||||
/* configure the TX pin */
|
/* configure the TX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the RX pin */
|
/* configure the RX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_3;
|
gpio_init_struct.gpio_pins = GPIO_PINS_3;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure param */
|
/* configure param */
|
||||||
@@ -493,10 +488,10 @@ void wk_usart2_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init usart3 function
|
* @brief init usart3 function
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_usart3_init(void)
|
void wk_usart3_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin usart3_init 0 */
|
/* add user code begin usart3_init 0 */
|
||||||
@@ -512,18 +507,18 @@ void wk_usart3_init(void)
|
|||||||
|
|
||||||
/* configure the TX pin */
|
/* configure the TX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the RX pin */
|
/* configure the RX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
gpio_pin_remap_config(USART3_GMUX_0001, TRUE);
|
gpio_pin_remap_config(USART3_GMUX_0001, TRUE);
|
||||||
@@ -552,10 +547,10 @@ void wk_usart3_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init tmr6 function.
|
* @brief init tmr6 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_tmr6_init(void)
|
void wk_tmr6_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin tmr6_init 0 */
|
/* add user code begin tmr6_init 0 */
|
||||||
@@ -590,10 +585,10 @@ void wk_tmr6_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init tmr8 function.
|
* @brief init tmr8 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_tmr8_init(void)
|
void wk_tmr8_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin tmr8_init 0 */
|
/* add user code begin tmr8_init 0 */
|
||||||
@@ -611,34 +606,34 @@ void wk_tmr8_init(void)
|
|||||||
/* add user code end tmr8_init 1 */
|
/* add user code end tmr8_init 1 */
|
||||||
|
|
||||||
/* configure the CH1 pin */
|
/* configure the CH1 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_6;
|
gpio_init_struct.gpio_pins = GPIO_PINS_6;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CH2 pin */
|
/* configure the CH2 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_7;
|
gpio_init_struct.gpio_pins = GPIO_PINS_7;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CH3 pin */
|
/* configure the CH3 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_8;
|
gpio_init_struct.gpio_pins = GPIO_PINS_8;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CH4 pin */
|
/* configure the CH4 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_9;
|
gpio_init_struct.gpio_pins = GPIO_PINS_9;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOC, &gpio_init_struct);
|
gpio_init(GPIOC, &gpio_init_struct);
|
||||||
|
|
||||||
@@ -654,64 +649,63 @@ void wk_tmr8_init(void)
|
|||||||
tmr_primary_mode_select(TMR8, TMR_PRIMARY_SEL_RESET);
|
tmr_primary_mode_select(TMR8, TMR_PRIMARY_SEL_RESET);
|
||||||
|
|
||||||
/* configure channel 1 output settings */
|
/* configure channel 1 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_1, 0);
|
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_1, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_1, FALSE);
|
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
|
|
||||||
/* configure channel 2 output settings */
|
/* configure channel 2 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_2, 0);
|
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_2, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_2, FALSE);
|
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_2, FALSE);
|
||||||
|
|
||||||
/* configure channel 3 output settings */
|
/* configure channel 3 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
|
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_3, 0);
|
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_3, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_3, FALSE);
|
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_3, FALSE);
|
||||||
|
|
||||||
/* configure channel 4 output settings */
|
/* configure channel 4 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_4, &tmr_output_struct);
|
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_4, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_4, 0);
|
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_4, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_4, FALSE);
|
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_4, FALSE);
|
||||||
|
|
||||||
/* configure break and dead-time settings */
|
/* configure break and dead-time settings */
|
||||||
tmr_brkdt_struct.brk_enable = FALSE;
|
tmr_brkdt_struct.brk_enable = FALSE;
|
||||||
tmr_brkdt_struct.auto_output_enable = FALSE;
|
tmr_brkdt_struct.auto_output_enable = FALSE;
|
||||||
tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW;
|
tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW;
|
||||||
tmr_brkdt_struct.fcsoen_state = FALSE;
|
tmr_brkdt_struct.fcsoen_state = FALSE;
|
||||||
tmr_brkdt_struct.fcsodis_state = FALSE;
|
tmr_brkdt_struct.fcsodis_state = FALSE;
|
||||||
tmr_brkdt_struct.wp_level = TMR_WP_OFF;
|
tmr_brkdt_struct.wp_level = TMR_WP_OFF;
|
||||||
tmr_brkdt_struct.deadtime = 0;
|
tmr_brkdt_struct.deadtime = 0;
|
||||||
tmr_brkdt_config(TMR8, &tmr_brkdt_struct);
|
tmr_brkdt_config(TMR8, &tmr_brkdt_struct);
|
||||||
|
|
||||||
|
|
||||||
tmr_output_enable(TMR8, TRUE);
|
tmr_output_enable(TMR8, TRUE);
|
||||||
|
|
||||||
tmr_counter_enable(TMR8, TRUE);
|
tmr_counter_enable(TMR8, TRUE);
|
||||||
@@ -722,10 +716,10 @@ void wk_tmr8_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init tmr11 function.
|
* @brief init tmr11 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_tmr11_init(void)
|
void wk_tmr11_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin tmr11_init 0 */
|
/* add user code begin tmr11_init 0 */
|
||||||
@@ -741,10 +735,10 @@ void wk_tmr11_init(void)
|
|||||||
/* add user code end tmr11_init 1 */
|
/* add user code end tmr11_init 1 */
|
||||||
|
|
||||||
/* configure the CH1 pin */
|
/* configure the CH1 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_9;
|
gpio_init_struct.gpio_pins = GPIO_PINS_9;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
@@ -755,13 +749,13 @@ void wk_tmr11_init(void)
|
|||||||
tmr_period_buffer_enable(TMR11, FALSE);
|
tmr_period_buffer_enable(TMR11, FALSE);
|
||||||
|
|
||||||
/* configure channel 1 output settings */
|
/* configure channel 1 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR11, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
tmr_output_channel_config(TMR11, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR11, TMR_SELECT_CHANNEL_1, 0);
|
tmr_channel_value_set(TMR11, TMR_SELECT_CHANNEL_1, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR11, TMR_SELECT_CHANNEL_1, FALSE);
|
tmr_output_channel_buffer_enable(TMR11, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
@@ -776,10 +770,10 @@ void wk_tmr11_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init tmr12 function.
|
* @brief init tmr12 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_tmr12_init(void)
|
void wk_tmr12_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin tmr12_init 0 */
|
/* add user code begin tmr12_init 0 */
|
||||||
@@ -795,18 +789,18 @@ void wk_tmr12_init(void)
|
|||||||
/* add user code end tmr12_init 1 */
|
/* add user code end tmr12_init 1 */
|
||||||
|
|
||||||
/* configure the CH1 pin */
|
/* configure the CH1 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_14;
|
gpio_init_struct.gpio_pins = GPIO_PINS_14;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CH2 pin */
|
/* configure the CH2 pin */
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_15;
|
gpio_init_struct.gpio_pins = GPIO_PINS_15;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
@@ -817,25 +811,25 @@ void wk_tmr12_init(void)
|
|||||||
tmr_period_buffer_enable(TMR12, FALSE);
|
tmr_period_buffer_enable(TMR12, FALSE);
|
||||||
|
|
||||||
/* configure channel 1 output settings */
|
/* configure channel 1 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_1, 0);
|
tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_1, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_1, FALSE);
|
tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_1, FALSE);
|
||||||
|
|
||||||
/* configure channel 2 output settings */
|
/* configure channel 2 output settings */
|
||||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||||
tmr_output_struct.oc_output_state = TRUE;
|
tmr_output_struct.oc_output_state = TRUE;
|
||||||
tmr_output_struct.occ_output_state = FALSE;
|
tmr_output_struct.occ_output_state = FALSE;
|
||||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||||
tmr_output_struct.oc_idle_state = FALSE;
|
tmr_output_struct.oc_idle_state = FALSE;
|
||||||
tmr_output_struct.occ_idle_state = FALSE;
|
tmr_output_struct.occ_idle_state = FALSE;
|
||||||
tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
||||||
tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_2, 0);
|
tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_2, 0);
|
||||||
tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_2, FALSE);
|
tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_2, FALSE);
|
||||||
@@ -848,10 +842,10 @@ void wk_tmr12_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init can1 function.
|
* @brief init can1 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_can1_init(void)
|
void wk_can1_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin can1_init 0 */
|
/* add user code begin can1_init 0 */
|
||||||
@@ -872,51 +866,51 @@ void wk_can1_init(void)
|
|||||||
|
|
||||||
/* configure the CAN1 TX pin */
|
/* configure the CAN1 TX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_12;
|
gpio_init_struct.gpio_pins = GPIO_PINS_12;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CAN1 RX pin */
|
/* configure the CAN1 RX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOA, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/*can_base_init--------------------------------------------------------------------*/
|
/*can_base_init--------------------------------------------------------------------*/
|
||||||
can_default_para_init(&can_base_struct);
|
can_default_para_init(&can_base_struct);
|
||||||
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
|
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
|
||||||
can_base_struct.ttc_enable = FALSE;
|
can_base_struct.ttc_enable = FALSE;
|
||||||
can_base_struct.aebo_enable = TRUE;
|
can_base_struct.aebo_enable = TRUE;
|
||||||
can_base_struct.aed_enable = TRUE;
|
can_base_struct.aed_enable = TRUE;
|
||||||
can_base_struct.prsf_enable = FALSE;
|
can_base_struct.prsf_enable = FALSE;
|
||||||
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
|
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
|
||||||
can_base_struct.mmssr_selection = CAN_SENDING_BY_ID;
|
can_base_struct.mmssr_selection = CAN_SENDING_BY_ID;
|
||||||
|
|
||||||
can_base_init(CAN1, &can_base_struct);
|
can_base_init(CAN1, &can_base_struct);
|
||||||
|
|
||||||
/*can_baudrate_setting-------------------------------------------------------------*/
|
/*can_baudrate_setting-------------------------------------------------------------*/
|
||||||
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
|
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
|
||||||
can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/
|
can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/
|
||||||
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
|
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
|
||||||
can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/
|
can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/
|
||||||
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
|
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
|
||||||
can_baudrate_set(CAN1, &can_baudrate_struct);
|
can_baudrate_set(CAN1, &can_baudrate_struct);
|
||||||
|
|
||||||
/*can_filter_0_config--------------------------------------------------------------*/
|
/*can_filter_0_config--------------------------------------------------------------*/
|
||||||
can_filter_init_struct.filter_activate_enable = TRUE;
|
can_filter_init_struct.filter_activate_enable = TRUE;
|
||||||
can_filter_init_struct.filter_number = 0;
|
can_filter_init_struct.filter_number = 0;
|
||||||
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
|
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
|
||||||
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
|
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
|
||||||
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
|
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
|
||||||
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
|
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
|
||||||
can_filter_init_struct.filter_id_high = 0x0 << 5;
|
can_filter_init_struct.filter_id_high = 0x0 << 5;
|
||||||
can_filter_init_struct.filter_id_low = 0x0 << 5;
|
can_filter_init_struct.filter_id_low = 0x0 << 5;
|
||||||
can_filter_init_struct.filter_mask_high = 0x0 << 5;
|
can_filter_init_struct.filter_mask_high = 0x0 << 5;
|
||||||
can_filter_init_struct.filter_mask_low = 0x0 << 5;
|
can_filter_init_struct.filter_mask_low = 0x0 << 5;
|
||||||
|
|
||||||
can_filter_init(CAN1, &can_filter_init_struct);
|
can_filter_init(CAN1, &can_filter_init_struct);
|
||||||
|
|
||||||
@@ -929,7 +923,7 @@ void wk_can1_init(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*can1 rx0 interrupt config--------------------------------------------------------*/
|
/*can1 rx0 interrupt config--------------------------------------------------------*/
|
||||||
//can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
// can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
||||||
|
|
||||||
/* add user code begin can1_init 2 */
|
/* add user code begin can1_init 2 */
|
||||||
can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
||||||
@@ -937,10 +931,10 @@ void wk_can1_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init can2 function.
|
* @brief init can2 function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_can2_init(void)
|
void wk_can2_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin can2_init 0 */
|
/* add user code begin can2_init 0 */
|
||||||
@@ -961,51 +955,51 @@ void wk_can2_init(void)
|
|||||||
|
|
||||||
/* configure the CAN2 TX pin */
|
/* configure the CAN2 TX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_13;
|
gpio_init_struct.gpio_pins = GPIO_PINS_13;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/* configure the CAN2 RX pin */
|
/* configure the CAN2 RX pin */
|
||||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
gpio_init_struct.gpio_pins = GPIO_PINS_12;
|
gpio_init_struct.gpio_pins = GPIO_PINS_12;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/*can_base_init--------------------------------------------------------------------*/
|
/*can_base_init--------------------------------------------------------------------*/
|
||||||
can_default_para_init(&can_base_struct);
|
can_default_para_init(&can_base_struct);
|
||||||
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
|
can_base_struct.mode_selection = CAN_MODE_COMMUNICATE;
|
||||||
can_base_struct.ttc_enable = FALSE;
|
can_base_struct.ttc_enable = FALSE;
|
||||||
can_base_struct.aebo_enable = TRUE;
|
can_base_struct.aebo_enable = TRUE;
|
||||||
can_base_struct.aed_enable = TRUE;
|
can_base_struct.aed_enable = TRUE;
|
||||||
can_base_struct.prsf_enable = FALSE;
|
can_base_struct.prsf_enable = FALSE;
|
||||||
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
|
can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED;
|
||||||
can_base_struct.mmssr_selection = CAN_SENDING_BY_ID;
|
can_base_struct.mmssr_selection = CAN_SENDING_BY_ID;
|
||||||
|
|
||||||
can_base_init(CAN2, &can_base_struct);
|
can_base_init(CAN2, &can_base_struct);
|
||||||
|
|
||||||
/*can_baudrate_setting-------------------------------------------------------------*/
|
/*can_baudrate_setting-------------------------------------------------------------*/
|
||||||
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
|
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
|
||||||
can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/
|
can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/
|
||||||
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
|
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
|
||||||
can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/
|
can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/
|
||||||
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
|
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
|
||||||
can_baudrate_set(CAN2, &can_baudrate_struct);
|
can_baudrate_set(CAN2, &can_baudrate_struct);
|
||||||
|
|
||||||
/*can_filter_0_config--------------------------------------------------------------*/
|
/*can_filter_0_config--------------------------------------------------------------*/
|
||||||
can_filter_init_struct.filter_activate_enable = TRUE;
|
can_filter_init_struct.filter_activate_enable = TRUE;
|
||||||
can_filter_init_struct.filter_number = 0;
|
can_filter_init_struct.filter_number = 0;
|
||||||
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
|
can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0;
|
||||||
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
|
can_filter_init_struct.filter_bit = CAN_FILTER_16BIT;
|
||||||
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
|
can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK;
|
||||||
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
|
/*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/
|
||||||
can_filter_init_struct.filter_id_high = 0x0 << 5;
|
can_filter_init_struct.filter_id_high = 0x0 << 5;
|
||||||
can_filter_init_struct.filter_id_low = 0x0 << 5;
|
can_filter_init_struct.filter_id_low = 0x0 << 5;
|
||||||
can_filter_init_struct.filter_mask_high = 0x0 << 5;
|
can_filter_init_struct.filter_mask_high = 0x0 << 5;
|
||||||
can_filter_init_struct.filter_mask_low = 0x0 << 5;
|
can_filter_init_struct.filter_mask_low = 0x0 << 5;
|
||||||
|
|
||||||
can_filter_init(CAN2, &can_filter_init_struct);
|
can_filter_init(CAN2, &can_filter_init_struct);
|
||||||
|
|
||||||
@@ -1018,7 +1012,7 @@ void wk_can2_init(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*can2 rx0 interrupt config--------------------------------------------------------*/
|
/*can2 rx0 interrupt config--------------------------------------------------------*/
|
||||||
//can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE);
|
// can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE);
|
||||||
|
|
||||||
/* add user code begin can2_init 2 */
|
/* add user code begin can2_init 2 */
|
||||||
can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE);
|
can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE);
|
||||||
@@ -1026,10 +1020,10 @@ void wk_can2_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init crc function.
|
* @brief init crc function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
void wk_crc_init(void)
|
void wk_crc_init(void)
|
||||||
{
|
{
|
||||||
/* add user code begin crc_init 0 */
|
/* add user code begin crc_init 0 */
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
#include "by_debug.h"
|
#include "by_debug.h"
|
||||||
#include "by_crc16.h"
|
#include "by_crc16.h"
|
||||||
|
#include "by_frame.h"
|
||||||
/* add user code end private includes */
|
/* add user code end private includes */
|
||||||
|
|
||||||
/* private typedef -----------------------------------------------------------*/
|
/* private typedef -----------------------------------------------------------*/
|
||||||
@@ -66,10 +67,10 @@
|
|||||||
/* add user code end 0 */
|
/* add user code end 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief main function.
|
* @brief main function.
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* add user code begin 1 */
|
/* add user code begin 1 */
|
||||||
@@ -137,12 +138,15 @@ int main(void)
|
|||||||
flash_ee_init();
|
flash_ee_init();
|
||||||
LOGD("eeprom init done");
|
LOGD("eeprom init done");
|
||||||
|
|
||||||
|
/* frame init */
|
||||||
|
by_frame_init();
|
||||||
|
LOGD("frame init done");
|
||||||
|
|
||||||
LOGI("init done");
|
LOGI("init done");
|
||||||
|
|
||||||
/* add user code end 2 */
|
/* add user code end 2 */
|
||||||
|
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
|
||||||
/* add user code begin 3 */
|
/* add user code begin 3 */
|
||||||
// DWT_Delay(1000000);
|
// DWT_Delay(1000000);
|
||||||
/* add user code end 3 */
|
/* add user code end 3 */
|
||||||
|
|||||||
Reference in New Issue
Block a user