2525#include "gpio_arch.h"
2626#include "irq_arch.h"
2727
28- #include "driver/periph_ctrl.h"
28+ #include "esp_clk_tree.h"
29+ #include "esp_cpu.h"
30+ #include "esp_private/periph_ctrl.h"
2931#include "esp_rom_gpio.h"
30- #include "hal/interrupt_controller_types.h"
31- #include "hal/interrupt_controller_ll.h"
3232#include "hal/twai_hal.h"
3333#include "log.h"
3434#include "rom/ets_sys.h"
35+ #include "soc/clk_tree_defs.h"
3536#include "soc/gpio_sig_map.h"
3637
3738#define ENABLE_DEBUG 0
@@ -592,11 +593,17 @@ static void _esp_can_power_up(can_t *dev)
592593 periph_module_reset (PERIPH_TWAI_MODULE );
593594 periph_module_enable (PERIPH_TWAI_MODULE );
594595
596+ twai_hal_config_t config = { .controller_id = 0 };
597+
598+ esp_clk_tree_src_get_freq_hz ((soc_module_clk_t )TWAI_CLK_SRC_DEFAULT ,
599+ ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED ,
600+ & config .clock_source_hz );
601+
595602 /* initialize the HAL context, on return the CAN controller is in listen
596603 * only mode but not yet started, the error counters are reset and
597604 * pending interrupts cleared */
598605
599- if (!twai_hal_init (& hw )) {
606+ if (!twai_hal_init (& hw , & config )) {
600607 assert (false);
601608 }
602609
@@ -608,8 +615,8 @@ static void _esp_can_power_up(can_t *dev)
608615
609616 /* route CAN interrupt source to CPU interrupt and enable it */
610617 intr_matrix_set (PRO_CPU_NUM , ETS_TWAI_INTR_SOURCE , CPU_INUM_CAN );
611- intr_cntrl_ll_set_int_handler (CPU_INUM_CAN , _esp_can_intr_handler , (void * )(uintptr_t )dev );
612- intr_cntrl_ll_enable_interrupts (BIT (CPU_INUM_CAN ));
618+ esp_cpu_intr_set_handler (CPU_INUM_CAN , _esp_can_intr_handler , (void * )(uintptr_t )dev );
619+ esp_cpu_intr_enable (BIT (CPU_INUM_CAN ));
613620
614621 /* initialize used GPIOs */
615622 _esp_can_init_pins ();
0 commit comments