Skip to content

Commit aa561f2

Browse files
ccli8adbridge
authored andcommitted
Fix incorrect use of peripheral name as peripheral base address
1 parent 48bbb7a commit aa561f2

File tree

4 files changed

+59
-53
lines changed

4 files changed

+59
-53
lines changed

targets/TARGET_NUVOTON/TARGET_M451/can_api.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
PA0 = 0x00;
7070
PA1 = 0x00;
7171

72-
CAN_Open((CAN_T *)obj->can, 500000, CAN_NORMAL_MODE);
72+
CAN_Open((CAN_T *)NU_MODBASE(obj->can), 500000, CAN_NORMAL_MODE);
7373

7474
can_filter(obj, 0, 0, CANStandard, 0);
7575
}
@@ -91,9 +91,9 @@ void can_free(can_t *obj)
9191

9292
int can_frequency(can_t *obj, int hz)
9393
{
94-
CAN_SetBaudRate((CAN_T *)obj->can, hz);
94+
CAN_SetBaudRate((CAN_T *)NU_MODBASE(obj->can), hz);
9595

96-
return CAN_GetCANBitRate((CAN_T *)obj->can);
96+
return CAN_GetCANBitRate((CAN_T *)NU_MODBASE(obj->can));
9797
}
9898

9999
static void can_irq(CANName name, int id)
@@ -154,7 +154,7 @@ void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id)
154154

155155
void can_irq_free(can_t *obj)
156156
{
157-
CAN_DisableInt((CAN_T *)obj->can, (CAN_CON_IE_Msk|CAN_CON_SIE_Msk|CAN_CON_EIE_Msk));
157+
CAN_DisableInt((CAN_T *)NU_MODBASE(obj->can), (CAN_CON_IE_Msk|CAN_CON_SIE_Msk|CAN_CON_EIE_Msk));
158158

159159
can_irq_ids[obj->index] = 0;
160160

@@ -163,32 +163,33 @@ void can_irq_free(can_t *obj)
163163

164164
void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable)
165165
{
166+
CAN_T *can_base = (CAN_T *) NU_MODBASE(obj->can);
166167

167-
CAN_EnterInitMode((CAN_T*)obj->can, ((enable != 0 )? CAN_CON_IE_Msk :0) );
168+
CAN_EnterInitMode(can_base, ((enable != 0 )? CAN_CON_IE_Msk :0) );
168169

169170

170171
switch (irq)
171172
{
172173
case IRQ_ERROR:
173174
case IRQ_BUS:
174175
case IRQ_PASSIVE:
175-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_EIE_Msk;
176-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_SIE_Msk;
176+
can_base->CON = can_base->CON |CAN_CON_EIE_Msk;
177+
can_base->CON = can_base->CON |CAN_CON_SIE_Msk;
177178
break;
178179

179180
case IRQ_RX:
180181
case IRQ_TX:
181182
case IRQ_OVERRUN:
182183
case IRQ_WAKEUP:
183-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_SIE_Msk;
184+
can_base->CON = can_base->CON |CAN_CON_SIE_Msk;
184185
break;
185186

186187
default:
187188
break;
188189

189190
}
190191

191-
CAN_LeaveInitMode((CAN_T*)obj->can);
192+
CAN_LeaveInitMode(can_base);
192193

193194
NVIC_SetVector(CAN0_IRQn, (uint32_t)&CAN0_IRQHandler);
194195
NVIC_EnableIRQ(CAN0_IRQn);
@@ -205,14 +206,14 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
205206
CMsg.DLC = msg.len;
206207
memcpy((void *)&CMsg.Data[0],(const void *)&msg.data[0], (unsigned int)8);
207208

208-
return CAN_Transmit((CAN_T *)(obj->can), cc, &CMsg);
209+
return CAN_Transmit((CAN_T *)NU_MODBASE(obj->can), cc, &CMsg);
209210
}
210211

211212
int can_read(can_t *obj, CAN_Message *msg, int handle)
212213
{
213214
STR_CANMSG_T CMsg;
214215

215-
if(!CAN_Receive((CAN_T *)(obj->can), handle, &CMsg))
216+
if(!CAN_Receive((CAN_T *)NU_MODBASE(obj->can), handle, &CMsg))
216217
return 0;
217218

218219
msg->format = (CANFormat)CMsg.IdType;
@@ -226,32 +227,34 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
226227

227228
int can_mode(can_t *obj, CanMode mode)
228229
{
230+
CAN_T *can_base = (CAN_T *) NU_MODBASE(obj->can);
231+
229232
int success = 0;
230233
switch (mode)
231234
{
232235
case MODE_RESET:
233-
CAN_LeaveTestMode((CAN_T*)obj->can);
236+
CAN_LeaveTestMode(can_base);
234237
success = 1;
235238
break;
236239

237240
case MODE_NORMAL:
238-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_BASIC_Msk);
241+
CAN_EnterTestMode(can_base, CAN_TEST_BASIC_Msk);
239242
success = 1;
240243
break;
241244

242245
case MODE_SILENT:
243-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk);
246+
CAN_EnterTestMode(can_base, CAN_TEST_SILENT_Msk);
244247
success = 1;
245248
break;
246249

247250
case MODE_TEST_LOCAL:
248251
case MODE_TEST_GLOBAL:
249-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_LBACK_Msk);
252+
CAN_EnterTestMode(can_base, CAN_TEST_LBACK_Msk);
250253
success = 1;
251254
break;
252255

253256
case MODE_TEST_SILENT:
254-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk);
257+
CAN_EnterTestMode(can_base, CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk);
255258
success = 1;
256259
break;
257260

@@ -267,7 +270,7 @@ int can_mode(can_t *obj, CanMode mode)
267270

268271
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
269272
{
270-
return CAN_SetRxMsg((CAN_T *)(obj->can), handle , (uint32_t)format, id);
273+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle , (uint32_t)format, id);
271274
}
272275

273276

@@ -285,19 +288,19 @@ void can_reset(can_t *obj)
285288

286289
unsigned char can_rderror(can_t *obj)
287290
{
288-
CAN_T *can = (CAN_T *)(obj->can);
291+
CAN_T *can = (CAN_T *)NU_MODBASE(obj->can);
289292
return ((can->ERR>>8)&0xFF);
290293
}
291294

292295
unsigned char can_tderror(can_t *obj)
293296
{
294-
CAN_T *can = (CAN_T *)(obj->can);
297+
CAN_T *can = (CAN_T *)NU_MODBASE(obj->can);
295298
return ((can->ERR)&0xFF);
296299
}
297300

298301
void can_monitor(can_t *obj, int silent)
299302
{
300-
CAN_EnterTestMode((CAN_T *)(obj->can), CAN_TEST_SILENT_Msk);
303+
CAN_EnterTestMode((CAN_T *)NU_MODBASE(obj->can), CAN_TEST_SILENT_Msk);
301304
}
302305

303306
#endif // DEVICE_CAN

targets/TARGET_NUVOTON/TARGET_M451/serial_api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ void serial_free(serial_t *obj)
255255

256256
void serial_baud(serial_t *obj, int baudrate) {
257257
// Flush Tx FIFO. Otherwise, output data may get lost on this change.
258-
while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart)));
258+
while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart))));
259259

260260
obj->serial.baudrate = baudrate;
261261
UART_Open((UART_T *) NU_MODBASE(obj->serial.uart), baudrate);
262262
}
263263

264264
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
265265
// Flush Tx FIFO. Otherwise, output data may get lost on this change.
266-
while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart)));
266+
while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart))));
267267

268268
// TODO: Assert for not supported parity and data bits
269269
obj->serial.databits = data_bits;
@@ -325,7 +325,7 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
325325
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
326326
{
327327
// Flush Tx FIFO. Otherwise, output data may get lost on this change.
328-
while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart)));
328+
while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart))));
329329

330330
const struct nu_modinit_s *modinit = get_modinit(obj->serial.uart, uart_modinit_tab);
331331
MBED_ASSERT(modinit != NULL);
@@ -515,7 +515,7 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
515515
// NUC472: End of source address
516516
// M451: Start of source address
517517
PDMA_SAR_INC, // Source address incremental
518-
(uint32_t) obj->serial.uart, // Destination address
518+
(uint32_t) NU_MODBASE(obj->serial.uart), // Destination address
519519
PDMA_DAR_FIX); // Destination address fixed
520520
PDMA_SetBurstType(obj->serial.dma_chn_id_tx,
521521
PDMA_REQ_SINGLE, // Single mode
@@ -572,7 +572,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
572572
(rx_width == 8) ? PDMA_WIDTH_8 : (rx_width == 16) ? PDMA_WIDTH_16 : PDMA_WIDTH_32,
573573
rx_length);
574574
PDMA_SetTransferAddr(obj->serial.dma_chn_id_rx,
575-
(uint32_t) obj->serial.uart, // Source address
575+
(uint32_t) NU_MODBASE(obj->serial.uart), // Source address
576576
PDMA_SAR_FIX, // Source address fixed
577577
(uint32_t) rx, // NOTE:
578578
// NUC472: End of destination address
@@ -593,7 +593,7 @@ void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_widt
593593
void serial_tx_abort_asynch(serial_t *obj)
594594
{
595595
// Flush Tx FIFO. Otherwise, output data may get lost on this change.
596-
while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart)));
596+
while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart))));
597597

598598
if (obj->serial.dma_usage_tx != DMA_USAGE_NEVER) {
599599
if (obj->serial.dma_chn_id_tx != DMA_ERROR_OUT_OF_CHANNELS) {

targets/TARGET_NUVOTON/TARGET_NUC472/can_api.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
PA2 = 0x00;
7676
PA3 = 0x00;
7777

78-
CAN_Open((CAN_T *)obj->can, 500000, CAN_NORMAL_MODE);
78+
CAN_Open((CAN_T *)NU_MODBASE(obj->can), 500000, CAN_NORMAL_MODE);
7979

8080
can_filter(obj, 0, 0, CANStandard, 0);
8181
}
@@ -97,9 +97,9 @@ void can_free(can_t *obj)
9797

9898
int can_frequency(can_t *obj, int hz)
9999
{
100-
CAN_SetBaudRate((CAN_T *)obj->can, hz);
100+
CAN_SetBaudRate((CAN_T *)NU_MODBASE(obj->can), hz);
101101

102-
return CAN_GetCANBitRate((CAN_T *)obj->can);
102+
return CAN_GetCANBitRate((CAN_T *)NU_MODBASE(obj->can));
103103
}
104104

105105
static void can_irq(CANName name, int id)
@@ -188,7 +188,7 @@ void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id)
188188

189189
void can_irq_free(can_t *obj)
190190
{
191-
CAN_DisableInt((CAN_T *)obj->can, (CAN_CON_IE_Msk|CAN_CON_SIE_Msk|CAN_CON_EIE_Msk));
191+
CAN_DisableInt((CAN_T *)NU_MODBASE(obj->can), (CAN_CON_IE_Msk|CAN_CON_SIE_Msk|CAN_CON_EIE_Msk));
192192

193193
can_irq_ids[obj->index] = 0;
194194

@@ -202,33 +202,34 @@ void can_irq_free(can_t *obj)
202202

203203
void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable)
204204
{
205+
CAN_T *can_base = (CAN_T *) NU_MODBASE(obj->can);
205206

206-
CAN_EnterInitMode((CAN_T*)obj->can);
207+
CAN_EnterInitMode((CAN_T*)can_base);
207208

208-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON ) | ((enable != 0 )? CAN_CON_IE_Msk :0);
209+
((CAN_T *)can_base)->CON = (((CAN_T *)can_base)->CON ) | ((enable != 0 )? CAN_CON_IE_Msk :0);
209210

210211
switch (irq)
211212
{
212213
case IRQ_ERROR:
213214
case IRQ_BUS:
214215
case IRQ_PASSIVE:
215-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_EIE_Msk;
216-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_SIE_Msk;
216+
can_base->CON = can_base->CON |CAN_CON_EIE_Msk;
217+
can_base->CON = can_base->CON |CAN_CON_SIE_Msk;
217218
break;
218219

219220
case IRQ_RX:
220221
case IRQ_TX:
221222
case IRQ_OVERRUN:
222223
case IRQ_WAKEUP:
223-
((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_SIE_Msk;
224+
can_base->CON = can_base->CON |CAN_CON_SIE_Msk;
224225
break;
225226

226227
default:
227228
break;
228229

229230
}
230231

231-
CAN_LeaveInitMode((CAN_T*)obj->can);
232+
CAN_LeaveInitMode(can_base);
232233

233234
if(!obj->index)
234235
{
@@ -253,14 +254,14 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
253254
CMsg.DLC = msg.len;
254255
memcpy((void *)&CMsg.Data[0],(const void *)&msg.data[0], (unsigned int)8);
255256

256-
return CAN_Transmit((CAN_T *)(obj->can), cc, &CMsg);
257+
return CAN_Transmit((CAN_T *)NU_MODBASE(obj->can), cc, &CMsg);
257258
}
258259

259260
int can_read(can_t *obj, CAN_Message *msg, int handle)
260261
{
261262
STR_CANMSG_T CMsg;
262263

263-
if(!CAN_Receive((CAN_T *)(obj->can), handle, &CMsg))
264+
if(!CAN_Receive((CAN_T *)NU_MODBASE(obj->can), handle, &CMsg))
264265
return 0;
265266

266267
msg->format = (CANFormat)CMsg.IdType;
@@ -274,32 +275,34 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
274275

275276
int can_mode(can_t *obj, CanMode mode)
276277
{
278+
CAN_T *can_base = (CAN_T *) NU_MODBASE(obj->can);
279+
277280
int success = 0;
278281
switch (mode)
279282
{
280283
case MODE_RESET:
281-
CAN_LeaveTestMode((CAN_T*)obj->can);
284+
CAN_LeaveTestMode(can_base);
282285
success = 1;
283286
break;
284287

285288
case MODE_NORMAL:
286-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_BASIC_Msk);
289+
CAN_EnterTestMode(can_base, CAN_TEST_BASIC_Msk);
287290
success = 1;
288291
break;
289292

290293
case MODE_SILENT:
291-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk);
294+
CAN_EnterTestMode(can_base, CAN_TEST_SILENT_Msk);
292295
success = 1;
293296
break;
294297

295298
case MODE_TEST_LOCAL:
296299
case MODE_TEST_GLOBAL:
297-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_LBACK_Msk);
300+
CAN_EnterTestMode(can_base, CAN_TEST_LBACK_Msk);
298301
success = 1;
299302
break;
300303

301304
case MODE_TEST_SILENT:
302-
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk);
305+
CAN_EnterTestMode(can_base, CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk);
303306
success = 1;
304307
break;
305308

@@ -315,7 +318,7 @@ int can_mode(can_t *obj, CanMode mode)
315318

316319
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
317320
{
318-
return CAN_SetRxMsg((CAN_T *)(obj->can), handle , (uint32_t)format, id);
321+
return CAN_SetRxMsg((CAN_T *)NU_MODBASE(obj->can), handle , (uint32_t)format, id);
319322
}
320323

321324

@@ -333,19 +336,19 @@ void can_reset(can_t *obj)
333336

334337
unsigned char can_rderror(can_t *obj)
335338
{
336-
CAN_T *can = (CAN_T *)(obj->can);
339+
CAN_T *can = (CAN_T *)NU_MODBASE(obj->can);
337340
return ((can->ERR>>8)&0xFF);
338341
}
339342

340343
unsigned char can_tderror(can_t *obj)
341344
{
342-
CAN_T *can = (CAN_T *)(obj->can);
345+
CAN_T *can = (CAN_T *)NU_MODBASE(obj->can);
343346
return ((can->ERR)&0xFF);
344347
}
345348

346349
void can_monitor(can_t *obj, int silent)
347350
{
348-
CAN_EnterTestMode((CAN_T *)(obj->can), CAN_TEST_SILENT_Msk);
351+
CAN_EnterTestMode((CAN_T *)NU_MODBASE(obj->can), CAN_TEST_SILENT_Msk);
349352
}
350353

351354
#endif // DEVICE_CAN

0 commit comments

Comments
 (0)