RX210のクロックをPLLに切り替えるプログラムです。ルネサスエレクトロニクスのサンプルコードを単純化したものです。水晶振動子の発振周波数が20MHzの時にCPUの動作クロックが50MHzとなり周辺機器のクロックが25MHzとなります。
- /* RX210 cpuのクロックをPLLに切り替えるプログラム */
- /* 水晶振動子の発振周波数が20MHzの時にCPUの動作クロックが50MHzとなり周辺機器のクロックが25MHzとなる。 */
-
- #include "iodefine.h"
- #include <machine.h>
- void change_oscillation_PLL(void)
- {
- unsigned int i;
- /* ---- Enable write protection ---- */
- /* PRCR - Protect Register
- b15:b8 PRKEY - PRC Key Code - A5h
- (The write value should be A5h to permission writing PRCi bit)
- b7:b4 Reserved - The write value should be 0.
- b3 PRC3 - Protect Bit 3 - Write disabled
- b2 PRC2 - Protect Bit 2 - Write enabled
- b1 PRC1 - Protect Bit 1 - Write enabled
- b0 PRC0 - Protect Bit 0 - Write enabled */
- SYSTEM.PRCR.WORD = 0xA507;
- /* ---- Set the VRCR register ---- */
- SYSTEM.VRCR = 0x00;
- /* ---- Set the main clock oscillator drive capability ---- */
- /* MOFCR - Main Clock Oscillator Forced Oscillation Control Register
- b7 Reserved - The write value should be 0.
- b6 MOSEL - Main Clock Oscillator Switch - Resonator
- b5:b4 MODRV2 - Main Clock Oscillator Drive Capability Switch 2
- - 16 MHz to 20 MHz
- b3:b1 MODRV - Main Clock Oscillator Drive Capability Switch
- - 16 MHz to 20 MHz non-lead type ceramic resonator
- b0 Reserved - The write value should be 0. */
- SYSTEM.MOFCR.BYTE = (0x30); /* Drive capability : 20 MHz crystal resonator */
- /* ---- Set wait time until the main clock oscillator stabilizes ---- */
- /* MOSCWTCR - Main Clock Oscillator Wait Control Register
- b7:b5 Reserved - The write value should be 0.
- b4:b0 MSTS - Main Clock Oscillator Waiting Time
- - Wait time is 131072 cycles (approx. 6.55 ms). */
- SYSTEM.MOSCWTCR.BYTE = (0x0D); /* Wait control register : 131072 cycles (approx. 6.55 ms) */
- /* ---- Operate the main clock oscillator ---- */
- /* MOSCCR - Main Clock Oscillator Control Register
- b7:b1 Reserved - The write value should be 0.
- b0 MOSTP - Main Clock Oscillator Stop - Main clock oscillator is operating. */
- SYSTEM.MOSCCR.BYTE = 0x00;
- while (0x00 != SYSTEM.MOSCCR.BYTE)
- {
- /* Confirm that the written value can be read correctly. */
- }
- /* ---- Wait processing for the clock oscillation stabilization ---- */
- for(i=0;i<100;i++) nop();</li>
- /* ---- Set the PLL division ratio and multiplication factor ---- */
- /* PLLCR - PLL Control Register
- b15:b13 Reserved - The write value should be 0.
- b12:b8 STC - Frequency Multiplication Factor Select
- - Frequency multiplication factor is multiply-by-10.
- b7:b2 Reserved - The write value should be 0.
- b1:b0 PLIDIV - PLL Input Frequency Division Ratio Select
- - PLL input division ratio is divide-by-2. */
- SYSTEM.PLLCR.WORD = (0x0901); /* Division ratio and multiplication factor : divide-by-2, multiply-by-10 */
- /* ---- Set wait time until the PLL clock oscillator stabilizes ---- */
- /* PLLWTCR - PLL Wait Control Register
- b7:b5 Reserved - The write value should be 0.
- b4:b0 PSTS - PLL Waiting Time
- - Wait time is 65536 cycles (approx. 655.36 us). */
- SYSTEM.PLLWTCR.BYTE = (0x09); /* Wait control register : 65536 cycles (approx. 655.36 us) */
- /* ---- Operate the PLL clock oscillator ---- */
- /* PLLCR2 - PLL Control Register 2
- b7:b1 Reserved - The write value should be 0.
- b0 PLLEN - PLL Stop Control - PLL is operating. */
- SYSTEM.PLLCR2.BYTE = 0x00;
- /* ---- Wait processing for the clock oscillation stabilization ---- */
- for(i=0;i<100;i++) nop();</li>
- /* ---- Set the operating power control mode ---- */
- /* OPCCR - Operating Power Control Register
- b7:b5 Reserved - The write value should be 0.
- b4 OPCMTSF - Operating Power Control Mode Transition Status Flag
- b3 Reserved - The write value should be 0.
- b2:b0 OPCM - Operating Power Control Mode Select - High-speed operating mode */
- SYSTEM.OPCCR.BYTE = (0x00); /* High-speed operating mode */
- while (0 != SYSTEM.OPCCR.BIT.OPCMTSF)
- {
- /* Confirm that the operation power control mode transition completed. */
- }
- /* ---- Set the internal clock division ratio ---- */
- /* SCKCR - System Clock Control Register
- b31:b28 FCK - FlashIF Clock(FCLK) Select - divide-by-4
- b27:b24 ICK - System Clock (ICLK) Select - divide-by-2
- b23 PSTOP1 - BCLK Pin Output Control - disabled. (Fixed high)
- b22:b20 Reserved - The write value should be 0.
- b19:b16 BCK - External Bus Clock (BCLK) Select - divide-by-4
- b15:b12 Reserved - The write value should be 0001b.
- b10:b8 PCLKB - Peripheral Module Clock B(PCLKB) Select - divide-by-4
- b7:b4 Reserved - The write value should be 0001b.
- b3:b0 PCLKD - Peripheral Module Clock D(PCLKD) Select - divide-by-2 */
- SYSTEM.SCKCR.LONG = 0x21821211; /* ICLK,PCLKD: divide-by-2 PCLKB,BCLK,FCLK: divide-by-4 */
- while (0x21821211 != SYSTEM.SCKCR.LONG)
- {
- /* Confirm that the written value can be read correctly. */
- }
- /* ---- Set the BCLK pin output ---- */
- /* BCKCR - External Bus Clock Control Register
- b7:b1 Reserved - The write value should be 0.
- b0 BCLKDIV - BCLK Pin Output Select - divide-by-2 */
- SYSTEM.BCKCR.BYTE = 0x01;
- while (0x01 != SYSTEM.BCKCR.BYTE)
- {
- /* Confirm that the written value can be read correctly. */
- }
- /* ---- Set the internal clock source ---- */
- /* SCKCR3 - System Clock Control Register 3
- b15:b11 Reserved - The write value should be 0.
- b10:b8 CKSEL - Clock Source Select - PLL circuit is selected.
- b7:b1 Reserved - The write value should be 0. */
- SYSTEM.SCKCR3.WORD = (0x0400); /* PLL */
- while ((0x0400) != SYSTEM.SCKCR3.WORD)
- {
- /* Confirm that the written value can be read correctly. */
- }
- /* ---- Disable write protection ---- */
- /* PRCR - Protect Register
- b15:b8 PRKEY - PRC Key Code - A5h
- (The write value should be A5h to permission writing PRCi bit)
- b2 PRC2 - Protect Bit 2 - Write disabled
- b1 PRC1 - Protect Bit 1 - Write disabled
- b0 PRC0 - Protect Bit 0 - Write disabled */
- SYSTEM.PRCR.WORD = 0xA500;
- }
- void main(void)
- {
- unsigned int i;
- change_oscillation_PLL(); //クロックソースPLL
- PORTC.PDR.BYTE = 0xFF;
- PORTC.PODR.BYTE = 0x00;
- PORTA.PDR.BYTE = 0xFF;
- PORTA.PODR.BYTE =0x00;
- PORTB.PDR.BYTE = 0xFF;
- PORTB.PODR.BYTE = 0xFF;
- while(1) {
- PORTC.PODR.BYTE = ~PORTC.PODR.BYTE;
- PORTA.PODR.BYTE = ~PORTA.PODR.BYTE;
- PORTB.PODR.BYTE = ~PORTB.PODR.BYTE;
- for(i=0;i<500000;i++) nop();</li>
- }
- }
※コメント投稿者のブログIDはブログ作成者のみに通知されます