Skip to content

Commit eff848a

Browse files
committed
LPC546XX: Update SDK driver to version 2.3
Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 1079767 commit eff848a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2912
-835
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC546XX/drivers/fsl_adc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/*
2+
* The Clear BSD License
23
* Copyright (c) 2016, Freescale Semiconductor, Inc.
34
* Copyright 2016-2017 NXP
5+
* All rights reserved.
46
*
57
* Redistribution and use in source and binary forms, with or without modification,
6-
* are permitted provided that the following conditions are met:
8+
* are permitted (subject to the limitations in the disclaimer below) provided
9+
* that the following conditions are met:
710
*
811
* o Redistributions of source code must retain the above copyright notice, this list
912
* of conditions and the following disclaimer.
@@ -16,6 +19,7 @@
1619
* contributors may be used to endorse or promote products derived from this
1720
* software without specific prior written permission.
1821
*
22+
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
1923
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2024
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2125
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC546XX/drivers/fsl_adc.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/*
2+
* The Clear BSD License
23
* Copyright (c) 2016, Freescale Semiconductor, Inc.
34
* Copyright 2016-2017 NXP
5+
* All rights reserved.
46
*
57
* Redistribution and use in source and binary forms, with or without modification,
6-
* are permitted provided that the following conditions are met:
8+
* are permitted (subject to the limitations in the disclaimer below) provided
9+
* that the following conditions are met:
710
*
811
* o Redistributions of source code must retain the above copyright notice, this list
912
* of conditions and the following disclaimer.
@@ -16,6 +19,7 @@
1619
* contributors may be used to endorse or promote products derived from this
1720
* software without specific prior written permission.
1821
*
22+
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
1923
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2024
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2125
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -46,8 +50,8 @@
4650

4751
/*! @name Driver version */
4852
/*@{*/
49-
/*! @brief ADC driver version 2.0.0. */
50-
#define LPC_ADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
53+
/*! @brief ADC driver version 2.1.0. */
54+
#define LPC_ADC_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
5155
/*@}*/
5256

5357
/*!
@@ -150,7 +154,7 @@ typedef enum _adc_trigger_polarity
150154
typedef enum _adc_priority
151155
{
152156
kADC_PriorityLow = 0U, /*!< This sequence would be preempted when another sequence is started. */
153-
kADC_PriorityHigh = 1U, /*!< This sequence would preempt other sequence even when is is started. */
157+
kADC_PriorityHigh = 1U, /*!< This sequence would preempt other sequence even when it is started. */
154158
} adc_priority_t;
155159

156160
/*!
@@ -247,7 +251,7 @@ typedef struct _adc_conv_seq_config
247251
*/
248252
typedef struct _adc_result_info
249253
{
250-
uint32_t result; /*!< Keey the conversion data value. */
254+
uint32_t result; /*!< Keep the conversion data value. */
251255
adc_threshold_compare_status_t thresholdCompareStatus; /*!< Keep the threshold compare status. */
252256
adc_threshold_crossing_status_t thresholdCorssingStatus; /*!< Keep the threshold crossing status. */
253257
uint32_t channelNumber; /*!< Keep the channel number for this conversion. */
@@ -307,6 +311,7 @@ void ADC_GetDefaultConfig(adc_config_t *config);
307311
*/
308312
bool ADC_DoSelfCalibration(ADC_Type *base);
309313

314+
#if !(defined(FSL_FEATURE_ADC_HAS_NO_INSEL) && FSL_FEATURE_ADC_HAS_NO_INSEL)
310315
/*!
311316
* @brief Enable the internal temperature sensor measurement.
312317
*
@@ -327,7 +332,7 @@ static inline void ADC_EnableTemperatureSensor(ADC_Type *base, bool enable)
327332
base->INSEL = (base->INSEL & ~ADC_INSEL_SEL_MASK) | ADC_INSEL_SEL(0);
328333
}
329334
}
330-
335+
#endif /* FSL_FEATURE_ADC_HAS_NO_INSEL. */
331336
/* @} */
332337

333338
/*!
@@ -611,13 +616,24 @@ static inline void ADC_DisableInterrupts(ADC_Type *base, uint32_t mask)
611616
}
612617

613618
/*!
614-
* @brief Enable the interrupt of shreshold compare event for each channel.
619+
* @brief Enable the interrupt of threshold compare event for each channel.
620+
* @deprecated Do not use this function. It has been superceded by @ADC_EnableThresholdCompareInterrupt
621+
*/
622+
static inline void ADC_EnableShresholdCompareInterrupt(ADC_Type *base,
623+
uint32_t channel,
624+
adc_threshold_interrupt_mode_t mode)
625+
{
626+
base->INTEN = (base->INTEN & ~(0x3U << ((channel << 1U) + 3U))) | ((uint32_t)(mode) << ((channel << 1U) + 3U));
627+
}
628+
629+
/*!
630+
* @brief Enable the interrupt of threshold compare event for each channel.
615631
*
616632
* @param base ADC peripheral base address.
617633
* @param channel Channel number.
618634
* @param mode Interrupt mode for threshold compare event, see to #adc_threshold_interrupt_mode_t.
619635
*/
620-
static inline void ADC_EnableShresholdCompareInterrupt(ADC_Type *base,
636+
static inline void ADC_EnableThresholdCompareInterrupt(ADC_Type *base,
621637
uint32_t channel,
622638
adc_threshold_interrupt_mode_t mode)
623639
{

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC546XX/drivers/fsl_clock.c

Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/*
2+
* The Clear BSD License
23
* Copyright (c) 2016, Freescale Semiconductor, Inc.
34
* Copyright (c) 2016 - 2017 , NXP
45
* All rights reserved.
56
*
7+
*
68
* Redistribution and use in source and binary forms, with or without modification,
7-
* are permitted provided that the following conditions are met:
9+
* are permitted (subject to the limitations in the disclaimer below) provided
10+
* that the following conditions are met:
811
*
912
* o Redistributions of source code must retain the above copyright notice, this list
1013
* of conditions and the following disclaimer.
@@ -17,6 +20,7 @@
1720
* contributors may be used to endorse or promote products derived from this
1821
* software without specific prior written permission.
1922
*
23+
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
2024
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2125
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2226
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -150,6 +154,10 @@ static uint32_t findPllPreDiv(uint32_t ctrlReg, uint32_t nDecReg);
150154
static uint32_t findPllPostDiv(uint32_t ctrlReg, uint32_t pDecReg);
151155
/* Get multiplier (M) from PLL MDEC and BYPASS_FBDIV2 settings */
152156
static uint32_t findPllMMult(uint32_t ctrlReg, uint32_t mDecReg);
157+
/* Convert the binary to fractional part */
158+
static double Binary2Fractional(uint32_t binaryPart);
159+
/* Calculate the powerTimes' power of 2 */
160+
static uint32_t power2Cal(uint32_t powerTimes);
153161
/* Get the greatest common divisor */
154162
static uint32_t FindGreatestCommonDivisor(uint32_t m, uint32_t n);
155163
/* Set PLL output based on desired output rate */
@@ -969,6 +977,25 @@ static uint32_t findPllMMult(uint32_t ctrlReg, uint32_t mDecReg)
969977
return mMult;
970978
}
971979

980+
/* Calculate the powerTimes' power of 2 */
981+
static uint32_t power2Cal(uint32_t powerTimes)
982+
{
983+
if (powerTimes == 0)
984+
return 1;
985+
return 2 * power2Cal(powerTimes - 1);
986+
}
987+
988+
/* Convert the binary to fractional part */
989+
static double Binary2Fractional(uint32_t binaryPart)
990+
{
991+
double fractional = 0;
992+
for (uint32_t i = 0; i <= 14; i++)
993+
{
994+
fractional += (double)((binaryPart >> i) & 0x1U) / (double)power2Cal(15 - i);
995+
}
996+
return fractional;
997+
}
998+
972999
/* Find greatest common divisor between m and n */
9731000
static uint32_t FindGreatestCommonDivisor(uint32_t m, uint32_t n)
9741001
{
@@ -1174,6 +1201,12 @@ static void CLOCK_GetAudioPLLOutFromSetupUpdate(pll_setup_t *pSetup)
11741201
s_Audio_Pll_Freq = CLOCK_GetAudioPLLOutFromSetup(pSetup);
11751202
}
11761203

1204+
/* Update AUDIO Fractional PLL rate variable */
1205+
static void CLOCK_GetAudioPLLOutFromAudioFracSetupUpdate(pll_setup_t *pSetup)
1206+
{
1207+
s_Audio_Pll_Freq = CLOCK_GetAudioPLLOutFromFractSetup(pSetup);
1208+
}
1209+
11771210
/* Update USB PLL rate variable */
11781211
static void CLOCK_GetUsbPLLOutFromSetupUpdate(const usb_pll_setup_t *pSetup)
11791212
{
@@ -1366,6 +1399,58 @@ uint32_t CLOCK_GetAudioPLLOutFromSetup(pll_setup_t *pSetup)
13661399
return (uint32_t)workRate;
13671400
}
13681401

1402+
/* Return Audio PLL output clock rate from audio fractioanl setup structure */
1403+
uint32_t CLOCK_GetAudioPLLOutFromFractSetup(pll_setup_t *pSetup)
1404+
{
1405+
uint32_t prediv, postdiv, inPllRate;
1406+
double workRate, mMultFactional;
1407+
1408+
inPllRate = CLOCK_GetAudioPLLInClockRate();
1409+
if ((pSetup->pllctrl & (1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT)) == 0U)
1410+
{
1411+
/* PLL is not in bypass mode, get pre-divider, and M divider, post-divider. */
1412+
/*
1413+
* 1. Pre-divider
1414+
* Pre-divider is only available when the DIRECTI is disabled.
1415+
*/
1416+
if (0U == (pSetup->pllctrl & SYSCON_AUDPLLCTRL_DIRECTI_MASK))
1417+
{
1418+
prediv = findPllPreDiv(pSetup->pllctrl, pSetup->pllndec);
1419+
}
1420+
else
1421+
{
1422+
prediv = 1U; /* The pre-divider is bypassed. */
1423+
}
1424+
/*
1425+
* 2. Post-divider
1426+
* Post-divider is only available when the DIRECTO is disabled.
1427+
*/
1428+
if (0U == (pSetup->pllctrl & SYSCON_AUDPLLCTRL_DIRECTO_MASK))
1429+
{
1430+
postdiv = findPllPostDiv(pSetup->pllctrl, pSetup->pllpdec);
1431+
}
1432+
else
1433+
{
1434+
postdiv = 1U; /* The post-divider is bypassed. */
1435+
}
1436+
/* Adjust input clock */
1437+
inPllRate = inPllRate / prediv;
1438+
1439+
mMultFactional = (double)(pSetup->audpllfrac >> 15) + (double)Binary2Fractional(pSetup->audpllfrac & 0x7FFFU);
1440+
workRate = (double)inPllRate * (double)mMultFactional;
1441+
1442+
workRate = workRate / ((double)postdiv);
1443+
workRate = workRate * 2U; /* SYS PLL hardware cco is divide by 2 before to M-DIVIDER*/
1444+
}
1445+
else
1446+
{
1447+
/* In bypass mode */
1448+
workRate = (uint64_t)inPllRate;
1449+
}
1450+
1451+
return (uint32_t)workRate;
1452+
}
1453+
13691454
/* Set the current PLL Rate */
13701455
void CLOCK_SetStoredPLLClockRate(uint32_t rate)
13711456
{
@@ -1609,6 +1694,48 @@ pll_error_t CLOCK_SetupAudioPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg)
16091694
return kStatus_PLL_Success;
16101695
}
16111696

1697+
/* Set AUDIO PLL output from AUDIO PLL fractional setup structure */
1698+
pll_error_t CLOCK_SetupAudioPLLPrecFract(pll_setup_t *pSetup, uint32_t flagcfg)
1699+
{
1700+
if ((SYSCON->AUDPLLCLKSEL & SYSCON_AUDPLLCLKSEL_SEL_MASK) == 0x01U)
1701+
{
1702+
/* Turn on the ext clock if system pll input select clk_in */
1703+
CLOCK_Enable_SysOsc(true);
1704+
}
1705+
/* Enable power VD3 for PLLs */
1706+
POWER_SetPLL();
1707+
/* Power off PLL during setup changes */
1708+
POWER_EnablePD(kPDRUNCFG_PD_AUDIO_PLL);
1709+
1710+
pSetup->flags = flagcfg;
1711+
1712+
/* Write PLL setup data */
1713+
SYSCON->AUDPLLCTRL = pSetup->pllctrl;
1714+
SYSCON->AUDPLLNDEC = pSetup->pllndec;
1715+
SYSCON->AUDPLLNDEC = pSetup->pllndec | (1U << SYSCON_SYSPLLNDEC_NREQ_SHIFT); /* latch */
1716+
SYSCON->AUDPLLPDEC = pSetup->pllpdec;
1717+
SYSCON->AUDPLLPDEC = pSetup->pllpdec | (1U << SYSCON_SYSPLLPDEC_PREQ_SHIFT); /* latch */
1718+
SYSCON->AUDPLLMDEC = pSetup->pllmdec;
1719+
SYSCON->AUDPLLFRAC = SYSCON_AUDPLLFRAC_SEL_EXT(0); /* enable fractional function */
1720+
SYSCON->AUDPLLFRAC = pSetup->audpllfrac;
1721+
SYSCON->AUDPLLFRAC = pSetup->audpllfrac | (1U << SYSCON_AUDPLLFRAC_REQ_SHIFT);
1722+
1723+
/* Enable peripheral states by setting low */
1724+
POWER_DisablePD(kPDRUNCFG_PD_AUDIO_PLL);
1725+
1726+
if ((pSetup->flags & PLL_SETUPFLAG_WAITLOCK) != 0U)
1727+
{
1728+
while (CLOCK_IsAudioPLLLocked() == false)
1729+
{
1730+
}
1731+
}
1732+
1733+
/* Update current programmed PLL rate var */
1734+
CLOCK_GetAudioPLLOutFromAudioFracSetupUpdate(pSetup);
1735+
1736+
return kStatus_PLL_Success;
1737+
}
1738+
16121739
/* Set Audio PLL output based on the passed Audio PLL setup data */
16131740
pll_error_t CLOCK_SetupAudioPLLData(pll_config_t *pControl, pll_setup_t *pSetup)
16141741
{
@@ -1819,7 +1946,7 @@ pll_error_t CLOCK_SetUsbPLLFreq(const usb_pll_setup_t *pSetup)
18191946
}
18201947

18211948
/* If configure the USB HOST clock, VD5 power for USB PHY should be enable
1822-
before the the PLL is working */
1949+
before the PLL is working */
18231950
/* Turn on the ext clock for usb pll input */
18241951
CLOCK_Enable_SysOsc(true);
18251952

0 commit comments

Comments
 (0)