ESP32 CAN
来自Jack's Lab
目录 |
1 Overview
2 Hacking
2.1 Pin
Need to call the gpio_matrix_out()/gpio_matrix_in() to setup the gpio matrix:
/* * @brief set gpio input to a signal, one gpio can input to several signals. * @param uint32_t gpio : gpio number, 0~0x27 * @param uint32_t signal_idx : signal index. * @param bool inv : the signal is inv or not * @return None */ void gpio_matrix_in(uint32_t gpio, uint32_t signal_idx, bool inv); /* * @brief set signal output to gpio, one signal can output to several gpios. * @param uint32_t gpio : gpio number, 0~0x27 * @param uint32_t signal_idx : signal index. * signal_idx == 0x100, cancel output put to the gpio * @param bool out_inv : the signal output is inv or not * @param bool oen_inv : the signal output enable is inv or not */ void gpio_matrix_out(uint32_t gpio, uint32_t signal_idx, bool out_inv, bool oen_inv);
The signal_idx of CAN is in components/esp32/include/soc/gpio_sig_map.h:
#define CAN_RX_IDX 94 #define CAN_TX_IDX 123 #define CAN_BUS_OFF_ON_IDX 124 #define CAN_CLKOUT_IDX 125
2.2 Registers
#define DPORT_PRO_CAN_INT_MAP_REG (DR_REG_DPORT_BASE + 0x1B8) /* DPORT_PRO_CAN_INT_MAP : R/W ;bitpos:[4:0] ;default: 5'd16 ; */ /*description: */ #define DPORT_PRO_CAN_INT_MAP 0x0000001F #define DPORT_PRO_CAN_INT_MAP_M ((DPORT_PRO_CAN_INT_MAP_V)<<(DPORT_PRO_CAN_INT_MAP_S)) #define DPORT_PRO_CAN_INT_MAP_V 0x1F #define DPORT_PRO_CAN_INT_MAP_S 0 #define DPORT_APP_CAN_INT_MAP_REG (DR_REG_DPORT_BASE + 0x2CC) /* DPORT_APP_CAN_INT_MAP : R/W ;bitpos:[4:0] ;default: 5'd16 ; */ /*description: */ #define DPORT_APP_CAN_INT_MAP 0x0000001F #define DPORT_APP_CAN_INT_MAP_M ((DPORT_APP_CAN_INT_MAP_V)<<(DPORT_APP_CAN_INT_MAP_S)) #define DPORT_APP_CAN_INT_MAP_V 0x1F #define DPORT_APP_CAN_INT_MAP_S 0 #define DPORT_AHBLITE_MPU_TABLE_CAN_REG (DR_REG_DPORT_BASE + 0x3C0) /* DPORT_CAN_ACCESS_GRANT_CONFIG : R/W ;bitpos:[5:0] ;default: 6'b0 ; */ /*description: */ #define DPORT_CAN_ACCESS_GRANT_CONFIG 0x0000003F #define DPORT_CAN_ACCESS_GRANT_CONFIG_M ((DPORT_CAN_ACCESS_GRANT_CONFIG_V)<<(DPORT_CAN_ACCESS_GRANT_CONFIG_S)) #define DPORT_CAN_ACCESS_GRANT_CONFIG_V 0x3F #define DPORT_CAN_ACCESS_GRANT_CONFIG_S 0
3 Reference