stm32/can: Allow CAN pins to be configured per board.
This patch allows a given board to configure which pins are used for the CAN peripherals, in a similar way to all the other bus peripherals (I2C, UART, SPI). To enable CAN on a board the mpconfigboard.h file should define (for example): #define MICROPY_HW_CAN1_TX (pin_B9) #define MICROPY_HW_CAN1_RX (pin_B8) #define MICROPY_HW_CAN2_TX (pin_B13) #define MICROPY_HW_CAN2_RX (pin_B12) And the board config file should no longer define MICROPY_HW_ENABLE_CAN.
This commit is contained in:
parent
0041396f05
commit
a7ebac2eae
@ -5,7 +5,6 @@
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 12MHz
|
||||
@ -50,6 +49,12 @@
|
||||
#define MICROPY_HW_SPI3_MISO (pin_B4)
|
||||
#define MICROPY_HW_SPI3_MOSI (pin_B5)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// The Cerb40 has No LEDs
|
||||
|
||||
// The Cerb40 has No SDCard
|
||||
|
@ -44,3 +44,5 @@ UART3_TX,PD8
|
||||
UART3_RX,PD9
|
||||
UART3_RTS,PD12
|
||||
UART3_CTS,PD11
|
||||
CAN2_TX,PB13
|
||||
CAN2_RX,PB12
|
||||
|
|
@ -5,7 +5,6 @@
|
||||
#define MICROPY_HW_HAS_FLASH (1)
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -59,6 +58,12 @@
|
||||
#define MICROPY_HW_SPI5_MISO (pin_F8)
|
||||
#define MICROPY_HW_SPI5_MOSI (pin_F9)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_C13)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -53,6 +52,12 @@
|
||||
#define MICROPY_HW_SPI3_MISO (pin_B4)
|
||||
#define MICROPY_HW_SPI3_MOSI (pin_B5)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_C13)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 25MHz
|
||||
@ -53,6 +52,12 @@
|
||||
#define MICROPY_HW_SPI3_MISO (pin_B4)
|
||||
#define MICROPY_HW_SPI3_MOSI (pin_B5)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_C13)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -7,7 +7,6 @@
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 12MHz
|
||||
@ -53,6 +52,12 @@
|
||||
#define MICROPY_HW_SPI2_MISO (pin_B14)
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A0)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_SERVO (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -66,8 +65,12 @@
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
||||
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
||||
#define MICROPY_HW_CAN1_NAME "YA"
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9) // Y4
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8) // Y3
|
||||
#define MICROPY_HW_CAN2_NAME "YB"
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13) // Y6
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12) // Y5
|
||||
|
||||
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
|
||||
#define MICROPY_HW_USRSW_PIN (pin_B3)
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_SERVO (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 12MHz
|
||||
@ -66,8 +65,12 @@
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
||||
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
||||
#define MICROPY_HW_CAN1_NAME "YA"
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9) // Y4
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8) // Y3
|
||||
#define MICROPY_HW_CAN2_NAME "YB"
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13) // Y6
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12) // Y5
|
||||
|
||||
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
|
||||
#define MICROPY_HW_USRSW_PIN (pin_B3)
|
||||
|
@ -9,7 +9,6 @@
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_SERVO (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -57,6 +56,12 @@
|
||||
#define MICROPY_HW_SPI2_MISO (pin_B14) // Y7
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9) // Y4
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8) // Y3
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13) // Y6
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12) // Y5
|
||||
|
||||
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A13)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_SERVO (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -63,8 +62,12 @@
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15) // Y8
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
|
||||
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
|
||||
#define MICROPY_HW_CAN1_NAME "YA"
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9) // Y4
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8) // Y3
|
||||
#define MICROPY_HW_CAN2_NAME "YB"
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13) // Y6
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12) // Y5
|
||||
|
||||
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
|
||||
#define MICROPY_HW_USRSW_PIN (pin_B3)
|
||||
|
@ -5,7 +5,6 @@
|
||||
#define MICROPY_HW_HAS_FLASH (1)
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -50,6 +49,12 @@
|
||||
//#define MICROPY_HW_SPI6_MISO (pin_G12)
|
||||
//#define MICROPY_HW_SPI6_MOSI (pin_G14)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A0)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// SD card detect switch
|
||||
@ -75,6 +74,12 @@
|
||||
//#define MICROPY_HW_SPI6_MISO (pin_G12)
|
||||
//#define MICROPY_HW_SPI6_MOSI (pin_G14)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A0)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 8MHz
|
||||
@ -60,6 +59,12 @@
|
||||
#define MICROPY_HW_SPI2_MISO (pin_B14)
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A0)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define MICROPY_HW_HAS_SDCARD (1)
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// HSE is 25MHz
|
||||
@ -44,6 +43,12 @@
|
||||
#define MICROPY_HW_SPI2_MISO (pin_B14)
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A0)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -55,3 +55,5 @@ UART1_TX,PA9
|
||||
UART1_RX,PA10
|
||||
UART5_TX,PC12
|
||||
UART5_RX,PD2
|
||||
CAN2_TX,PB13
|
||||
CAN2_RX,PB12
|
||||
|
|
@ -6,7 +6,6 @@
|
||||
#define MICROPY_HW_HAS_SDCARD (1)
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
#define MICROPY_BOARD_EARLY_INIT STM32F7DISC_board_early_init
|
||||
@ -50,6 +49,12 @@ void STM32F7DISC_board_early_init(void);
|
||||
#define MICROPY_HW_SPI2_MISO (pin_B14)
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_B15)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
#define MICROPY_HW_CAN2_TX (pin_B13)
|
||||
#define MICROPY_HW_CAN2_RX (pin_B12)
|
||||
|
||||
// USRSW is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_I11)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -51,3 +51,5 @@ USB_DM,PA11
|
||||
USB_DP,PA12
|
||||
VCP_TX,PA9
|
||||
VCP_RX,PB7
|
||||
CAN_TX,PB13
|
||||
CAN_RX,PB12
|
||||
|
|
@ -9,7 +9,6 @@ void STM32L476DISC_board_early_init(void);
|
||||
#define MICROPY_HW_HAS_FLASH (1)
|
||||
#define MICROPY_HW_ENABLE_RNG (1)
|
||||
#define MICROPY_HW_ENABLE_RTC (1)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#define MICROPY_HW_ENABLE_USB (1)
|
||||
|
||||
// use external SPI flash for storage
|
||||
@ -58,6 +57,10 @@ extern struct _spi_bdev_t spi_bdev;
|
||||
#define MICROPY_HW_SPI2_MISO (pin_D3)
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_D4)
|
||||
|
||||
// CAN busses
|
||||
#define MICROPY_HW_CAN1_TX (pin_B9)
|
||||
#define MICROPY_HW_CAN1_RX (pin_B8)
|
||||
|
||||
// Joystick is pulled low. Pressing the button makes the input go high.
|
||||
#define MICROPY_HW_USRSW_PIN (pin_A0)
|
||||
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
|
||||
|
@ -16,6 +16,7 @@ SUPPORTED_FN = {
|
||||
'UART' : ['RX', 'TX', 'CTS', 'RTS'],
|
||||
'SPI' : ['NSS', 'SCK', 'MISO', 'MOSI'],
|
||||
'SDMMC' : ['CK', 'CMD', 'D0', 'D1', 'D2', 'D3'],
|
||||
'CAN' : ['TX', 'RX'],
|
||||
}
|
||||
|
||||
CONDITIONAL_VAR = {
|
||||
@ -25,6 +26,7 @@ CONDITIONAL_VAR = {
|
||||
'UART' : 'MICROPY_HW_UART{num}_TX',
|
||||
'USART' : 'MICROPY_HW_UART{num}_TX',
|
||||
'SDMMC' : 'MICROPY_HW_SDMMC{num}_CK',
|
||||
'CAN' : 'MICROPY_HW_CAN{num}_TX',
|
||||
}
|
||||
|
||||
def parse_port_pin(name_str):
|
||||
|
@ -104,31 +104,26 @@ STATIC uint8_t can2_start_bank = 14;
|
||||
// assumes Init parameters have been set up correctly
|
||||
STATIC bool can_init(pyb_can_obj_t *can_obj) {
|
||||
CAN_TypeDef *CANx = NULL;
|
||||
|
||||
uint32_t GPIO_Pin = 0;
|
||||
uint8_t GPIO_AF_CANx = 0;
|
||||
GPIO_TypeDef* GPIO_Port = NULL;
|
||||
uint32_t sce_irq = 0;
|
||||
const pin_obj_t *pins[2];
|
||||
|
||||
switch (can_obj->can_id) {
|
||||
// CAN1 is on RX,TX = Y3,Y4 = PB9,PB9
|
||||
#if defined(MICROPY_HW_CAN1_TX)
|
||||
case PYB_CAN_1:
|
||||
CANx = CAN1;
|
||||
GPIO_AF_CANx = GPIO_AF9_CAN1;
|
||||
GPIO_Port = GPIOB;
|
||||
GPIO_Pin = GPIO_PIN_8 | GPIO_PIN_9;
|
||||
sce_irq = CAN1_SCE_IRQn;
|
||||
pins[0] = MICROPY_HW_CAN1_TX;
|
||||
pins[1] = MICROPY_HW_CAN1_RX;
|
||||
__CAN1_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(CAN2)
|
||||
// CAN2 is on RX,TX = Y5,Y6 = PB12,PB13
|
||||
#if defined(MICROPY_HW_CAN2_TX)
|
||||
case PYB_CAN_2:
|
||||
CANx = CAN2;
|
||||
GPIO_AF_CANx = GPIO_AF9_CAN2;
|
||||
GPIO_Port = GPIOB;
|
||||
GPIO_Pin = GPIO_PIN_12 | GPIO_PIN_13;
|
||||
sce_irq = CAN2_SCE_IRQn;
|
||||
pins[0] = MICROPY_HW_CAN2_TX;
|
||||
pins[1] = MICROPY_HW_CAN2_RX;
|
||||
__CAN1_CLK_ENABLE(); // CAN2 is a "slave" and needs CAN1 enabled as well
|
||||
__CAN2_CLK_ENABLE();
|
||||
break;
|
||||
@ -139,13 +134,13 @@ STATIC bool can_init(pyb_can_obj_t *can_obj) {
|
||||
}
|
||||
|
||||
// init GPIO
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pin = GPIO_Pin;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStructure.Alternate = GPIO_AF_CANx;
|
||||
HAL_GPIO_Init(GPIO_Port, &GPIO_InitStructure);
|
||||
uint32_t mode = MP_HAL_PIN_MODE_ALT;
|
||||
uint32_t pull = MP_HAL_PIN_PULL_UP;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (!mp_hal_pin_config_alt(pins[i], mode, pull, AF_FN_CAN, can_obj->can_id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// init CANx
|
||||
can_obj->can.Instance = CANx;
|
||||
|
@ -57,11 +57,6 @@
|
||||
#define MICROPY_HW_ENABLE_DAC (0)
|
||||
#endif
|
||||
|
||||
// Whether to enable the CAN peripheral, exposed as pyb.CAN
|
||||
#ifndef MICROPY_HW_ENABLE_CAN
|
||||
#define MICROPY_HW_ENABLE_CAN (0)
|
||||
#endif
|
||||
|
||||
// Whether to enable USB support
|
||||
#ifndef MICROPY_HW_ENABLE_USB
|
||||
#define MICROPY_HW_ENABLE_USB (0)
|
||||
@ -156,6 +151,13 @@
|
||||
#define MICROPY_HW_ENABLE_HW_I2C (0)
|
||||
#endif
|
||||
|
||||
// Enable CAN if there are any peripherals defined
|
||||
#if defined(MICROPY_HW_CAN1_TX) || defined(MICROPY_HW_CAN2_TX)
|
||||
#define MICROPY_HW_ENABLE_CAN (1)
|
||||
#else
|
||||
#define MICROPY_HW_ENABLE_CAN (0)
|
||||
#endif
|
||||
|
||||
// Pin definition header file
|
||||
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stm32.h"
|
||||
|
||||
|
@ -49,6 +49,7 @@ enum {
|
||||
AF_FN_SPI,
|
||||
AF_FN_I2S,
|
||||
AF_FN_SDMMC,
|
||||
AF_FN_CAN,
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -93,6 +94,9 @@ enum {
|
||||
AF_PIN_TYPE_SDMMC_D1,
|
||||
AF_PIN_TYPE_SDMMC_D2,
|
||||
AF_PIN_TYPE_SDMMC_D3,
|
||||
|
||||
AF_PIN_TYPE_CAN_TX = 0,
|
||||
AF_PIN_TYPE_CAN_RX,
|
||||
};
|
||||
|
||||
// The HAL uses a slightly different naming than we chose, so we provide
|
||||
|
@ -736,7 +736,7 @@ void UART8_IRQHandler(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_ENABLE_CAN
|
||||
#if defined(MICROPY_HW_CAN1_TX)
|
||||
void CAN1_RX0_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN1_RX0_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_1, CAN_FIFO0);
|
||||
@ -754,7 +754,9 @@ void CAN1_SCE_IRQHandler(void) {
|
||||
can_sce_irq_handler(PYB_CAN_1);
|
||||
IRQ_EXIT(CAN1_SCE_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_CAN2_TX)
|
||||
void CAN2_RX0_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN2_RX0_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_2, CAN_FIFO0);
|
||||
@ -772,7 +774,7 @@ void CAN2_SCE_IRQHandler(void) {
|
||||
can_sce_irq_handler(PYB_CAN_2);
|
||||
IRQ_EXIT(CAN2_SCE_IRQn);
|
||||
}
|
||||
#endif // MICROPY_HW_ENABLE_CAN
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
void I2C1_EV_IRQHandler(void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user