Skip to content

Commit 9115dd9

Browse files
committed
Add can_init_freq for STM devices
1 parent 3d44a3f commit 9115dd9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

targets/TARGET_STM/can_api.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ static uint32_t can_irq_ids[CAN_NUM] = {0};
3030
static can_irq_handler irq_handler;
3131

3232
void can_init(can_t *obj, PinName rd, PinName td)
33+
{
34+
can_init_freq(obj, rd, td, 100000);
35+
}
36+
37+
void can_init_freq (can_t *obj, PinName rd, PinName td, int hz)
3338
{
3439
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
3540
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
@@ -80,8 +85,8 @@ void can_init(can_t *obj, PinName rd, PinName td)
8085
error("Cannot initialize CAN");
8186
}
8287

83-
// Set initial CAN frequency to 100 kb/s
84-
can_frequency(obj, 100000);
88+
// Set initial CAN frequency to requested kb/s
89+
can_frequency(obj, hz);
8590

8691
uint32_t filter_number = (obj->can == CAN_1) ? 0 : 14;
8792
can_filter(obj, 0, 0, CANStandard, filter_number);
@@ -227,16 +232,16 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
227232
} else {
228233
can->sTxMailBox[transmitmailbox].TIR |= ((msg.id << 3) | CAN_ID_EXT | msg.type);
229234
}
230-
235+
231236
/* Set up the DLC */
232237
can->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0;
233238
can->sTxMailBox[transmitmailbox].TDTR |= (msg.len & (uint8_t)0x0000000F);
234-
239+
235240
/* Set up the data field */
236241
can->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)msg.data[3] << 24) |
237-
((uint32_t)msg.data[2] << 16) |
238-
((uint32_t)msg.data[1] << 8) |
239-
((uint32_t)msg.data[0]));
242+
((uint32_t)msg.data[2] << 16) |
243+
((uint32_t)msg.data[1] << 8) |
244+
((uint32_t)msg.data[0]));
240245
can->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)msg.data[7] << 24) |
241246
((uint32_t)msg.data[6] << 16) |
242247
((uint32_t)msg.data[5] << 8) |

0 commit comments

Comments
 (0)