Skip to content

Commit fad2190

Browse files
committed
[NUCLEO_F042K6] Added CAN support
Added CAN API support for NUCLEO_F042K6 target. "stm32f042x6.h" file was changed to avoid compilation errors. Change-Id: I9622a233775fc6834201a322740bf5026244d50e
1 parent d140e99 commit fad2190

File tree

9 files changed

+39
-10
lines changed

9 files changed

+39
-10
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/stm32f042x6.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ typedef struct
672672
#define IWDG ((IWDG_TypeDef *) IWDG_BASE)
673673
#define USART2 ((USART_TypeDef *) USART2_BASE)
674674
#define I2C1 ((I2C_TypeDef *) I2C1_BASE)
675-
#define CAN ((CAN_TypeDef *) CAN_BASE)
675+
#define CAN1 ((CAN_TypeDef *) CAN_BASE)
676676
#define CRS ((CRS_TypeDef *) CRS_BASE)
677677
#define PWR ((PWR_TypeDef *) PWR_BASE)
678678
#define CEC ((CEC_TypeDef *) CEC_BASE)

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/PeripheralNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ typedef enum {
6868
PWM_17 = (int)TIM17_BASE
6969
} PWMName;
7070

71+
typedef enum {
72+
CAN_1 = (int)CAN_BASE
73+
} CANName;
74+
7175
#ifdef __cplusplus
7276
}
7377
#endif

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/PeripheralPins.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,14 @@ const PinMap PinMap_SPI_SSEL[] = {
146146
// {PA_15, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF0_SPI1)},
147147
{NC, NC, 0}
148148
};
149+
150+
const PinMap PinMap_CAN_RD[] = {
151+
// {PB_8 , CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)},
152+
{PA_11, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)},
153+
{NC, NC, 0}
154+
};
155+
156+
const PinMap PinMap_CAN_TD[] = {
157+
{PA_12, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_CAN)},
158+
{NC, NC, 0}
159+
};

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454

5555
#define DEVICE_SLEEP 1
5656

57+
#define DEVICE_CAN 1
58+
5759
//=======================================
5860

5961
#define DEVICE_SEMIHOST 0

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ struct pwmout_s {
9595
uint32_t pulse;
9696
};
9797

98+
struct can_s {
99+
CANName can;
100+
int index;
101+
};
102+
98103
#include "gpio_object.h"
99104

100105
#ifdef __cplusplus

libraries/tests/mbed/can/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ CAN can1(D2, D3);
1414
#elif defined(TARGET_B96B_F446VE)
1515
// B96B_F446VE support only single CAN channel
1616
CAN can1(PD_0, PD_1);
17-
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB)
17+
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
18+
defined(TARGET_NUCLEO_F042K6)
1819
CAN can1(PA_11, PA_12);
1920
#else
2021
CAN can1(p9, p10);
@@ -51,7 +52,8 @@ int main() {
5152
CANMessage msg;
5253
while(1) {
5354
#if (!defined (TARGET_LPC1549) && !defined(TARGET_B96B_F446VE) && \
54-
!defined(TARGET_NUCLEO_F091RC) && !defined(TARGET_NUCLEO_F072RB))
55+
!defined(TARGET_NUCLEO_F091RC) && !defined(TARGET_NUCLEO_F072RB) && \
56+
!defined(TARGET_NUCLEO_F042K6))
5557
printf("loop()\n");
5658
if(can2.read(msg)) {
5759
printmsg("Rx message:", &msg);

libraries/tests/mbed/can_interrupt/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ CAN can1(D2, D3);
1414
#elif defined(TARGET_B96B_F446VE)
1515
// B96B_F446VE support only single CAN channel
1616
CAN can1(PD_0, PD_1);
17-
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB)
17+
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
18+
defined(TARGET_NUCLEO_F042K6)
1819
CAN can1(PA_11, PA_12);
1920
#else
2021
CAN can1(p9, p10);
@@ -46,7 +47,8 @@ void send() {
4647
}
4748

4849
#if (!defined (TARGET_LPC1549) && !defined(TARGET_B96B_F446VE) && \
49-
!defined(TARGET_NUCLEO_F091RC) && !defined(TARGET_NUCLEO_F072RB))
50+
!defined(TARGET_NUCLEO_F091RC) && !defined(TARGET_NUCLEO_F072RB) && \
51+
!defined(TARGET_NUCLEO_F042K6))
5052
void read() {
5153
CANMessage msg;
5254
printf("rx()\n");
@@ -61,7 +63,8 @@ int main() {
6163
printf("main()\n");
6264
ticker.attach(&send, 1);
6365
#if (!defined (TARGET_LPC1549) && !defined(TARGET_B96B_F446VE) && \
64-
!defined(TARGET_NUCLEO_F091RC) && !defined(TARGET_NUCLEO_F072RB))
66+
!defined(TARGET_NUCLEO_F091RC) && !defined(TARGET_NUCLEO_F072RB) && \
67+
!defined(TARGET_NUCLEO_F042K6))
6568
can2.attach(&read);
6669
#endif
6770
while(1) {

libraries/tests/mbed/can_loopback/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ CAN can1(p9, p10);
1313
CAN can1(PD_0, PD_1);
1414
#elif defined(TARGET_VK_RZ_A1H)
1515
CAN can1(P5_9, P5_10);
16-
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB)
16+
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
17+
defined(TARGET_NUCLEO_F042K6)
1718
CAN can1(PA_11, PA_12);
1819
#endif
1920

workspace_tools/tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
* VK_RZ_A1H:(RX=P5_9, TX=P5_10)
9494
* NUCLEO_F091RC: (RX=PA_11, TX=PA_12)
9595
* NUCLEO_F072RB: (RX=PA_11, TX=PA_12)
96+
* NUCLEO_F042K6: (RX=PA_11, TX=PA_12)
9697
9798
"""
9899
TESTS = [
@@ -299,7 +300,7 @@
299300
"duration": 20,
300301
"peripherals": ["can_transceiver"],
301302
"mcu": ["LPC1549", "LPC1768","B96B_F446VE", "VK_RZ_A1H",
302-
"NUCLEO_F091RC", "NUCLEO_F072RB"],
303+
"NUCLEO_F091RC", "NUCLEO_F072RB", "NUCLEO_F042K6"],
303304
},
304305
{
305306
"id": "MBED_BLINKY", "description": "Blinky",
@@ -571,14 +572,14 @@
571572
"source_dir": join(TEST_DIR, "mbed", "can"),
572573
"dependencies": [MBED_LIBRARIES],
573574
"mcu": ["LPC1768", "LPC4088", "LPC1549", "RZ_A1H", "B96B_F446VE", "NUCLEO_F091RC",
574-
"NUCLEO_F072RB"]
575+
"NUCLEO_F072RB", "NUCLEO_F042K6"]
575576
},
576577
{
577578
"id": "MBED_30", "description": "CAN network test using interrupts",
578579
"source_dir": join(TEST_DIR, "mbed", "can_interrupt"),
579580
"dependencies": [MBED_LIBRARIES],
580581
"mcu": ["LPC1768", "LPC4088", "LPC1549", "RZ_A1H", "B96B_F446VE", "NUCLEO_F091RC",
581-
"NUCLEO_F072RB"]
582+
"NUCLEO_F072RB", "NUCLEO_F042K6"]
582583
},
583584
{
584585
"id": "MBED_31", "description": "PWM LED test",

0 commit comments

Comments
 (0)