在线时间96 小时
UID3167208
注册时间2015-10-21
NXP金币0
TA的每日心情 | 开心 2019-3-22 20:15 |
---|
签到天数: 21 天 连续签到: 1 天 [LV.4]偶尔看看III
高级会员

- 积分
- 909
- 最后登录
- 2019-4-7
|
本帖最后由 噬猎者 于 2016-11-20 20:38 编辑
1.LPC54102概述:LPC54102主要特性和优势:
Dual processor cores: ARM Cortex-M4 and ARM Cortex-M0+. The M0+ core runs at the same frequency as the M4 core. Both cores operate up to a maximum frequency of 100 MHz.
ARM Cortex-M4F core (version r0p1):
ARM Cortex-M4 processor, running at a frequency of up to 100 MHz.
Floating Point Unit (FPU) and Memory Protection Unit (MPU).
ARM Cortex-M4 built-in Nested Vectored Interrupt Controller (NVIC).
Non-maskable Interrupt (NMI) input with a selection of sources.
Serial Wire Debug with eight breakpoints and four watch points.
Includes Serial Wire Output for enhanced debug capabilities.
System tick timer.
ARM Cortex-M0+ core (version r0p1):
ARM Cortex-M0+ processor, running at a frequency of up to 100 MHz.
ARM Cortex-M0+ built-in Nested Vectored Interrupt Controller (NVIC).
Non-maskable Interrupt (NMI) input with a selection of sources.
Serial Wire Debug with four breakpoints and two watch points.
System tick timer.
On-chip memory:
Up to 512 KB on-chip flash program memory with flash accelerator and 256 byte page erase and write.
104 KB SRAM for code and data use.
ROM API support:
Flash In-Application Programming (IAP) and In-System Programming (ISP).
Power control API.
Serial interfaces:
Four USART interfaces with synchronous mode and 32 kHz mode for wake-up from Deep-sleep and Power-down modes. The USARTs include a FIFO buffer and share a fractional baud-rate generator.
Two SPI interfaces, each with four slave selects and flexible data configuration.
The SPIs include a FIFO buffer. The slave function is able to wake up the device from Deep-sleep and Power-down modes.
Three I2C-bus interfaces supporting fast mode and Fast-mode Plus with data rates of up to 1Mbit/s and with multiple address recognition and monitor mode. Each I2C-bus interface also supports High Speed Mode (3.4 Mbit/s) as a slave. The slave function is able to wake up the device from Deep-sleep and Power-down modes.
Digital peripherals:
DMA controller with 22 channels and 20 programmable triggers, able to access all memories and DMA-capable peripherals.
Up to 50 General-Purpose Input/Output (GPIO) pins. Most GPIOs have configurable pull-up/pull-down resistors, programmable open-drain mode, and input/output inverter.
GPIO registers are located on the AHB for fast access. The DMA supports GPIO ports.
Up to eight GPIOs can be selected as pin interrupts (PINT), triggered by rising,falling or both input edges.
Two GPIO grouped interrupts (GINT) enable an interrupt based on a logical (AND/OR) combination of input states.
CRC engine.
Timers:
Five 32-bit general purpose timers/counters, with up to 4 capture inputs and 4 compare outputs, PWM mode, and external count input. Specific timer events can be selected to generate DMA requests.
One State Configurable Timer/PWM (SCT) with 6 input and 8 output functions
(including capture and match). Inputs and outputs can be routed to/from external pins and internally to/from selected peripherals. Internally, the SCT supports 13 captures/matches, 13 events and 13 states.
32-bit Real-time clock (RTC) with 1 s resolution running in the always-on power domain. A timer in the RTC can be used for wake-up from all low power modes including Deep power-down, with 1 ms resolution. The RTC is clocked by the 32 kHz oscillator.
Multiple-channel multi-rate 24-bit timer (MRT) for repetitive interrupt generation at up to four programmable, fixed rates.
Windowed Watchdog Timer (WWDT).
Ultra-low power Micro-tick Timer, running from the Watchdog oscillator,that can beused to wake up the device from low power modes.
Repetitive Interrupt Timer (RIT) for debug time-stamping and general-purpose use.
Analog peripheral: 12-bit, 12-channel, Analog-to-Digital Converter (ADC) supporting 4.8 Msamples/s. The ADC supports two independent conversion sequences.
Clock generation:
12 MHz internal RC oscillator.
External clock input for clock frequencies of up to 24 MHz.
Internal low-power, watchdog oscillator with a nominal frequency of 500 kHz (WDOSC).
32 kHz low-power RTC oscillator.
System PLL allows CPU operation up to the maximum CPU rate. May be run from the internal RC oscillator, the external clock input CLKIN, or the RTC oscillator.
Clock output function for monitoring internal clocks.
Frequency measurement unit for measuring the frequency of any on-chip or off-chip clock signal.
Power-saving modes and wake-up:
Integrated PMU (Power Management Unit) to minimize power consumption.
Reduced power modes: Sleep, Deep-sleep, Power-down, and Deep power-down.
Wake-up from Deep-sleep and Power-down modes via activity on the USART, SPI,and I2C peripherals.
Wake-up from Sleep, Deep-sleep, Power-down, and Deep power-down modes using the RTC alarm.
The Micro-tick Timer can wake-up the device from the Deep power-down mode by using the watchdog oscillator when no other on-chip resources are running.
Single power supply 1.62 V to 3.6 V.
Power-On Reset (POR).
Brown-Out Detect (BOD) with separate thresholds for interrupt and forced reset.
JTAG boundary scan supported.
Unique device serial number for identification.
Operating temperature range 40 ℃ to 105 ℃.
Available in a 3.288 x 3.288 mm WLCSP49 package and LQFP64 package.
看到这些,我们可以大致了解这款芯片
1.管脚少 - 49to64Pin 更适应于便携产品
2.低功耗-尽管M4 架构很费电,但是由于LPC54102具有双核优势,M0 Plus的协处理器可以有效降低功耗 3.低电压 1.8Vor3.3V电压供电,方便电池供电
4.高速ADC,天哪,有5M的ADC啊。。。不过实际上使用时达不到5M,这个仅限于理论。
5.PMU MMU FPU ...从寄存器上看每个管脚都配有电流检测,复位等功能,这也是这款芯片更具备稳定性的原因。
6.不需要外部晶振!真的不需要,这真的是大大节省了空间,降低了生产成本(不过等芯片价格降下来再说了)。
7.这款芯片效仿了现在最流行的架构,功能模块分离,这样保证了芯片管脚的速率,提高稳定性。
8.总的来说,这芯片还可以。
2.分享给大家这些LPC54102的资料(都是有用的,没用的我是不会给你的 ):
1.软件安装(给大家提供了 LPC54102的PACK ,LPC_Driver驱动,LPCXpresso软件,选下)
- 链接:https://pan.baidu.com/s/1sllJLuP 密码:uybp
复制代码
2.关于LPC54102芯片有关的开发板原理图(如果你要是用于产品,做PCB肯定会需要它的)
- 链接:https://pan.baidu.com/s/1slEkfoT 密码:37uh
复制代码
3.LPC54102库编程----这里有好多公司开发的库,当然都是拿NXP公司的库改的。。。普通人就用这个就很好了
(简单来说下这个库,库值能调用,不能重新编写,这也是公司便于用户使用做的,但不适合所有人开发,当然也不适合我,不过初学者肯定需要用这个入门,了解NXP公司的编程规则)
- 链接:https://pan.baidu.com/s/1c1K0apa 密码:doja
复制代码
4.NXP-LPC54102开发资料(像低功耗掉电模式等特殊功能着重讲解进行)
- 链接:https://pan.baidu.com/s/1eSNZVBc 密码:8jb8
复制代码
5.寄存器开发利器(LPC54102寄存器手册,这个手册是我好不容易搞来的,这里非常感谢那位好心的工程师)
【这么说吧,今后我讲得所有的东西都是围绕这本寄存器手册讲解的,包括寄存器开发,从启动文件进行逐渐讲解开发流程。我这刚写出了一份精简版的LPC54102_CMSIS,加上总工程一共64kb,这和库开发相比速度更快,编译更快,执行效率更高】
- 链接:https://pan.baidu.com/s/1c2mQs2c 密码:renw
复制代码
3.LPC寄存器开发入门(我们以M4内核来进行讲解寄存器开发,首先需要了解到LPC的启动顺序)
1.启动文件: keil_startup_lpc5410x.s//CORE_M4内核启动
经过许多声明文件---->SystemInit这个函数 ---->main函数
2.SystemInit//系统初始化函数,用于初始化时钟以及相应的配置文件尽管M4内核和M0内核可以同时编译不过为了方便用户理解,还是分成两个不同的工程建立,这里面只存放M4内核的文件。
- void SystemInit(void)//系统初始化函数
- {
- extern void *__Vectors;
- SCB->VTOR = (uint32_t) &__Vectors;
- FPU_Init();//FPU初始化
- Board_SystemInit();//时钟初始化
- }
复制代码 率先启动的是FPU,这个寄存器已经在CORE_M4内核文件已经定义了,我们简单看下它的初始化过程:
- //FPU配置文件
- #define LPC_CPACR 0xE000ED88
- #define SCB_MVFR0 0xE000EF40
- #define SCB_MVFR0_RESET 0x10110021
- #define SCB_MVFR1 0xE000EF44
- #define SCB_MVFR1_RESET 0x11000011
- void FPU_Init(void)//FPU初始化
- {
- volatile uint32_t *regCpacr = (uint32_t *) LPC_CPACR;
- volatile uint32_t *regMvfr0 = (uint32_t *) SCB_MVFR0;
- volatile uint32_t *regMvfr1 = (uint32_t *) SCB_MVFR1;
- volatile uint32_t Cpacr;
- volatile uint32_t Mvfr0;
- volatile uint32_t Mvfr1;
- char vfpPresent = 0;
- Mvfr0 = *regMvfr0;
- Mvfr1 = *regMvfr1;
- vfpPresent = ((SCB_MVFR0_RESET == Mvfr0) && (SCB_MVFR1_RESET == Mvfr1));
- if (vfpPresent) {
- Cpacr = *regCpacr;
- Cpacr |= (0xF << 20);
- *regCpacr = Cpacr; // enable CP10 and CP11 for full access
- }
- }
复制代码 我们在这只借助内部IRC时钟启动具体讲解启动过程。
SYSCON寄存器:
打开寄存器手册第26页,在SYSCON中有50个配置寄存器,以下是我的寄存器编程方式, 地址+结构体,这样也是为了方便查找寄存器手册。
- /* ----------------------------------------------------------------------------
- -- System configuration (SYSCON)
- ---------------------------------------------------------------------------- */
- // LPC5410x System configuration (SYSCON) P26
- //Register overview: Main system configuration (base address 0x4000 0000)
- //地址
- #define SYSCON_BASE_PTR ((SYSCON_MemMapPtr)0x40000000UL)
- //结构体
- typedef struct SYSCON_MemMap{
- uint32_t AHBMATPRIO; /*!< System Remap register */
- uint32_t RESERVED0[4];
- uint32_t SYSTCKCAL; /*!< System Tick Calibration register */
- uint32_t RESERVED1[1];
- uint32_t NMISRC; /*!< NMI Source select register */
- uint32_t ASYNCAPBCTRL; /*!< Asynch APB chiplet control register */
- uint32_t RESERVED2[7];
- uint32_t SYSRSTSTAT; /*!< System Reset Stat register */
- uint32_t PRESETCTRL[2]; /*!< Peripheral Reset Ctrl register */
- uint32_t PRESETCTRLSET[2];/*!< Peripheral Reset Ctrl Set register */
- uint32_t PRESETCTRLCLR[2];/*!< Peripheral Reset Ctrl Clr register */
- uint32_t PIOPORCAP[2]; /*!< PIO Power-On Reset Capture register */
- uint32_t RESERVED3[1];
- uint32_t PIORESCAP[2]; /*!< PIO Pad Reset Capture register */
- uint32_t RESERVED4[4];
- uint32_t MAINCLKSELA; /*!< Main Clk sel Source Sel A register */
- uint32_t MAINCLKSELB; /*!< Main Clk sel Source Sel B register */
- uint32_t RESERVED5;
- uint32_t ADCCLKSEL; /*!< ADC Async Clk Sel register */
- uint32_t RESERVED6;
- uint32_t CLKOUTSELA; /*!< Clk Out Sel Source A register */
- uint32_t CLKOUTSELB; /*!< Clk Out Sel Source B register */
- uint32_t RESERVED7;
- uint32_t SYSPLLCLKSEL; /*!< System PLL Clk Selregister */
- uint32_t RESERVED8[7];
- uint32_t AHBCLKCTRL[2]; /*!< AHB Peripheral Clk Enable register */
- uint32_t AHBCLKCTRLSET[2];/*!< AHB Peripheral Clk Enable Set register */
- uint32_t AHBCLKCTRLCLR[2];/*!< AHB Peripheral Clk Enable Clr register */
- uint32_t RESERVED9[2];
- uint32_t SYSTICKCLKDIV; /*!< Systick Clock divider register */
- uint32_t RESERVED10[7];
- uint32_t AHBCLKDIV; /*!< Main Clk Divider register */
- uint32_t RESERVED11;
- uint32_t ADCCLKDIV; /*!< ADC Async Clk Divider register */
- uint32_t CLKOUTDIV; /*!< Clk Out Divider register */
- uint32_t RESERVED12[4];
- uint32_t FREQMECTRL; /*!< Frequency Measure Control register */
- uint32_t FLASHCFG; /*!< Flash Config register */
- uint32_t RESERVED13[8];
- uint32_t FIFOCTRL; /*!< VFIFO control register */
- uint32_t RESERVED14[14];
- uint32_t RESERVED15[1];
- uint32_t RESERVED16[2];
- uint32_t RTCOSCCTRL; /*!< RTC Oscillator Control register */
- uint32_t RESERVED17[7];
- uint32_t SYSPLLCTRL; /*!< System PLL control register */
- uint32_t SYSPLLSTAT; /*!< PLL status register */
- uint32_t SYSPLLNDEC; /*!< PLL N decoder register */
- uint32_t SYSPLLPDEC; /*!< PLL P decoder register */
- uint32_t SYSPLLSSCTRL[2]; /*!< Spread Spectrum control registers */
- uint32_t RESERVED18[18];
- uint32_t PDRUNCFG; /*!< Power Down Run Config register */
- uint32_t PDRUNCFGSET; /*!< Power Down Run Config Set register */
- uint32_t PDRUNCFGCLR; /*!< Power Down Run Config Clr register */
- uint32_t RESERVED19[9];
- uint32_t STARTERP[2]; /*!< Start Signal Enable Register */
- uint32_t STARTERSET[2]; /*!< Start Signal Enable Set Register */
- uint32_t STARTERCLR[2]; /*!< Start Signal Enable Clr Register */
- uint32_t RESERVED20[42];
- uint32_t RESERVED20A[4];
- uint32_t RESERVED21[57];
- uint32_t JTAG_IDCODE;
- uint32_t DEVICE_ID0; /*!< Boot ROM and die revision register */
- uint32_t DEVICE_ID1; /*!< Boot ROM and die revision register */
- } volatile *SYSCON_MemMapPtr;
复制代码
1.我们首先关注的是Board_SYSCON_PowerUp 函数 ,同时对应着 Board_SYSCON_PowerDown函数
这两个函数主要作用是用于控制模块电源的。
这两个寄存器的配置在P54
SYSCON_BASE_PTR-> DRUNCFGCLR //Power Down Run Config Clr register
SYSCON_BASE_PTR-> DRUNCFGSET //Power Down Run Config Set register
一般可以直接用PDRUNCFG对寄存器进行写0写1,但是为防止出现问题采用 SET 和 CLR 寄存分别进行 开关。同样控制的还是 CFG寄存器的数据
为了对其进行快速配置,我们采用宏定义方式对其操作:
例如: Board_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_IRC_OSC | SYSCON_PDRUNCFG_PD_IRC);
- //电源控制寄存器
- //SYSCON->PDRUNCFGCLR
- //SYSCON->PDRUNCFGSET
- /* Power control definition bits (0 = powered, 1 = powered down) */
- #define SYSCON_PDRUNCFG_PD_IRC_OSC (1 << 3) /*!< IRC oscillator output */
- #define SYSCON_PDRUNCFG_PD_IRC (1 << 4) /*!< IRC oscillator */
- #define SYSCON_PDRUNCFG_PD_FLASH (1 << 5) /*!< Flash memory */
- #define SYSCON_PDRUNCFG_PD_BOD_RST (1 << 7) /*!< Brown-out Detect reset */
- #define SYSCON_PDRUNCFG_PD_BOD_INTR (1 << 8) /*!< Brown-out Detect interrupt */
- #define SYSCON_PDRUNCFG_PD_ADC0 (1 << 10) /*!< ADC0 */
- #define SYSCON_PDRUNCFG_PD_SRAM0A (1 << 13) /*!< First 8 kB of SRAM0 */
- #define SYSCON_PDRUNCFG_PD_SRAM0B (1 << 14) /*!< Remaining portion of SRAM0 */
- #define SYSCON_PDRUNCFG_PD_SRAM1 (1 << 15) /*!< SRAM1 */
- #define SYSCON_PDRUNCFG_PD_SRAM2 (1 << 16) /*!< SRAM2 */
- #define SYSCON_PDRUNCFG_PD_ROM (1 << 17) /*!< ROM */
- #define SYSCON_PDRUNCFG_PD_VDDA_ENA (1 << 19) /*!< Vdda to the ADC, must be enabled for the ADC to work */
- #define SYSCON_PDRUNCFG_PD_WDT_OSC (1 << 20) /*!< Watchdog oscillator */
- #define SYSCON_PDRUNCFG_PD_SYS_PLL (1 << 22) /*!< PLL0 */
- #define SYSCON_PDRUNCFG_PD_VREFP (1 << 23) /*!< Vrefp to the ADC, must be enabled for the ADC to work */
- #define SYSCON_PDRUNCFG_PD_32K_OSC (1 << 24) /*!< 32 kHz RTC oscillator */
复制代码 同理对于其他寄存器我们也是进行类似操作。
2.内部时钟和锁相环初始化函数的寄存器简要介绍:
- void Board_SetupIrcClocking(void)//启动内部时钟震荡器
- {
- PLL_CONFIG_T pllConfig;
- PLL_SETUP_T pllSetup;
- PLL_ERROR_T pllError;
- /* Turn on the IRC by clearing the power down bit 通过清除掉电点 打开IRC */
- Board_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_IRC_OSC | SYSCON_PDRUNCFG_PD_IRC);
- /* Select the PLL input to the IRC 选择PLL的输入为IRC */
- Board_Clock_SetSystemPLLSource(SYSCON_PLLCLKSRC_IRC);
- /* Setup FLASH access 启动Flash配置 */
- Board_SetupFlashClocks();
- /* Power down PLL to change the PLL divider ratio 掉电锁相环改变锁相环分频比 */
- Board_SYSCON_PowerDown(SYSCON_PDRUNCFG_PD_SYS_PLL);
- /* Setup PLL configuration */
- pllConfig.desiredRate = BOARD_MAINCLOCKRATE;
- pllConfig.InputRate = 0;
- pllConfig.flags = PLL_CONFIGFLAG_FORCENOFRACT;
- pllError = Board_Clock_SetupPLLData(&pllConfig, &pllSetup);
- if (pllError == PLL_ERROR_SUCCESS) {
- pllSetup.flags = PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_ADGVOLT;
- pllError = Board_Clock_SetupSystemPLLPrec(&pllSetup);
- }
- /* Set system clock divider to 1 将系统时钟分频器设置为1 */
- Board_Clock_SetSysClockDiv(1);
- /* Set main clock source to the system PLL. This will drive 24MHz
- for the main clock and 24MHz for the system clock
- 将主时钟源设置为系统锁相环。这将为系统时钟,主时钟和24MHz 24mhz驱动*/
- Board_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_PLLOUT);
- /* ASYSNC SYSCON needs to be on or all serial peripheral won't work.
- Be careful if PLL is used or not, ASYNC_SYSCON source needs to be
- selected carefully. asysnc该需要或所有串行外设不能正常工作。如果锁相环的使用或不小心,async_syscon源需要仔细选择。*/
- Board_SYSCON_Enable_ASYNC_Syscon(true);
-
- Board_Clock_SetAsyncSysconClockDiv(1);
-
- Board_Clock_SetAsyncSysconClockSource(SYSCON_ASYNC_IRC);
- }
复制代码
关于配置时钟的顺序,这幅图示简单介绍了配置流程:
好了,到此为止,关于时钟初始化简单讲这些,这是我建的一个小历程
project.zip
(63.35 KB, 下载次数: 25)
|
|