diff --git a/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c b/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c index 643dec6334..dfb0da85bd 100644 --- a/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c +++ b/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c @@ -268,26 +268,30 @@ int can_config_rxmsgobj(can_t *obj) { } -void can_init(can_t *obj, PinName rd, PinName td) { +void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { // Enable power and clock LPC_SYSCON->PRESETCTRL |= PRESETCTRL_CAN_RST_N; LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_CAN; - + // Enable Initialization mode if (!(LPC_CAN->CNTL & CANCNTL_INIT)) { LPC_CAN->CNTL |= CANCNTL_INIT; } - - can_frequency(obj, 125000); - + + can_frequency(obj, hz); + // Resume operation LPC_CAN->CNTL &= ~CANCNTL_INIT; while ( LPC_CAN->CNTL & CANCNTL_INIT ); - + // Initialize RX message object can_config_rxmsgobj(obj); } +void can_init(can_t *obj, PinName rd, PinName td) { + can_init_freq(obj, rd, td, 125000); +} + void can_free(can_t *obj) { LPC_SYSCON->SYSAHBCLKCTRL &= ~(SYSAHBCLKCTRL_CAN); LPC_SYSCON->PRESETCTRL &= ~(PRESETCTRL_CAN_RST_N); diff --git a/targets/TARGET_NXP/TARGET_LPC15XX/can_api.c b/targets/TARGET_NXP/TARGET_LPC15XX/can_api.c index 26fcbf2170..d0f0ff307e 100644 --- a/targets/TARGET_NXP/TARGET_LPC15XX/can_api.c +++ b/targets/TARGET_NXP/TARGET_LPC15XX/can_api.c @@ -415,8 +415,7 @@ int can_config_txmsgobj(can_t *obj) { return 1; } - -void can_init(can_t *obj, PinName rd, PinName td) { +void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { // Enable power and clock LPC_SYSCON->SYSAHBCLKCTRL1 |= (1UL << 7); LPC_SYSCON->PRESETCTRL1 |= (1UL << 7); @@ -430,7 +429,7 @@ void can_init(can_t *obj, PinName rd, PinName td) { LPC_SWM->PINASSIGN[6] &= ~(0x00FFFF00L); LPC_SWM->PINASSIGN[6] |= (rd << 16) | (td << 8); - can_frequency(obj, 100000); + can_frequency(obj, hz); // Resume operation LPC_C_CAN0->CANCNTL &= ~(1UL << 0); @@ -442,6 +441,10 @@ void can_init(can_t *obj, PinName rd, PinName td) { can_config_txmsgobj(obj); } +void can_init(can_t *obj, PinName rd, PinName td) { + can_init_freq(obj, rd, td, 100000); +} + void can_free(can_t *obj) { LPC_SYSCON->SYSAHBCLKCTRL1 &= ~(1UL << 7); LPC_SYSCON->PRESETCTRL1 &= ~(1UL << 7); diff --git a/targets/TARGET_NXP/TARGET_LPC176X/can_api.c b/targets/TARGET_NXP/TARGET_LPC176X/can_api.c index 75d6d7e633..f1301c24c0 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/can_api.c +++ b/targets/TARGET_NXP/TARGET_LPC176X/can_api.c @@ -292,7 +292,7 @@ static unsigned int can_speed(unsigned int sclk, unsigned int pclk, unsigned int } -void can_init(can_t *obj, PinName rd, PinName td) { +void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); @@ -313,11 +313,15 @@ void can_init(can_t *obj, PinName rd, PinName td) { can_reset(obj); obj->dev->IER = 0; // Disable Interrupts - can_frequency(obj, 100000); + can_frequency(obj, hz); LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter } +void can_init(can_t *obj, PinName rd, PinName td) { + can_init_freq(obj, rd, td, 100000); +} + void can_free(can_t *obj) { switch ((int)obj->dev) { case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break; diff --git a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/can_api.c b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/can_api.c index 34f1a04d24..aeda13e60a 100644 --- a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/can_api.c +++ b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/can_api.c @@ -239,7 +239,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha } -void can_init(can_t *obj, PinName rd, PinName td) { +void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); @@ -252,19 +252,23 @@ void can_init(can_t *obj, PinName rd, PinName td) { pinmap_pinout(rd, PinMap_CAN_RD); pinmap_pinout(td, PinMap_CAN_TD); - + switch ((int)obj->dev) { case CAN_1: obj->index = 0; break; case CAN_2: obj->index = 1; break; } - + can_reset(obj); obj->dev->IER = 0; // Disable Interrupts - can_frequency(obj, 100000); + can_frequency(obj, hz); LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter } +void can_init(can_t *obj, PinName rd, PinName td) { + can_init_freq(obj, rd, td, 100000); +} + void can_free(can_t *obj) { switch ((int)obj->dev) { case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break; diff --git a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/can_api.c b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/can_api.c index 676bc27401..03f8bb1977 100644 --- a/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/can_api.c +++ b/targets/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/can_api.c @@ -236,7 +236,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha } -void can_init(can_t *obj, PinName rd, PinName td) { +void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); @@ -257,11 +257,15 @@ void can_init(can_t *obj, PinName rd, PinName td) { can_reset(obj); obj->dev->IER = 0; // Disable Interrupts - can_frequency(obj, 100000); + can_frequency(obj, hz); LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter } +void can_init(can_t *obj, PinName rd, PinName td) { + can_init_freq(obj, rd, td, 100000); +} + void can_free(can_t *obj) { switch ((int)obj->dev) { case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;