Skip to content

Commit efc49c5

Browse files
committed
stmhal: Improve CAN print function.
1 parent 6a15ac8 commit efc49c5

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

stmhal/can.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ STATIC void pyb_can_print(void (*print)(void *env, const char *fmt, ...), void *
144144
if (!self->is_enabled) {
145145
print(env, "CAN(%u)", self->can_id);
146146
} else {
147-
print(env, "CAN(%u, ", self->can_id);
147+
print(env, "CAN(%u, CAN.", self->can_id);
148148
qstr mode;
149149
switch (self->can.Init.Mode) {
150150
case CAN_MODE_NORMAL: mode = MP_QSTR_NORMAL; break;
151151
case CAN_MODE_LOOPBACK: mode = MP_QSTR_LOOPBACK; break;
152152
case CAN_MODE_SILENT: mode = MP_QSTR_SILENT; break;
153153
case CAN_MODE_SILENT_LOOPBACK: default: mode = MP_QSTR_SILENT_LOOPBACK; break;
154154
}
155-
print(env, "%s, ", qstr_str(mode));
155+
print(env, "%s, extframe=", qstr_str(mode));
156156
if (self->extframe) {
157157
mode = MP_QSTR_True;
158158
} else {
@@ -162,7 +162,7 @@ STATIC void pyb_can_print(void (*print)(void *env, const char *fmt, ...), void *
162162
}
163163
}
164164

165-
/// \method init(mode, prescaler=100, *, sjw=1, bs1=6, bs2=8)
165+
/// \method init(mode, extframe=False, prescaler=100, *, sjw=1, bs1=6, bs2=8)
166166
///
167167
/// Initialise the CAN bus with the given parameters:
168168
///
@@ -184,6 +184,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const
184184
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
185185

186186
self->extframe = args[1].u_bool;
187+
187188
// set the CAN configuration values
188189
memset(&self->can, 0, sizeof(self->can));
189190
CAN_InitTypeDef *init = &self->can.Init;

tests/pyb/can.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from pyb import CAN
22

3-
can = CAN(1, CAN.LOOPBACK)
3+
can = CAN(1)
4+
print(can)
5+
6+
can.init(CAN.LOOPBACK)
47
print(can)
58
print(can.any(0))
9+
610
can.send('abcd', 123)
711
print(can.any(0))
812
print(can.recv(0))
@@ -37,6 +41,3 @@
3741
print('passed')
3842
else:
3943
print('failed, wrong data received')
40-
41-
42-
print('end')

tests/pyb/can.py.exp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
CAN(1, LOOPBACK, False)
1+
CAN(1)
2+
CAN(1, CAN.LOOPBACK, extframe=False)
23
False
34
True
45
(123, 0, 0, b'abcd')
56
(2047, 0, 0, b'abcd')
67
(0, 0, 0, b'abcd')
78
passed
8-
CAN(1, LOOPBACK, True)
9+
CAN(1, CAN.LOOPBACK, extframe=True)
910
passed
10-
end

0 commit comments

Comments
 (0)