Skip to content

Commit a184a86

Browse files
committed
MCUXpresso: Update the SDK LPUART drivers
Use the latest driver from K66F Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent bff2875 commit a184a86

File tree

12 files changed

+786
-396
lines changed

12 files changed

+786
-396
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/drivers/fsl_lpuart.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2015, Freescale Semiconductor, Inc.
3-
* All rights reserved.
2+
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3+
* Copyright 2016-2017 NXP
44
*
55
* Redistribution and use in source and binary forms, with or without modification,
66
* are permitted provided that the following conditions are met:
@@ -12,7 +12,7 @@
1212
* list of conditions and the following disclaimer in the documentation and/or
1313
* other materials provided with the distribution.
1414
*
15-
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
15+
* o Neither the name of the copyright holder nor the names of its
1616
* contributors may be used to endorse or promote products derived from this
1717
* software without specific prior written permission.
1818
*
@@ -115,8 +115,17 @@ static const IRQn_Type s_lpuartTxIRQ[] = LPUART_TX_IRQS;
115115
#else
116116
static const IRQn_Type s_lpuartIRQ[] = LPUART_RX_TX_IRQS;
117117
#endif
118+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
118119
/* Array of LPUART clock name. */
119120
static const clock_ip_name_t s_lpuartClock[] = LPUART_CLOCKS;
121+
122+
#if defined(LPUART_PERIPH_CLOCKS)
123+
/* Array of LPUART functional clock name. */
124+
static const clock_ip_name_t s_lpuartPeriphClocks[] = LPUART_PERIPH_CLOCKS;
125+
#endif
126+
127+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
128+
120129
/* LPUART ISR for transactional APIs. */
121130
static lpuart_isr_t s_lpuartIsr;
122131

@@ -128,15 +137,15 @@ uint32_t LPUART_GetInstance(LPUART_Type *base)
128137
uint32_t instance;
129138

130139
/* Find the instance index from base address mappings. */
131-
for (instance = 0; instance < FSL_FEATURE_SOC_LPUART_COUNT; instance++)
140+
for (instance = 0; instance < ARRAY_SIZE(s_lpuartBases); instance++)
132141
{
133142
if (s_lpuartBases[instance] == base)
134143
{
135144
break;
136145
}
137146
}
138147

139-
assert(instance < FSL_FEATURE_SOC_LPUART_COUNT);
148+
assert(instance < ARRAY_SIZE(s_lpuartBases));
140149

141150
return instance;
142151
}
@@ -280,11 +289,25 @@ status_t LPUART_Init(LPUART_Type *base, const lpuart_config_t *config, uint32_t
280289
return kStatus_LPUART_BaudrateNotSupport;
281290
}
282291

292+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
293+
294+
uint32_t instance = LPUART_GetInstance(base);
295+
283296
/* Enable lpuart clock */
284-
CLOCK_EnableClock(s_lpuartClock[LPUART_GetInstance(base)]);
297+
CLOCK_EnableClock(s_lpuartClock[instance]);
298+
#if defined(LPUART_PERIPH_CLOCKS)
299+
CLOCK_EnableClock(s_lpuartPeriphClocks[instance]);
300+
#endif
301+
302+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
285303

304+
#if defined(FSL_FEATURE_LPUART_HAS_GLOBAL) && FSL_FEATURE_LPUART_HAS_GLOBAL
305+
/*Reset all internal logic and registers, except the Global Register */
306+
LPUART_SoftwareReset(base);
307+
#else
286308
/* Disable LPUART TX RX before setting. */
287309
base->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);
310+
#endif
288311

289312
temp = base->BAUD;
290313

@@ -422,8 +445,17 @@ void LPUART_Deinit(LPUART_Type *base)
422445
/* Disable the module. */
423446
base->CTRL = 0;
424447

448+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
449+
uint32_t instance = LPUART_GetInstance(base);
450+
425451
/* Disable lpuart clock */
426-
CLOCK_DisableClock(s_lpuartClock[LPUART_GetInstance(base)]);
452+
CLOCK_DisableClock(s_lpuartClock[instance]);
453+
454+
#if defined(LPUART_PERIPH_CLOCKS)
455+
CLOCK_DisableClock(s_lpuartPeriphClocks[instance]);
456+
#endif
457+
458+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
427459
}
428460

429461
void LPUART_GetDefaultConfig(lpuart_config_t *config)
@@ -861,7 +893,6 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
861893
size_t bytesToReceive;
862894
/* How many bytes currently have received. */
863895
size_t bytesCurrentReceived;
864-
uint32_t regPrimask = 0U;
865896

866897
/* How to get data:
867898
1. If RX ring buffer is not enabled, then save xfer->data and xfer->dataSize
@@ -885,8 +916,8 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
885916
/* If RX ring buffer is used. */
886917
if (handle->rxRingBuffer)
887918
{
888-
/* Disable IRQ, protect ring buffer. */
889-
regPrimask = DisableGlobalIRQ();
919+
/* Disable LPUART RX IRQ, protect ring buffer. */
920+
LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable);
890921

891922
/* How many bytes in RX ring buffer currently. */
892923
bytesToCopy = LPUART_TransferGetRxRingBufferLength(base, handle);
@@ -923,8 +954,8 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
923954
handle->rxDataSizeAll = bytesToReceive;
924955
handle->rxState = kLPUART_RxBusy;
925956
}
926-
/* Enable IRQ if previously enabled. */
927-
EnableGlobalIRQ(regPrimask);
957+
/* Enable LPUART RX IRQ if previously enabled. */
958+
LPUART_EnableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable);
928959

929960
/* Call user callback since all data are received. */
930961
if (0 == bytesToReceive)

0 commit comments

Comments
 (0)