feat: 完成 can 初测
This commit is contained in:
@@ -74,13 +74,13 @@
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* add user code begin NonMaskableInt_IRQ 0 */
|
||||
/* add user code begin NonMaskableInt_IRQ 0 */
|
||||
|
||||
/* add user code end NonMaskableInt_IRQ 0 */
|
||||
/* add user code end NonMaskableInt_IRQ 0 */
|
||||
|
||||
/* add user code begin NonMaskableInt_IRQ 1 */
|
||||
/* add user code begin NonMaskableInt_IRQ 1 */
|
||||
|
||||
/* add user code end NonMaskableInt_IRQ 1 */
|
||||
/* add user code end NonMaskableInt_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,15 +90,15 @@ void NMI_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 */
|
||||
/* go to infinite loop when hard fault exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_HardFault_IRQ 0 */
|
||||
/* add user code end HardFault_IRQ 0 */
|
||||
/* go to infinite loop when hard fault exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_HardFault_IRQ 0 */
|
||||
|
||||
/* add user code end W1_HardFault_IRQ 0 */
|
||||
}
|
||||
/* add user code end W1_HardFault_IRQ 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,15 +108,15 @@ void HardFault_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 */
|
||||
/* go to infinite loop when memory manage exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_MemoryManagement_IRQ 0 */
|
||||
/* add user code end MemoryManagement_IRQ 0 */
|
||||
/* go to infinite loop when memory manage exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_MemoryManagement_IRQ 0 */
|
||||
|
||||
/* add user code end W1_MemoryManagement_IRQ 0 */
|
||||
}
|
||||
/* add user code end W1_MemoryManagement_IRQ 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,15 +126,15 @@ void MemManage_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 */
|
||||
/* go to infinite loop when bus fault exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_BusFault_IRQ 0 */
|
||||
/* add user code end BusFault_IRQ 0 */
|
||||
/* go to infinite loop when bus fault exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_BusFault_IRQ 0 */
|
||||
|
||||
/* add user code end W1_BusFault_IRQ 0 */
|
||||
}
|
||||
/* add user code end W1_BusFault_IRQ 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,15 +144,15 @@ void BusFault_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 */
|
||||
/* go to infinite loop when usage fault exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_UsageFault_IRQ 0 */
|
||||
/* add user code end UsageFault_IRQ 0 */
|
||||
/* go to infinite loop when usage fault exception occurs */
|
||||
while (1) {
|
||||
/* add user code begin W1_UsageFault_IRQ 0 */
|
||||
|
||||
/* add user code end W1_UsageFault_IRQ 0 */
|
||||
}
|
||||
/* add user code end W1_UsageFault_IRQ 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,12 +162,12 @@ void UsageFault_Handler(void)
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* add user code begin SVCall_IRQ 0 */
|
||||
/* add user code begin SVCall_IRQ 0 */
|
||||
|
||||
/* add user code end SVCall_IRQ 0 */
|
||||
/* add user code begin SVCall_IRQ 1 */
|
||||
/* add user code end SVCall_IRQ 0 */
|
||||
/* add user code begin SVCall_IRQ 1 */
|
||||
|
||||
/* add user code end SVCall_IRQ 1 */
|
||||
/* add user code end SVCall_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,12 +177,12 @@ void SVC_Handler(void)
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* add user code begin DebugMonitor_IRQ 0 */
|
||||
/* add user code begin DebugMonitor_IRQ 0 */
|
||||
|
||||
/* add user code end DebugMonitor_IRQ 0 */
|
||||
/* add user code begin DebugMonitor_IRQ 1 */
|
||||
/* add user code end DebugMonitor_IRQ 0 */
|
||||
/* add user code begin DebugMonitor_IRQ 1 */
|
||||
|
||||
/* add user code end DebugMonitor_IRQ 1 */
|
||||
/* add user code end DebugMonitor_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,12 +192,32 @@ void DebugMon_Handler(void)
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* add user code begin PendSV_IRQ 0 */
|
||||
/* add user code begin PendSV_IRQ 0 */
|
||||
|
||||
/* add user code end PendSV_IRQ 0 */
|
||||
/* add user code begin PendSV_IRQ 1 */
|
||||
/* add user code end PendSV_IRQ 0 */
|
||||
/* add user code begin PendSV_IRQ 1 */
|
||||
|
||||
/* add user code end PendSV_IRQ 1 */
|
||||
/* add user code end PendSV_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles USB Low Priority or CAN1 RX0 handler.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void USBFS_L_CAN1_RX0_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin USBFS_L_CAN1_RX0_IRQ 0 */
|
||||
if (SET == can_flag_get(CAN1, CAN_RF0MN_FLAG)) {
|
||||
can_rx_message_type rx_message_struct;
|
||||
can_message_receive(CAN1, CAN_RX_FIFO0, &rx_message_struct);
|
||||
lwprintf("CAN1 RECV: ID = 0x%X\r\n", rx_message_struct.standard_id);
|
||||
can_flag_clear(CAN1, CAN_RF0MN_FLAG);
|
||||
}
|
||||
/* add user code end USBFS_L_CAN1_RX0_IRQ 0 */
|
||||
/* add user code begin USBFS_L_CAN1_RX0_IRQ 1 */
|
||||
|
||||
/* add user code end USBFS_L_CAN1_RX0_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,12 +227,12 @@ void PendSV_Handler(void)
|
||||
*/
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin USART1_IRQ 0 */
|
||||
/* add user code begin USART1_IRQ 0 */
|
||||
|
||||
/* add user code end USART1_IRQ 0 */
|
||||
/* add user code begin USART1_IRQ 1 */
|
||||
/* add user code end USART1_IRQ 0 */
|
||||
/* add user code begin USART1_IRQ 1 */
|
||||
|
||||
/* add user code end USART1_IRQ 1 */
|
||||
/* add user code end USART1_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,15 +242,15 @@ void USART1_IRQHandler(void)
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin USART2_IRQ 0 */
|
||||
if (SET == usart_flag_get(USART2, USART_RDBF_FLAG)) {
|
||||
usart_data_receive(USART2);
|
||||
usart_flag_clear(USART2, USART_RDBF_FLAG);
|
||||
}
|
||||
/* add user code end USART2_IRQ 0 */
|
||||
/* add user code begin USART2_IRQ 1 */
|
||||
/* add user code begin USART2_IRQ 0 */
|
||||
if (SET == usart_flag_get(USART2, USART_RDBF_FLAG)) {
|
||||
usart_data_receive(USART2);
|
||||
usart_flag_clear(USART2, USART_RDBF_FLAG);
|
||||
}
|
||||
/* add user code end USART2_IRQ 0 */
|
||||
/* add user code begin USART2_IRQ 1 */
|
||||
|
||||
/* add user code end USART2_IRQ 1 */
|
||||
/* add user code end USART2_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,12 +260,12 @@ void USART2_IRQHandler(void)
|
||||
*/
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin USART3_IRQ 0 */
|
||||
/* add user code begin USART3_IRQ 0 */
|
||||
|
||||
/* add user code end USART3_IRQ 0 */
|
||||
/* add user code begin USART3_IRQ 1 */
|
||||
/* add user code end USART3_IRQ 0 */
|
||||
/* add user code begin USART3_IRQ 1 */
|
||||
|
||||
/* add user code end USART3_IRQ 1 */
|
||||
/* add user code end USART3_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,15 +275,39 @@ void USART3_IRQHandler(void)
|
||||
*/
|
||||
void TMR6_GLOBAL_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin TMR6_GLOBAL_IRQ 0 */
|
||||
static uint64_t i = 0;
|
||||
if (SET == tmr_flag_get(TMR6, TMR_OVF_FLAG)) {
|
||||
tmr_flag_clear(TMR6, TMR_OVF_FLAG);
|
||||
}
|
||||
/* add user code end TMR6_GLOBAL_IRQ 0 */
|
||||
/* add user code begin TMR6_GLOBAL_IRQ 1 */
|
||||
/* add user code begin TMR6_GLOBAL_IRQ 0 */
|
||||
if (SET == tmr_flag_get(TMR6, TMR_OVF_FLAG)) {
|
||||
tmr_flag_clear(TMR6, TMR_OVF_FLAG);
|
||||
}
|
||||
/* add user code end TMR6_GLOBAL_IRQ 0 */
|
||||
/* add user code begin TMR6_GLOBAL_IRQ 1 */
|
||||
|
||||
/* add user code end TMR6_GLOBAL_IRQ 1 */
|
||||
/* add user code end TMR6_GLOBAL_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles CAN2 RX0 handler.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void CAN2_RX0_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin CAN2_RX0_IRQ 0 */
|
||||
if (SET == can_flag_get(CAN2, CAN_RF0MN_FLAG)) {
|
||||
can_rx_message_type rx_message_struct;
|
||||
can_message_receive(CAN2, CAN_RX_FIFO0, &rx_message_struct);
|
||||
lwprintf("CAN2 RECV: ID = 0x%X\r\n", rx_message_struct.standard_id);
|
||||
lwprintf("---------------------\r\n| ");
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
lwprintf("0x%02X |", rx_message_struct.data[i]);
|
||||
}
|
||||
lwprintf("\r\n---------------------\r\n");
|
||||
can_flag_clear(CAN2, CAN_RF0MN_FLAG);
|
||||
}
|
||||
/* add user code end CAN2_RX0_IRQ 0 */
|
||||
/* add user code begin CAN2_RX0_IRQ 1 */
|
||||
|
||||
/* add user code end CAN2_RX0_IRQ 1 */
|
||||
}
|
||||
|
||||
/* add user code begin 1 */
|
||||
|
||||
@@ -220,10 +220,12 @@ void wk_nvic_config(void)
|
||||
{
|
||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||
|
||||
nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0, 0);
|
||||
nvic_irq_enable(USART1_IRQn, 1, 0);
|
||||
nvic_irq_enable(USART2_IRQn, 1, 0);
|
||||
nvic_irq_enable(USART3_IRQn, 1, 0);
|
||||
nvic_irq_enable(TMR6_GLOBAL_IRQn, 0, 0);
|
||||
nvic_irq_enable(CAN2_RX0_IRQn, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -741,13 +743,13 @@ void wk_tmr11_init(void)
|
||||
gpio_init(GPIOB, &gpio_init_struct);
|
||||
|
||||
/* configure counter settings */
|
||||
tmr_base_init(TMR11, 65535, 0);
|
||||
tmr_base_init(TMR11, 2399, 99);
|
||||
tmr_cnt_dir_set(TMR11, TMR_COUNT_UP);
|
||||
tmr_clock_source_div_set(TMR11, TMR_CLOCK_DIV1);
|
||||
tmr_period_buffer_enable(TMR11, FALSE);
|
||||
|
||||
/* configure channel 1 output settings */
|
||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||
tmr_output_struct.oc_output_state = TRUE;
|
||||
tmr_output_struct.occ_output_state = FALSE;
|
||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||
@@ -758,6 +760,8 @@ void wk_tmr11_init(void)
|
||||
tmr_channel_value_set(TMR11, TMR_SELECT_CHANNEL_1, 0);
|
||||
tmr_output_channel_buffer_enable(TMR11, TMR_SELECT_CHANNEL_1, FALSE);
|
||||
|
||||
tmr_output_channel_immediately_set(TMR11, TMR_SELECT_CHANNEL_1, FALSE);
|
||||
|
||||
tmr_counter_enable(TMR11, TRUE);
|
||||
|
||||
/* add user code begin tmr11_init 2 */
|
||||
@@ -910,8 +914,19 @@ void wk_can1_init(void)
|
||||
|
||||
can_filter_init(CAN1, &can_filter_init_struct);
|
||||
|
||||
/* add user code begin can1_init 2 */
|
||||
/**
|
||||
* Users need to configure CAN1 interrupt functions according to the actual application.
|
||||
* 1. Call the below function to enable the corresponding CAN1 interrupt.
|
||||
* --can_interrupt_enable(...)
|
||||
* 2. Add the user's interrupt handler code into the below function in the at32f403a_407_int.c file.
|
||||
* --void USBFS_L_CAN1_RX0_IRQHandler(void)
|
||||
*/
|
||||
|
||||
/*can1 rx0 interrupt config--------------------------------------------------------*/
|
||||
// can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
||||
|
||||
/* add user code begin can1_init 2 */
|
||||
can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
||||
/* add user code end can1_init 2 */
|
||||
}
|
||||
|
||||
@@ -988,8 +1003,19 @@ void wk_can2_init(void)
|
||||
|
||||
can_filter_init(CAN2, &can_filter_init_struct);
|
||||
|
||||
/* add user code begin can2_init 2 */
|
||||
/**
|
||||
* Users need to configure CAN2 interrupt functions according to the actual application.
|
||||
* 1. Call the below function to enable the corresponding CAN2 interrupt.
|
||||
* --can_interrupt_enable(...)
|
||||
* 2. Add the user's interrupt handler code into the below function in the at32f403a_407_int.c file.
|
||||
* --void CAN2_RX0_IRQHandler(void)
|
||||
*/
|
||||
|
||||
/*can2 rx0 interrupt config--------------------------------------------------------*/
|
||||
// can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE);
|
||||
|
||||
/* add user code begin can2_init 2 */
|
||||
can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE);
|
||||
/* add user code end can2_init 2 */
|
||||
}
|
||||
|
||||
|
||||
@@ -71,70 +71,70 @@
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* add user code begin 1 */
|
||||
by_debug_init();
|
||||
/* add user code end 1 */
|
||||
/* add user code begin 1 */
|
||||
by_debug_init();
|
||||
/* add user code end 1 */
|
||||
|
||||
/* system clock config. */
|
||||
wk_system_clock_config();
|
||||
/* system clock config. */
|
||||
wk_system_clock_config();
|
||||
|
||||
/* config periph clock. */
|
||||
wk_periph_clock_config();
|
||||
/* config periph clock. */
|
||||
wk_periph_clock_config();
|
||||
|
||||
/* init debug function. */
|
||||
wk_debug_config();
|
||||
/* init debug function. */
|
||||
wk_debug_config();
|
||||
|
||||
/* nvic config. */
|
||||
wk_nvic_config();
|
||||
/* nvic config. */
|
||||
wk_nvic_config();
|
||||
|
||||
/* init usart1 function. */
|
||||
wk_usart1_init();
|
||||
/* init usart1 function. */
|
||||
wk_usart1_init();
|
||||
|
||||
/* init usart2 function. */
|
||||
wk_usart2_init();
|
||||
/* init usart2 function. */
|
||||
wk_usart2_init();
|
||||
|
||||
/* init usart3 function. */
|
||||
wk_usart3_init();
|
||||
/* init usart3 function. */
|
||||
wk_usart3_init();
|
||||
|
||||
/* init i2c1 function. */
|
||||
wk_i2c1_init();
|
||||
/* init i2c1 function. */
|
||||
wk_i2c1_init();
|
||||
|
||||
/* init i2c2 function. */
|
||||
wk_i2c2_init();
|
||||
/* init i2c2 function. */
|
||||
wk_i2c2_init();
|
||||
|
||||
/* init adc1 function. */
|
||||
wk_adc1_init();
|
||||
/* init adc1 function. */
|
||||
wk_adc1_init();
|
||||
|
||||
/* init tmr6 function. */
|
||||
wk_tmr6_init();
|
||||
/* init tmr6 function. */
|
||||
wk_tmr6_init();
|
||||
|
||||
/* init tmr8 function. */
|
||||
wk_tmr8_init();
|
||||
/* init tmr8 function. */
|
||||
wk_tmr8_init();
|
||||
|
||||
/* init tmr11 function. */
|
||||
wk_tmr11_init();
|
||||
/* init tmr11 function. */
|
||||
wk_tmr11_init();
|
||||
|
||||
/* init tmr12 function. */
|
||||
wk_tmr12_init();
|
||||
/* init tmr12 function. */
|
||||
wk_tmr12_init();
|
||||
|
||||
/* init can1 function. */
|
||||
wk_can1_init();
|
||||
/* init can1 function. */
|
||||
wk_can1_init();
|
||||
|
||||
/* init can2 function. */
|
||||
wk_can2_init();
|
||||
/* init can2 function. */
|
||||
wk_can2_init();
|
||||
|
||||
/* init gpio function. */
|
||||
wk_gpio_config();
|
||||
/* init gpio function. */
|
||||
wk_gpio_config();
|
||||
|
||||
/* add user code begin 2 */
|
||||
DWT_Init();
|
||||
/* add user code begin 2 */
|
||||
DWT_Init();
|
||||
|
||||
lwprintf("init done!\r\n");
|
||||
/* add user code end 2 */
|
||||
lwprintf("init done!\r\n");
|
||||
/* add user code end 2 */
|
||||
|
||||
while (1) {
|
||||
/* add user code begin 3 */
|
||||
// DWT_Delay(1000000);
|
||||
/* add user code end 3 */
|
||||
}
|
||||
while (1) {
|
||||
/* add user code begin 3 */
|
||||
// DWT_Delay(1000000);
|
||||
/* add user code end 3 */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user