feat: 完成 can 初测

This commit is contained in:
2024-04-13 22:52:03 +08:00
parent d90e5d0e61
commit 2200c58e43
7 changed files with 199 additions and 135 deletions

View File

@@ -7,8 +7,8 @@ Language: Cpp
###################################
UseTab: Never
IndentWidth: 4
TabWidth: 4
IndentWidth: 2
TabWidth: 2
ColumnLimit: 0
AccessModifierOffset: -4
NamespaceIndentation: All

View File

@@ -94,6 +94,11 @@
<ModeSub name="Channel1 mode" value="Output_CH1"/>
<ModeSub name="Activated" value="TRUE"/>
</Mode>
<Parameters>
<ParametersSub name="DividerValue" value="99"/>
<ParametersSub name="Period" value="2399"/>
<ParametersSub name="OCMode_1" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
</Parameters>
</TMR11>
<TMR12>
<Mode>
@@ -124,7 +129,7 @@
<CRM_IRQHandler>0;0;0</CRM_IRQHandler>
<ADC1_2_IRQHandler>0;0;0</ADC1_2_IRQHandler>
<USBFS_H_CAN1_TX_IRQHandler>0;0;0</USBFS_H_CAN1_TX_IRQHandler>
<USBFS_L_CAN1_RX0_IRQHandler>0;0;0</USBFS_L_CAN1_RX0_IRQHandler>
<USBFS_L_CAN1_RX0_IRQHandler>1;0;0</USBFS_L_CAN1_RX0_IRQHandler>
<CAN1_RX1_IRQHandler>0;0;0</CAN1_RX1_IRQHandler>
<CAN1_SE_IRQHandler>0;0;0</CAN1_SE_IRQHandler>
<TMR1_TRG_HALL_TMR11_IRQHandler>0;0;0</TMR1_TRG_HALL_TMR11_IRQHandler>
@@ -141,7 +146,7 @@
<TMR8_CH_IRQHandler>0;0;0</TMR8_CH_IRQHandler>
<TMR6_GLOBAL_IRQHandler>1;0;0</TMR6_GLOBAL_IRQHandler>
<CAN2_TX_IRQHandler>0;0;0</CAN2_TX_IRQHandler>
<CAN2_RX0_IRQHandler>0;0;0</CAN2_RX0_IRQHandler>
<CAN2_RX0_IRQHandler>1;0;0</CAN2_RX0_IRQHandler>
<CAN2_RX1_IRQHandler>0;0;0</CAN2_RX1_IRQHandler>
<CAN2_SE_IRQHandler>0;0;0</CAN2_SE_IRQHandler>
</NVIC>

View File

@@ -33,18 +33,5 @@
}
},
"extensions": {
"recommendations": [
"cl.eide",
"keroc.hex-fmt",
"xiaoyongdong.srecord",
"hars.cppsnippets",
"zixuanwang.linkerscript",
"redhat.vscode-yaml",
"IBM.output-colorizer",
"cschlosser.doxdocgen",
"ms-vscode.vscode-serial-monitor",
"dan-c-underwood.arm",
"marus25.cortex-debug"
]
}
}

View File

@@ -65,10 +65,12 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void USBFS_L_CAN1_RX0_IRQHandler(void);
void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
void USART3_IRQHandler(void);
void TMR6_GLOBAL_IRQHandler(void);
void CAN2_RX0_IRQHandler(void);
/* add user code begin exported functions */
/* add user code end exported functions */

View File

@@ -200,6 +200,26 @@ void PendSV_Handler(void)
/* 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 */
}
/**
* @brief this function handles USART1 handler.
* @param none
@@ -256,7 +276,6 @@ 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);
}
@@ -266,6 +285,31 @@ void TMR6_GLOBAL_IRQHandler(void)
/* 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 */
/* add user code end 1 */

View File

@@ -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 */
}