Skip to content

Commit f3d547e

Browse files
committed
Merge pull request #1771 from BartSX/can-devel-f4
[STM32F4xx] CAN development for STM32F4xx family
2 parents 7c29455 + 766b5c2 commit f3d547e

File tree

16 files changed

+107
-6
lines changed

16 files changed

+107
-6
lines changed

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/PeripheralNames.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ typedef enum {
9090
PWM_14 = (int)TIM14_BASE
9191
} PWMName;
9292

93+
typedef enum {
94+
CAN_1 = (int)CAN1_BASE,
95+
CAN_2 = (int)CAN2_BASE
96+
} CANName;
97+
9398
#ifdef __cplusplus
9499
}
95100
#endif

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/PeripheralPins.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,21 @@ const PinMap PinMap_SPI_SSEL[] = {
280280
{PG_8, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI6)},
281281
{NC, NC, 0}
282282
};
283+
284+
const PinMap PinMap_CAN_RD[] = {
285+
{PB_8, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
286+
{PB_12, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
287+
{PD_0, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
288+
{PB_5 , CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
289+
{PA_11, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
290+
{NC, NC, 0}
291+
};
292+
293+
const PinMap PinMap_CAN_TD[] = {
294+
{PB_9, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
295+
{PB_13, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
296+
{PD_1, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
297+
{PB_6 , CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
298+
{PA_12, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
299+
{NC, NC, 0}
300+
};

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/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

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ struct pwmout_s {
104104
uint8_t inverted;
105105
};
106106

107+
struct can_s {
108+
CANName can;
109+
int index;
110+
};
111+
107112
#include "gpio_object.h"
108113

109114
#ifdef __cplusplus

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/PeripheralNames.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ typedef enum {
9191
PWM_14 = (int)TIM14_BASE
9292
} PWMName;
9393

94+
typedef enum {
95+
CAN_1 = (int)CAN1_BASE,
96+
CAN_2 = (int)CAN2_BASE
97+
} CANName;
98+
9499
#ifdef __cplusplus
95100
}
96101
#endif

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/PeripheralPins.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,13 @@ const PinMap PinMap_SPI_SSEL[] = {
301301
{PI_0, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
302302
{NC, NC, 0}
303303
};
304+
305+
const PinMap PinMap_CAN_RD[] = {
306+
{PB_8 , CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
307+
{NC, NC, 0}
308+
};
309+
310+
const PinMap PinMap_CAN_TD[] = {
311+
{PB_9 , CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
312+
{NC, NC, 0}
313+
};

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/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

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ struct pwmout_s {
104104
uint8_t inverted;
105105
};
106106

107+
struct can_s {
108+
CANName can;
109+
int index;
110+
};
111+
107112
#include "gpio_object.h"
108113

109114
#ifdef __cplusplus

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/PeripheralNames.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ typedef enum {
8787
PWM_14 = (int)TIM14_BASE
8888
} PWMName;
8989

90+
typedef enum {
91+
CAN_1 = (int)CAN1_BASE,
92+
CAN_2 = (int)CAN2_BASE
93+
} CANName;
94+
9095
#ifdef __cplusplus
9196
}
9297
#endif

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/PeripheralPins.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,19 @@ const PinMap PinMap_SPI_SSEL[] = {
232232
{PB_12, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)},
233233
{NC, NC, 0}
234234
};
235+
236+
const PinMap PinMap_CAN_RD[] = {
237+
{PB_8, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
238+
{PB_12, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
239+
{PB_5 , CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
240+
{PA_11, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
241+
{NC, NC, 0}
242+
};
243+
244+
const PinMap PinMap_CAN_TD[] = {
245+
{PB_9, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
246+
{PB_13, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
247+
{PB_6 , CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
248+
{PA_12, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
249+
{NC, NC, 0}
250+
};

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/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

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ struct pwmout_s {
104104
uint8_t inverted;
105105
};
106106

107+
struct can_s {
108+
CANName can;
109+
int index;
110+
};
111+
107112
#include "gpio_object.h"
108113

109114
#ifdef __cplusplus

libraries/tests/mbed/can/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ CAN can1(PD_0, PD_1);
1717
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
1818
defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F334R8) || \
1919
defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303K8) || \
20-
defined(TARGET_NUCLEO_F302R8)
20+
defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F446RE) || \
21+
defined(TARGET_DISCO_F429ZI)
2122
CAN can1(PA_11, PA_12);
23+
#elif defined(TARGET_DISCO_F469NI)
24+
CAN can1(PB_8, PB_9);
2225
#else
2326
CAN can1(p9, p10);
2427
#endif
@@ -27,6 +30,9 @@ CAN can1(p9, p10);
2730
CAN can2(p34, p33);
2831
#elif defined (TARGET_LPC1768)
2932
CAN can2(p30, p29);
33+
#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_DISCO_F469NI) || \
34+
defined(TARGET_DISCO_F429ZI)
35+
CAN can2(PB_5, PB_6);
3036
#endif
3137
char counter = 0;
3238

libraries/tests/mbed/can_interrupt/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ CAN can1(PD_0, PD_1);
1717
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
1818
defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F334R8) || \
1919
defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303K8) || \
20-
defined(TARGET_NUCLEO_F302R8)
20+
defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F446RE) || \
21+
defined(TARGET_DISCO_F429ZI)
2122
CAN can1(PA_11, PA_12);
23+
#elif defined(TARGET_DISCO_F469NI)
24+
CAN can1(PB_8, PB_9);
2225
#else
2326
CAN can1(p9, p10);
2427
#endif
@@ -27,6 +30,9 @@ CAN can1(p9, p10);
2730
CAN can2(p34, p33);
2831
#elif defined (TARGET_LPC1768)
2932
CAN can2(p30, p29);
33+
#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_DISCO_F469NI) || \
34+
defined(TARGET_DISCO_F429ZI)
35+
CAN can2(PB_5, PB_6);
3036
#endif
3137
char counter = 0;
3238

libraries/tests/mbed/can_loopback/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ CAN can1(P5_9, P5_10);
1616
#elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
1717
defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F334R8) || \
1818
defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303K8) || \
19-
defined(TARGET_NUCLEO_F302R8)
19+
defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F446RE) || \
20+
defined(TARGET_DISCO_F429ZI)
2021
CAN can1(PA_11, PA_12);
22+
#elif defined(TARGET_DISCO_F469NI)
23+
CAN can1(PB_8, PB_9);
2124
#endif
2225

2326
#define TEST_ITERATIONS 127

workspace_tools/tests.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
* NUCLEO_F303RE: (RX=PA_11, TX=PA_12)
9999
* NUCLEO_F303K8: (RX=PA_11, TX=PA_12)
100100
* NUCLEO_F302R8: (RX=PA_11, TX=PA_12)
101+
* NUCLEO_F446RE: (RX=PA_11, TX=PA_12)
102+
* DISCO_F469NI: (RX=PB_8, TX=PB_9)
103+
* DISCO_F4269ZI: (RX=PA_11, TX=PA_12)
101104
102105
"""
103106
TESTS = [
@@ -305,7 +308,8 @@
305308
"peripherals": ["can_transceiver"],
306309
"mcu": ["LPC1549", "LPC1768","B96B_F446VE", "VK_RZ_A1H",
307310
"NUCLEO_F091RC", "NUCLEO_F072RB", "NUCLEO_F042K6", "NUCLEO_F334R8",
308-
"NUCLEO_F303RE", "NUCLEO_F303K8", "NUCLEO_F302R8"],
311+
"NUCLEO_F303RE", "NUCLEO_F303K8", "NUCLEO_F302R8", "NUCLEO_F446RE",
312+
"DISCO_F469NI", "DISCO_F429ZI"],
309313
},
310314
{
311315
"id": "MBED_BLINKY", "description": "Blinky",
@@ -578,15 +582,17 @@
578582
"dependencies": [MBED_LIBRARIES],
579583
"mcu": ["LPC1768", "LPC4088", "LPC1549", "RZ_A1H", "B96B_F446VE", "NUCLEO_F091RC",
580584
"NUCLEO_F072RB", "NUCLEO_F042K6", "NUCLEO_F334R8", "NUCLEO_F303RE",
581-
"NUCLEO_F303K8", "NUCLEO_F302R8"]
585+
"NUCLEO_F303K8", "NUCLEO_F302R8", "NUCLEO_F446RE", "DISCO_F469NI",
586+
"DISCO_F429ZI"]
582587
},
583588
{
584589
"id": "MBED_30", "description": "CAN network test using interrupts",
585590
"source_dir": join(TEST_DIR, "mbed", "can_interrupt"),
586591
"dependencies": [MBED_LIBRARIES],
587592
"mcu": ["LPC1768", "LPC4088", "LPC1549", "RZ_A1H", "B96B_F446VE", "NUCLEO_F091RC",
588593
"NUCLEO_F072RB", "NUCLEO_F042K6", "NUCLEO_F334R8", "NUCLEO_F303RE",
589-
"NUCLEO_F303K8", "NUCLEO_F302R8"]
594+
"NUCLEO_F303K8", "NUCLEO_F302R8", "NUCLEO_F446RE", "DISCO_F469NI",
595+
"DISCO_F429ZI"]
590596
},
591597
{
592598
"id": "MBED_31", "description": "PWM LED test",

0 commit comments

Comments
 (0)