《2440 Bare Metal》Clock System

Publisher:size0109Latest update time:2022-04-23 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Principle Analysis

insert image description here

The S3C2440A has two phase-locked loops (PLLs): one (MPLL) for FCLK, HCLK and PCLK, and the other (UPLL) dedicated to USB. FCLK is used for CPU, HCLK is used for AHB bus, and PCLK is used for APB bus.


AHB (Advanced High performance Bus) is an advanced high performance bus used to connect high performance modules.

APB (Advanced Peripheral Bus) peripheral bus, used for connecting low-speed peripherals.


After simplifying the above picture, we can roughly get the following picture.

insert image description here

From this simplified diagram, we can see that the frequency of the crystal oscillator generated by MPLL is the frequency used by FCLK, and the frequency generated by UPLL is the frequency used by USB. If FCLK is further divided by HDIV and PDIV, HCLK and PCLK will be obtained respectively.


So what is the entire timing and workflow from system power-on (reset) to working at the set frequency? There is a diagram in the chip manual that explains this process.

insert image description here

After the system is powered on, the crystal oscillator (OSC) starts working. After the OSC is stable, nRESET will be pulled to a high level, and then the PLL will work according to the configuration. After the lock time, FCLK can be immediately configured as the phase-locked loop output.

With the above theoretical basis, if we want to set FCLK:HCLK:PCLK=400M:100M:50M and the crystal frequency is 12M, we can divide the configuration into the following steps:


Set LOCKTIME (0x4C000000)


Set the division value of HDIV and PDIV, FCLK:HCLK:PCLK=400M:100M:50M, so we can get HDIV=4, PDIV=8. These two values ​​can be configured through the CLKDIVN (0x4C000014) register.

insert image description here

According to the table above, HDIVN should be configured as 0b10, PDIVN should be configured as 0b1, so this register should be configured as 0x5


Set the CPU to work in asynchronous mode

insert image description here

The general meaning of this paragraph is that if HDIVN is not 0 (we set it above, it is indeed not 0), the CPU mode must be changed from fast bus mode to asynchronous bus mode. How to change it? The chip manual also provides assembly code. The question is what does #R1_nf:OR:R1_iA mean?

In fact, orr r0,r0,#R1_nf:OR:R1_iA means to set bit 30 (nf bit) and bit 31 (ia bit) to 1, so this sentence is equivalent to orr r0,r0,#0xc0000000


Set P, M, S in MPLL to make FCLK=400M

insert image description here

The manual provides a formula. Now we can substitute the values ​​given in the manual into the formula to verify it.

image.png

The values ​​of these three can be set through MPLLCON (0x4C000004).

insert image description here

2. Programming

.text

.global _start


_start:


/* Disable watchdog */

ldr r0, =0x53000000

ldr r1, =0

str r1, [r0]


/* Set MPLL, FCLK : HCLK : PCLK = 400m : 100m : 50m */

/* LOCKTIME(0x4C000000) = 0xFFFFFFFF */

ldr r0, =0x4C000000

ldr r1, =0xFFFFFFFF

str r1, [r0]


/* CLKDIVN(0x4C000014) = 0X5, tFCLK:tHCLK:tPCLK = 1:4:8 */

ldr r0, =0x4C000014

ldr r1, =0x5

str r1, [r0]


/* Set the CPU to work in asynchronous mode */

mrc p15,0,r0,c1,c0,0

orr r0,r0,#0xc0000000 //R1_nF:OR:R1_iA

mcr p15,0,r0,c1,c0,0


/* Set MPLLCON(0x4C000004) = (92<<12)|(1<<4)|(1<<0) 

* m = MDIV+8 = 92+8=100

* p = PDIV+2 = 1+2 = 3

* s = SDIV = 1

* FCLK = 2*m*Fin/(p*2^s) = 2*100*12/(3*2^1)=400M

*/

ldr r0, =0x4C000004

ldr r1, =(92<<12)|(1<<4)|(1<<0)

str r1, [r0]


/* Once the PLL is set, the lock time will be locked until the PLL output is stable

* Then the CPU operates at the new frequency FCLK

*/


/* Set up memory: sp stack */

/* Distinguish whether it is NOR/NAND startup

* Write 0 to address 0, then read it out

* If you get 0, it means the content at address 0 has been modified, it corresponds to ram, this is nand boot

* Otherwise, it is NOR start

*/

mov r1, #0

ldr r0, [r1] /* read out the original value backup */

str r1, [r1] /* 0->[0] */ 

ldr r2, [r1] /* r2=[0] */

cmp r1, r2 /* r1==r2? If they are equal, it means NAND boot*/

ldr sp, =0x40000000+4096 /* Assume that it is NOR startup*/

moveq sp, #4096 /* nand start */

streq r0, [r1] /* restore the original value */


bl main


halt:

b halt


Reference address:《2440 Bare Metal》Clock System

Previous article:Overview of the ARM microprocessor instruction set (IV) - the difference between MOV and LDR
Next article:Basic knowledge of "2440 bare metal"

Recommended posts

Please recommend embedded Linux introductory learning materials
PleaserecommendsomeintroductorylearningmaterialsforembeddedLinux,includingsystemintroduction,drivercallingandinterfacedevelopmentrelatedentry-levelmaterials Homecookingseries "DetailedExplanationofEmbeddedLinuxDevel
grarrow Linux and Android
Detection circuit and limiter circuit
Detectioncircuitandlimitercircuit Detectioncircuit---ThevalueofC3andR6shouldbeRC3t,howtounderstandthis?Timeconstant3t?IsC3=0.01uFsetarbitrarily?Whatif0.1uF,0.01uFisOK? Limitercircuit---Theconductionvoltageof
QWE4562009 Circuit Observation Room
【USB charger DIY】Device selection: fast charging module
Firstchoosethecorecomponent:thefastchargingmodule.IwasgoingtorecommendthismodelthatItestedlasttime.Ithasthreeoutputs,2Aand1C,butIdidn'texpectittobesuddenlyremovedfromtheshelvestoday. Butitdoesn't
dcexpert Power technology
Is there any requirement for the length of the data packet of the serial port? For example, ACK 00 00 means that the data has been received, instead of...
Isthereanyrequirementforthelengthofthedatapacketoftheserialport?Forexample,ACK0000meansthatthedatahasbeenreceived,ratherthanalongstringofnumbers. Whethertouseaspecificcharactertoindicatetheendofapacket
QWE4562009 Integrated technical exchanges
Award-winning live broadcast: STMicroelectronics SiC products and industrial application guide, please watch at 10:00 on September 10~
Clickheretoregister Livebroadcasttime:10:00-11:30am,September10,2020 LiveTopic:STMicroelectronicsSiCProductsandIndustrialApplicationGuide Livebroadcastintroduction: STMicroelectronicshasmorethan20yearsofe
EEWORLD社区 ST Sensors & Low Power Wireless Technology Forum
Theory and application technology of dual active full-bridge DC-DC converter
Thedual-activefull-bridgeDC-DCconverterhasthecharacteristicsofmodularsymmetricalstructure,highpowerdensity,bidirectionalpowertransmissioncapability,fastdynamicresponse,andeasysoftswitching,andissuitableformedium-to-high
arui1999 Download Centre
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号