Skip to content

Commit c12ac69

Browse files
committed
combine canfd_init_freq(), canfd_init_freq_direct(), and canfd_frequency() with the existing functions
minor fixes on documentation
1 parent 5293499 commit c12ac69

File tree

6 files changed

+71
-95
lines changed

6 files changed

+71
-95
lines changed

drivers/source/CAN.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CAN::CAN(PinName rd, PinName td, int hz, int data_hz) : _can(), _irq()
3434
{
3535
// No lock needed in constructor
3636
#if DEVICE_CAN_FD
37-
canfd_init_freq(&_can, rd, td, hz, data_hz);
37+
can_init_freq(&_can, rd, td, hz, data_hz);
3838
#else
3939
MBED_ASSERT(data_hz == 0);
4040
can_init_freq(&_can, rd, td, hz);
@@ -53,7 +53,7 @@ CAN::CAN(const can_pinmap_t &pinmap, int hz, int data_hz) : _can(), _irq()
5353
{
5454
// No lock needed in constructor
5555
#if DEVICE_CAN_FD
56-
canfd_init_freq_direct(&_can, &pinmap, hz, data_hz);
56+
can_init_freq_direct(&_can, &pinmap, hz, data_hz);
5757
#else
5858
MBED_ASSERT(data_hz == 0);
5959
can_init_freq_direct(&_can, &pinmap, hz);
@@ -77,7 +77,7 @@ int CAN::frequency(int f, int data_f)
7777
{
7878
lock();
7979
#if DEVICE_CAN_FD
80-
int ret = canfd_frequency(&_can, f, data_f);
80+
int ret = can_frequency(&_can, f, data_f);
8181
#else
8282
MBED_ASSERT(data_f == 0);
8383
int ret = can_frequency(&_can, f);

hal/include/hal/can_api.h

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,70 +74,85 @@ typedef struct can_s can_t;
7474
* @param rd The CAN RD pin name
7575
* @param td The CAN TD pin name
7676
*/
77-
void can_init(can_t *obj, PinName rd, PinName td);
77+
void can_init(can_t *obj, PinName rd, PinName td);
7878

7979
/** Initialize the CAN peripheral. It sets the default parameters for CAN
8080
* peripheral, and configures its specifieds pins.
8181
*
8282
* @param obj The CAN object
8383
* @param pinmap pointer to structure which holds static pinmap
8484
*/
85-
void can_init_direct(can_t *obj, const can_pinmap_t *pinmap);
85+
void can_init_direct(can_t *obj, const can_pinmap_t *pinmap);
8686

8787
/** Initialize the CAN peripheral. It sets the default parameters for CAN
8888
* peripheral, and configures its specifieds pins.
8989
*
9090
* @param obj CAN object
9191
* @param rd The CAN RD pin name
9292
* @param td The CAN TD pin name
93-
* @param hz The bus frequency
93+
* @param hz The bus frequency in classical CAN mode, or nominal phase frequency in CAN FD mode
94+
* @param data_hz The data phase frequency in CAN FD mode, the CAN object is put into Classical CAN mode if this parameter is zero
9495
*/
95-
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
96+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz
97+
#ifdef DEVICE_CAN_FD
98+
, int data_hz
99+
#endif
100+
);
96101

97102
/** Initialize the CAN peripheral. It sets the default parameters for CAN
98103
* peripheral, and configures its specifieds pins.
99104
*
100105
* @param obj CAN object
101106
* @param pinmap pointer to structure which holds static pinmap
102-
* @param hz The bus frequency
107+
* @param hz The bus frequency in classical CAN mode, or nominal phase frequency in CAN FD mode
108+
* @param data_hz The data phase frequency in CAN FD mode, the CAN object is put into Classical CAN mode if this parameter is zero
103109
*/
104-
void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz);
110+
void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz
111+
#ifdef DEVICE_CAN_FD
112+
, int data_hz
113+
#endif
114+
);
105115

106116
/** Release the CAN peripheral, not currently invoked. It requires further
107117
* resource management.
108118
*
109119
* @param obj The CAN object
110120
*/
111-
void can_free(can_t *obj);
121+
void can_free(can_t *obj);
112122

113123
/** Configure the CAN bus frequency
114124
*
115125
* @param obj The CAN object
116-
* @param hz The bus frequency
126+
* @param hz The bus frequency in classical CAN mode, or nominal phase frequency in CAN FD mode
127+
* @param data_hz The data phase frequency in CAN FD mode, the CAN object is put into Classical CAN mode if this parameter is zero
117128
*/
118-
int can_frequency(can_t *obj, int hz);
129+
int can_frequency(can_t *obj, int hz
130+
#ifdef DEVICE_CAN_FD
131+
, int data_hz
132+
#endif
133+
);
119134

120135
/** Initialize the CAN IRQ handler
121136
*
122137
* @param obj The CAN object
123138
* @param handler The handler to be attached to CAN IRQ
124139
* @param context The context to be passed back to the handler (context != 0, 0 is reserved)
125140
*/
126-
void can_irq_init(can_t *obj, can_irq_handler handler, uintptr_t context);
141+
void can_irq_init(can_t *obj, can_irq_handler handler, uintptr_t context);
127142

128-
/** Release the CAN object
143+
/** Remove the CAN IRQ handler
129144
*
130145
* @param obj The CAN object
131146
*/
132-
void can_irq_free(can_t *obj);
147+
void can_irq_free(can_t *obj);
133148

134149
/** Enable/disable the CAN IRQ event
135150
*
136151
* @param obj The CAN object
137152
* @param irq The CAN IRQ event
138153
* @param enable The enable flag
139154
*/
140-
void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
155+
void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
141156

142157
/** Write a CAN message to the bus.
143158
*
@@ -147,7 +162,7 @@ void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable);
147162
* @return 0 if write failed,
148163
* 1 if write was successful
149164
*/
150-
int can_write(can_t *obj, CAN_Message msg);
165+
int can_write(can_t *obj, CAN_Message msg);
151166

152167
/** Read a CAN message from the bus.
153168
*
@@ -158,7 +173,7 @@ int can_write(can_t *obj, CAN_Message msg);
158173
* @return 0 if no message arrived,
159174
* 1 if message arrived
160175
*/
161-
int can_read(can_t *obj, CAN_Message *msg, int handle);
176+
int can_read(can_t *obj, CAN_Message *msg, int handle);
162177

163178
/** Change CAN operation to the specified mode.
164179
*
@@ -168,7 +183,7 @@ int can_read(can_t *obj, CAN_Message *msg, int handle);
168183
* @return 0 if mode change failed or unsupported,
169184
* 1 if mode change was successful
170185
*/
171-
int can_mode(can_t *obj, CanMode mode);
186+
int can_mode(can_t *obj, CanMode mode);
172187

173188
/** Filter out incomming messages.
174189
*
@@ -181,15 +196,15 @@ int can_mode(can_t *obj, CanMode mode);
181196
* @return 0 if filter change failed or unsupported,
182197
* new filter handle if successful
183198
*/
184-
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
199+
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
185200

186201
/** Reset CAN interface.
187202
*
188203
* @param obj CAN object
189204
*
190205
* To use after error overflow.
191206
*/
192-
void can_reset(can_t *obj);
207+
void can_reset(can_t *obj);
193208

194209
/** Detects read errors - Used to detect read overflow errors.
195210
*
@@ -210,38 +225,9 @@ unsigned char can_tderror(can_t *obj);
210225
* @param obj CAN object
211226
* @param silent boolean indicating whether to go into silent mode or not.
212227
*/
213-
void can_monitor(can_t *obj, int silent);
228+
void can_monitor(can_t *obj, int silent);
214229

215230
#if DEVICE_CAN_FD
216-
/** Initialize the CAN FD peripheral. It sets the default parameters for CAN FD
217-
* peripheral, and configures its specifieds pins.
218-
*
219-
* @param obj CAN object
220-
* @param rd The CAN RD pin name
221-
* @param td The CAN TD pin name
222-
* @param hz The bus frequency of nominal phase
223-
* @param data_hz The bus frequency of data phase, the CAN object is put into Classical CAN mode if this parameter is zero
224-
*/
225-
void canfd_init_freq(can_t *obj, PinName rd, PinName td, int hz, int data_hz);
226-
227-
/** Initialize the CAN FD peripheral. It sets the default parameters for CAN FD
228-
* peripheral, and configures its specifieds pins.
229-
*
230-
* @param obj CAN object
231-
* @param pinmap pointer to structure which holds static pinmap
232-
* @param hz The bus frequency of nominal phase
233-
* @param data_hz The bus frequency of data phase, the CAN object is put into Classical CAN mode if this parameter is zero
234-
*/
235-
void canfd_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz, int data_hz);
236-
237-
/** Configure the CAN FD bus frequency
238-
*
239-
* @param obj The CAN object
240-
* @param hz The bus frequency of nominal phase
241-
* @param data_hz The bus frequency of data phase, the CAN object is put into Classical CAN mode if this parameter is zero
242-
*/
243-
int canfd_frequency(can_t *obj, int hz, int data_hz);
244-
245231
/** Write a CAN FD Message to the bus.
246232
*
247233
* @param obj The CAN object
@@ -250,7 +236,7 @@ int canfd_frequency(can_t *obj, int hz, int data_hz);
250236
* @return 0 if write failed,
251237
* 1 if write was successful
252238
*/
253-
int canfd_write(can_t *obj, CANFD_Message msg);
239+
int canfd_write(can_t *obj, CANFD_Message msg);
254240

255241
/** Read a Classical CAN or CAN FD Message from the bus.
256242
*
@@ -261,7 +247,7 @@ int canfd_write(can_t *obj, CANFD_Message msg);
261247
* @return 0 if no message arrived,
262248
* 1 if message arrived
263249
*/
264-
int canfd_read(can_t *obj, CANFD_Message *msg, int handle);
250+
int canfd_read(can_t *obj, CANFD_Message *msg, int handle);
265251
#endif
266252

267253
/** Get the pins that support CAN RD

hal/include/hal/can_helper.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ typedef enum CANType CANType;
5959
*
6060
**/
6161
struct CAN_Message {
62-
unsigned int id; // 29 bit identifier
63-
unsigned char data[8]; // Data field
64-
unsigned char len; // Length of data field in bytes
65-
CANFormat format; // Format ::CANFormat
66-
CANType type; // Type ::CANType
62+
unsigned int id; ///< 29 bit identifier
63+
unsigned char data[8]; ///< Data field
64+
unsigned char len; ///< Length of data field in bytes
65+
CANFormat format; ///< Format ::CANFormat
66+
CANType type; ///< Type ::CANType
6767
};
6868
typedef struct CAN_Message CAN_Message;
6969

@@ -77,11 +77,11 @@ typedef struct CAN_Message CAN_Message;
7777
*
7878
**/
7979
struct CANFD_Message {
80-
unsigned int id; // 29 bit identifier
81-
unsigned char data[64]; // Data field
82-
unsigned char len; // Length of data field in bytes
83-
CANFormat format; // Format ::CANFormat
84-
CANType type; // Type ::CANType
80+
unsigned int id; ///< 29 bit identifier
81+
unsigned char data[64]; ///< Data field
82+
unsigned char len; ///< Length of data field in bytes
83+
CANFormat format; ///< Format ::CANFormat
84+
CANType type; ///< Type ::CANType
8585
};
8686
typedef struct CANFD_Message CANFD_Message;
8787

hal/source/static_pinmap.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ MBED_WEAK void serial_set_flow_control_direct(serial_t *obj, FlowControl type, c
7474
#endif
7575

7676
#if DEVICE_CAN
77+
#if DEVICE_CAN_FD
78+
MBED_WEAK void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz, int data_hz)
79+
{
80+
can_init_freq(obj, pinmap->rd_pin, pinmap->td_pin, hz, data_hz);
81+
}
82+
83+
MBED_WEAK void can_init_direct(can_t *obj, const can_pinmap_t *pinmap)
84+
{
85+
can_init(obj, pinmap->rd_pin, pinmap->td_pin);
86+
}
87+
#else
7788
MBED_WEAK void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz)
7889
{
7990
can_init_freq(obj, pinmap->rd_pin, pinmap->td_pin, hz);
@@ -83,7 +94,7 @@ MBED_WEAK void can_init_direct(can_t *obj, const can_pinmap_t *pinmap)
8394
{
8495
can_init(obj, pinmap->rd_pin, pinmap->td_pin);
8596
}
86-
97+
#endif
8798
#endif
8899

89100
#if DEVICE_QSPI

targets/TARGET_STM/can_api.c

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ static uint32_t get_canfd_data_prescaler(uint32_t input_f, int data_f, uint32_t
115115
}
116116

117117
#if STATIC_PINMAP_READY
118-
#define CANFD_INIT_FREQ_DIRECT canfd_init_freq_direct
119-
void canfd_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz)
118+
#define CAN_INIT_FREQ_DIRECT can_init_freq_direct
119+
void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz, int data_hz)
120120
#else
121-
#define CANFD_INIT_FREQ_DIRECT _canfd_init_freq_direct
122-
static void _canfd_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz, int data_hz)
121+
#define CAN_INIT_FREQ_DIRECT _can_init_freq_direct
122+
static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz, int data_hz)
123123
#endif
124124
{
125125
MBED_ASSERT((int)pinmap->peripheral != NC);
@@ -301,24 +301,13 @@ static void _canfd_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int
301301
can_internal_init(obj);
302302
}
303303

304-
#if STATIC_PINMAP_READY
305-
#define CAN_INIT_FREQ_DIRECT can_init_freq_direct
306-
void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz)
307-
#else
308-
#define CAN_INIT_FREQ_DIRECT _can_init_freq_direct
309-
static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz)
310-
#endif
311-
{
312-
CANFD_INIT_FREQ_DIRECT(obj, pinmap, hz, 0);
313-
}
314-
315304
void can_init_direct(can_t *obj, const can_pinmap_t *pinmap)
316305
{
317306
/* default frequency is 100 kHz */
318-
CAN_INIT_FREQ_DIRECT(obj, pinmap, 100000);
307+
can_init_freq_direct(obj, pinmap, 100000, 0);
319308
}
320309

321-
void canfd_init_freq(can_t *obj, PinName rd, PinName td, int hz, int data_hz)
310+
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz, int data_hz)
322311
{
323312
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
324313
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
@@ -329,17 +318,12 @@ void canfd_init_freq(can_t *obj, PinName rd, PinName td, int hz, int data_hz)
329318

330319
const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td};
331320

332-
CANFD_INIT_FREQ_DIRECT(obj, &static_pinmap, hz, data_hz);
333-
}
334-
335-
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz)
336-
{
337-
canfd_init_freq(obj, rd, td, hz, 0);
321+
CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, hz, data_hz);
338322
}
339323

340324
void can_init(can_t *obj, PinName rd, PinName td)
341325
{
342-
can_init_freq(obj, rd, td, 100000);
326+
can_init_freq(obj, rd, td, 100000, 0);
343327
}
344328

345329
void can_irq_init(can_t *obj, can_irq_handler handler, uintptr_t context)
@@ -427,7 +411,7 @@ void can_reset(can_t *obj)
427411
HAL_FDCAN_ResetTimestampCounter(&obj->CanHandle);
428412
}
429413

430-
int canfd_frequency(can_t *obj, int f, int data_f)
414+
int can_frequency(can_t *obj, int f, int data_f)
431415
{
432416
if (HAL_FDCAN_Stop(&obj->CanHandle) != HAL_OK) {
433417
error("HAL_FDCAN_Stop error\n");
@@ -488,11 +472,6 @@ int canfd_frequency(can_t *obj, int f, int data_f)
488472
return can_internal_init(obj);
489473
}
490474

491-
int can_frequency(can_t *obj, int f)
492-
{
493-
return canfd_frequency(obj, f, 0);
494-
}
495-
496475
/** Filter out incoming messages
497476
*
498477
* @param obj CAN object

targets/targets.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4923,7 +4923,7 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
49234923
"macro_name": "CLOCK_SOURCE"
49244924
},
49254925
"hse_value": {
4926-
"help": "HSE default value is 16MHz in stm32u5xx_hal_conf.h, The valid value range is between 4MHz and 50MHz",
4926+
"help": "HSE default value is 16MHz in stm32u5xx_hal_conf.h, The effective value is within the range of 4MHz to 50MHz and can be divided by 4MHz or 5MHz.",
49274927
"value": "16000000",
49284928
"macro_name": "HSE_VALUE"
49294929
},

0 commit comments

Comments
 (0)