RX210のクロックを内蔵高速クロックに切り替えるプログラムです。ルネサスエレクトロニクスのサンプルコードを単純化したものです。
change_oscillation_HOCO()関数の引数でクロック周波数を変更できます。
- /* RX210 cpuのクロックを内蔵高速クロックに切り替えるプログラム */
-
-
- #include "iodefine.h"
- #include <machine.h>
- #define FREQ_32MHz (0x00) /* 32 MHz */
- #define FREQ_36MHz (0x01) /* 36.864 MHz */
- #define FREQ_40MHz (0x02) /* 40 MHz */
- #define FREQ_50MHz (0x03) /* 50 MHz */
- void change_oscillation_HOCO(unsigned char cpufreq) // <--引数にOSCの周波数を設定
- {
- unsigned char reg_hocwtcr2;
- unsigned int i;
- cpufreq &= 0x03;
- if(cpufreq == FREQ_50MHz) {
- reg_hocwtcr2 = 0x03; /* 50 MHz : 9216 cycles */
- } else {
- reg_hocwtcr2 = 0x02; /* 32 MHz, 36.864 MHz, 40 MHz : 7168 cycles */
- }
- /* ---- 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 HOCO frequency ---- */
- /* HOCOCR2 - High-Speed On-Chip Oscillator Control Register 2
- b7:b2 Reserved - The write value should be 0.
- b1:b0 HCFRQ - HOCO Frequency Setting - 50 MHz */
- SYSTEM.HOCOCR2.BYTE = cpufreq;
- /* ---- Set wait time until the HOCO oscillator stabilizes ---- */
- /* HOCOWTCR2 - HOCO Wait Control Register 2
- b7:b4 Reserved - The write value should be 0.
- b3:b0 HSTS2 - HOCO Wait Time Select 2
- - Wait time is 9216 cycles (approx. 184.32 us). */
- SYSTEM.HOCOWTCR2.BYTE = reg_hocwtcr2;
- //SYSTEM.SCKCR.BIT.BCK = 1; //BCK 2分周
- /* ---- Operate the HOCO clock ---- */
- /* HOCOCR - High-Speed On-Chip Oscillator Control Register
- b7:b1 Reserved - The write value should be 0.
- b0 HCSTP - the HOCO is operating. */
- SYSTEM.HOCOCR.BYTE = 0x00;
- /* ---- Wait processing for the clock oscillation stabilization ---- */
- for(i=0;i<100;i++) nop();
- /* ---- 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 = 0x10811110; /* ICLK,PCLKD: no division PCLKB,BCLK,FCLK: divide-by-2 */
- while (0x10811110 != 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 = 0x0100;
- while (0x0100 != 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_HOCO(FREQ_50MHz); //クロック変更
- 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();
- }
- }
※コメント投稿者のブログIDはブログ作成者のみに通知されます