秋月電子通商で販売しているAE-RX210ボードでリアルタイムOSのFreeRTOSを動かしてみました。 環境はe2 studio上でRXCです。
FreeRTOSのサイトからソースコードをダウンロードして展開します。ソースコードには各種CPUアーキテクチャ用のファイルが混在しているので必要なものを
e2 studioに登録していきます。どのフォルダからコピーしたのかを示します。
[src] +---- iodefine.h --- ウイザードで自動作成 +---- stacksct.h --- ウイザードで自動作成 +---- typedefine.h --- ウイザードで自動作成 +---- vect.h --- ウイザードで自動作成したものを書き換え +---- dbsct.c --- ウイザードで自動作成 +---- interrupt_handlers.c --- ウイザードで自動作成 +---- main.c --- ウイザードで自動作成 +---- reset_program.c --- ウイザードで自動作成 +---- vector_table.c --- ウイザードで自動作成 | +-----[FreeRTOS] +------ croutine.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ deprecated_definitions.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ event_groups.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ FreeRTOS.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ list.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ mpu_wrappers.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ portable.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ projdefs.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ queue.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ semphr.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ StackMacros.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ task.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ timers.h --- FreeRTOSv8.2.2\FreeRTOS\Source\include からコピー +------ croutine.c --- FreeRTOSv8.2.2\FreeRTOS\Source からコピー +------ event_groups.c --- FreeRTOSv8.2.2\FreeRTOS\Source からコピー +------ list.c --- FreeRTOSv8.2.2\FreeRTOS\Source からコピー +------ queue.c --- FreeRTOSv8.2.2\FreeRTOS\Source からコピー +------ tasks.c --- FreeRTOSv8.2.2\FreeRTOS\Source からコピー +------ timers.c --- FreeRTOSv8.2.2\FreeRTOS\Source からコピー | +------ [portable] +------ FreeRTOSConfig.h --- FreeRTOSv8.2.2\FreeRTOS\Demo\RX200_RX210-RSK_Renesas\RTOSDemo からコピーし書き換え +------ heap_2.c --- FreeRTOSv8.2.2\FreeRTOS\Source\portable\MemMang からコピー +------ hwsetup.c --- FreeRTOSv8.2.2\FreeRTOS\Demo\RX200_RX210-RSK_Renesas\RTOSDemo\Renesas-Files からコピーし書き換え +------ port.c --- FreeRTOSv8.2.2\FreeRTOS\Source\portable\Renesas\RX200 からコピー +------ portmacro.h --- FreeRTOSv8.2.2\FreeRTOS\Source\portable\Renesas\RX200 からコピー +------ port_asm.src --- FreeRTOSv8.2.2\FreeRTOS\Source\portable\Renesas\RX200 からコピー
登録後はこのようになります。
![](https://blogimg.goo.ne.jp/user_image/38/a6/5a7efc5a200b8bd7901d2e05733791ce.png)
ファイルのフォルダ構成を変更したのでソースコード内の
#includde "filename.h"
行のファイルの位置を相対パスで指定しなおします。
次にコードを一部書き直します。
main.c
/* Hardware specific includes. */ #include "iodefine.h" /* Kernel includes. */ #include "FreeRTOS/FreeRTOS.h" #include "FreeRTOS/task.h" #include "FreeRTOS/queue.h" /* This variable is not used by this simple Blinky example. It is defined purely to allow the project to link as it is used by the full build configuration. */ volatile unsigned long ulHighFrequencyTickCount = 0UL; /*-----------------------------------------------------------*/ void vTask1(void *pvParameters) { while(1) { PORTC.PODR.BIT.B1 = ~PORTC.PODR.BIT.B1; vTaskDelay(100/portTICK_PERIOD_MS); } } void vTask2(void *pvParameters) { while(1) { PORTC.PODR.BIT.B2 = ~PORTC.PODR.BIT.B2; vTaskDelay(200/portTICK_PERIOD_MS); } } void vTask3(void *pvParameters) { while(1) { PORTC.PODR.BIT.B3 = ~PORTC.PODR.BIT.B3; vTaskDelay(300/portTICK_PERIOD_MS); } } void main(void) { extern void HardwareSetup( void ); /* Renesas provided CPU configuration routine. The clocks are configured in here. */ HardwareSetup(); /* Turn all LEDs off. */ PORTC.PDR.BYTE = 0xFF; //ポートC出力 PORTC.PODR.BYTE = 0xFF; //初期値 xTaskCreate(vTask1,"Task1",100,NULL,1,NULL); xTaskCreate(vTask2,"Task2",100,NULL,1,NULL); xTaskCreate(vTask3,"Task3",100,NULL,1,NULL); /* Create the queue. */ vTaskStartScheduler(); /* If all is well the next line of code will not be reached as the scheduler will be running. If the next line is reached then it is likely that there was insufficient heap available for the idle task to be created. */ for( ;; ); } /*-----------------------------------------------------------*/ /* A callback function named vApplicationSetupTimerInterrupt() must be defined to configure a tick interrupt source, and configTICK_VECTOR set in FreeRTOSConfig.h to install the tick interrupt handler in the correct position in the vector table. This example uses a compare match timer. It can be into any FreeRTOS project, provided the same compare match timer is available. */ void vApplicationSetupTimerInterrupt( void ) { /* Enable compare match timer 0. */ SYSTEM.PRCR.WORD = 0x0A502; MSTP( CMT0 ) = 0; SYSTEM.PRCR.WORD = 0x0A500; /* Interrupt on compare match. */ CMT0.CMCR.BIT.CMIE = 1; CMT0.CMCR.BIT.CKS = 0; // CLK = PCLK/8 /* Set the compare match value. */ CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 ); /* Divide the PCLK by 8. */ CMT0.CMCR.BIT.CKS = 0; /* Enable the interrupt... */ _IEN( _CMT0_CMI0 ) = 1; ICU.IER[IER_CMT0_CMI0].BIT.IEN_CMT0_CMI0 = 1; //Enable CMIE /* ...and set its priority to the application defined kernel priority. */ _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY; ICU.IPR[IPR_CMT0_CMI0].BYTE = configKERNEL_INTERRUPT_PRIORITY; // Set interrupt priority level /* Start the timer. */ CMT.CMSTR0.BIT.STR0 = 1; } /*-----------------------------------------------------------*/ /* If configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h, then this function will be called if pvPortMalloc() returns NULL because it has exhausted the available FreeRTOS heap space. See http://www.freertos.org/a00111.html. */ void vApplicationMallocFailedHook( void ) { for( ;; ); } /*-----------------------------------------------------------*/ /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 in FreeRTOSConfig.h, then this function will be called if a task overflows its stack space. See http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) { for( ;; ); } /*-----------------------------------------------------------*/ /* If configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h, then this function will be called on each iteration of the idle task. See http://www.freertos.org/a00016.html */ void vApplicationIdleHook( void ) { /* If this is being executed then the kernel has been started. Start the high frequency timer test as described at the top of this file. This is only included in the optimised build configuration - otherwise it takes up too much CPU time and can disrupt other tests. */ #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST static portBASE_TYPE xTimerTestStarted = pdFALSE; extern void vSetupHighFrequencyTimer( void ); if( xTimerTestStarted == pdFALSE ) { vSetupHighFrequencyTimer(); xTimerTestStarted = pdTRUE; } #endif } /*-----------------------------------------------------------*/
vect.h
vect.h の70行目から76行目をコメントアウト // FCU FIFERR #pragma interrupt (Excep_FCU_FIFERR(vect=21)) void Excep_FCU_FIFERR( void); // FCU FRDYI #pragma interrupt (Excep_FCU_FRDYI(vect=23)) void Excep_FCU_FRDYI( void); // ICU SWINT //#pragma interrupt (Excep_ICU_SWINT(vect =27)) --- コメントアウト //void Excep_ICU_SWINT(void); --- コメントアウト // CMT0 CMI0 //#pragma interrupt (Excep_CMT0_CMI0(vect =28)) --- コメントアウト //void Excep_CMT0_CMI0(void); --- コメントアウト // CMT1 CMI1 #pragma interrupt (Excep_CMT1_CMI1(vect=29)) void Excep_CMT1_CMI1( void);
FreeRTOSConfig.h
/* FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd. All rights reserved VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. *************************************************************************** >>! NOTE: The modification to the GPL is included to allow you to !<< >>! distribute a combined work that includes FreeRTOS without being !<< >>! obliged to provide the source code for proprietary components !<< >>! outside of the FreeRTOS kernel. !<< *************************************************************************** FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Full license text is available on the following link: http://www.freertos.org/a00114.html *************************************************************************** * * * FreeRTOS provides completely free yet professionally developed, * * robust, strictly quality controlled, supported, and cross * * platform software that is more than just the market leader, it * * is the industry's de facto standard. * * * * Help yourself get started quickly while simultaneously helping * * to support the FreeRTOS project by purchasing a FreeRTOS * * tutorial book, reference manual, or both: * * http://www.FreeRTOS.org/Documentation * * * *************************************************************************** http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading the FAQ page "My application does not run, what could be wrong?". Have you defined configASSERT()? http://www.FreeRTOS.org/support - In return for receiving this top quality embedded software for free we request you assist our global community by participating in the support forum. http://www.FreeRTOS.org/training - Investing in training allows your team to be as productive as possible as early as possible. Now you can receive FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers Ltd, and the world's leading authority on the world's leading RTOS. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, including FreeRTOS+Trace - an indispensable productivity tool, a DOS compatible FAT file system, and our tiny thread aware UDP/IP stack. http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS licenses offer ticketed support, indemnification and commercial middleware. http://www.SafeRTOS.com - High Integrity Systems also provide a safety engineered and independently SIL3 certified version for use in safety and mission critical applications that require provable dependability. 1 tab == 4 spaces! */ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H /* Board specifics. */ //#include "rskrx210def.h" /* System Clock Settings */ /* ボードのクロック設定 * CLK_SRC_HOCO=0 で 20MHz xtal * CLK_SRC_HOCO=1 で 50MHz 内臓発振器 */ #define CLK_SRC_HOCO 0 /* DETAIL THIS LATER !!!! */ #if (CLK_SRC_HOCO == 0) /* External xtal and PLL circuit */ #define XTAL_FREQUENCY (20000000L) #define PLL_MUL (10) #define PLL_INPUT_FREQ_DIV (2) #define ICLK_DIV (2) #define PCLK_DIV (4) #define BCLK_DIV (4) #define PLL_FREQUENCY (XTAL_FREQUENCY * (PLL_MUL / PLL_INPUT_FREQ_DIV)) #define ICLK_FREQUENCY (PLL_FREQUENCY / ICLK_DIV) #define PCLK_FREQUENCY (PLL_FREQUENCY / PCLK_DIV) #define BCLK_FREQUENCY (PLL_FREQUENCY / BCLK_DIV) #else /* Internal high speed on-chip oscillator (HOCO) */ #define XTAL_FREQUENCY (50000000L) #define PLL_MUL (1) #define PLL_INPUT_FREQ_DIV (1) #define ICLK_DIV (1) #define PCLK_DIV (2) #define BCLK_DIV (2) #define PLL_FREQUENCY (XTAL_FREQUENCY * (PLL_MUL / PLL_INPUT_FREQ_DIV)) #define ICLK_FREQUENCY (PLL_FREQUENCY / ICLK_DIV) #define PCLK_FREQUENCY (PLL_FREQUENCY / PCLK_DIV) #define BCLK_FREQUENCY (PLL_FREQUENCY / BCLK_DIV) #endif /*----------------------------------------------------------- * Application specific definitions. * * These definitions should be adjusted for your particular hardware and * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( ICLK_FREQUENCY ) /* Set in rskrx210def.h. */ #define configPERIPHERAL_CLOCK_HZ ( PCLK_FREQUENCY ) /* Set in rskrx210def.h. */ #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 140 ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 50 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 12 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_CO_ROUTINES 0 #define configUSE_MUTEXES 1 #define configGENERATE_RUN_TIME_STATS 1 #define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 0 #define configUSE_MALLOC_FAILED_HOOK 1 #define configUSE_APPLICATION_TASK_TAG 0 #define configMAX_PRIORITIES ( 7 ) #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Software timer definitions. */ #define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY ( 3 ) #define configTIMER_QUEUE_LENGTH 5 #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE ) /* The interrupt priority used by the kernel itself for the tick interrupt and the pended interrupt. This would normally be the lowest priority. */ #define configKERNEL_INTERRUPT_PRIORITY 1 /* The maximum interrupt priority from which FreeRTOS API calls can be made. Interrupts that use a priority above this will not be effected by anything the kernel is doing. */ #define configMAX_SYSCALL_INTERRUPT_PRIORITY 4 /* The peripheral used to generate the tick interrupt is configured as part of the application code. This constant should be set to the vector number of the peripheral chosen. As supplied this is CMT0. */ #define configTICK_VECTOR _CMT0_CMI0 /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskCleanUpResources 0 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_uxTaskGetStackHighWaterMark 1 #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_eTaskGetState 1 #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } extern volatile unsigned long ulHighFrequencyTickCount; #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() nop() /* Run time stats use the same timer as the high frequency timer test. */ #define portGET_RUN_TIME_COUNTER_VALUE() ulHighFrequencyTickCount /* Override some of the priorities set in the common demo tasks. This is required to ensure flase positive timing errors are not reported. */ #define bktPRIMARY_PRIORITY ( configMAX_PRIORITIES - 3 ) #define bktSECONDARY_PRIORITY ( configMAX_PRIORITIES - 4 ) #define intqHIGHER_PRIORITY ( configMAX_PRIORITIES - 3 ) #endif /* FREERTOS_CONFIG_H */
hwsetup.c
/****************************************************************************** * DISCLAIMER * This software is supplied by Renesas Technology Corp. and is only * intended for use with Renesas products. No other uses are authorized. * This software is owned by Renesas Technology Corp. and is protected under * all applicable laws, including copyright laws. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES * REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, * INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY * DISCLAIMED. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS * TECHNOLOGY CORP. NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES * FOR ANY REASON RELATED TO THE THIS SOFTWARE, EVEN IF RENESAS OR ITS * AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * Renesas reserves the right, without notice, to make changes to this * software and to discontinue the availability of this software. * By using this software, you agree to the additional terms and * conditions found by accessing the following link: * http://www.renesas.com/disclaimer ****************************************************************************** * Copyright (C) 2008. Renesas Technology Corp., All Rights Reserved. ******************************************************************************* * File Name : hwsetup.c * Version : 1.00 * Description : Power up hardware initializations ****************************************************************************** * History : DD.MM.YYYY Version Description * : 15.02.2010 1.00 First Release ******************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include <stdint.h> #include "../../iodefine.h" #include "../FreeRTOS.h" /****************************************************************************** Typedef definitions ******************************************************************************/ /****************************************************************************** Macro definitions ******************************************************************************/ /****************************************************************************** Imported global variables and functions (from other files) ******************************************************************************/ /****************************************************************************** Exported global variables and functions (to be accessed by other files) ******************************************************************************/ /****************************************************************************** Private global variables and functions ******************************************************************************/ void io_set_cpg(void); void EnablePeripheralModules(void); /****************************************************************************** * Function Name: HardwareSetup * Description : This function does initial setting for CPG port pins used in * : the Demo including the MII pins of the Ethernet PHY connection. * Arguments : none * Return Value : none ******************************************************************************/ void HardwareSetup(void) { /* CPG setting */ io_set_cpg(); /* Enables peripherals */ EnablePeripheralModules(); } /****************************************************************************** * Function Name: EnablePeripheralModules * Description : Enables Peripheral Modules before use * Arguments : none * Return Value : none ******************************************************************************/ void EnablePeripheralModules(void) { /* Module standby clear */ SYSTEM.PRCR.WORD = 0x0A502; MSTP( CMT0 ) = 0; SYSTEM.PRCR.WORD = 0x0A500; } /****************************************************************************** * Function Name: io_set_cpg * Description : Sets up operating speed * Arguments : none * Return Value : none ******************************************************************************/ void io_set_cpg(void) { /* Set CPU PLL operating frequencies. Changes to the peripheral clock will require changes to the debugger and flash kernel BRR settings. */ /* ==== CPG setting ==== */ volatile unsigned int i; SYSTEM.PRCR.WORD = 0xA507; /* Protect off */ #if (CLK_SRC_HOCO == 1) /* ---- Set the VRCR register ---- */ SYSTEM.VRCR = 0x00; SYSTEM.HOCOPCR.BYTE = 0x00; /* HOCO power supply on */ SYSTEM.HOCOCR2.BYTE = 0x03; /* Select - 50MHz */ SYSTEM.HOCOWTCR2.BYTE = 0x03; /* Set wait time until the HOCO oscillator stabilizes */ SYSTEM.HOCOCR.BYTE = 0x01; /* HOCO is operating */ 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. */ } SYSTEM.BCKCR.BYTE = 0x01; /* ---- Set the BCLK pin output ---- */ while (0x01 != SYSTEM.BCKCR.BYTE) { /* Confirm that the written value can be read correctly. */ } for(i=0; i<10; i++){ /* wait over 60us */ } // SYSTEM.SCKCR.LONG = 0x21823333; /* ICK=PLL/2,FCK,PCK,BCL=PLL/4 */ /************************************************************************/ /* If setting bits individually, rather than a single long write, */ /* set the BCK value before that of ICK */ /************************************************************************/ // SYSTEM.SCKCR.BIT.PCKD = 3; /* PLL/8 = 10MHz */ // //SYSTEM.SCKCR.BIT.PCKC = 3; /* PLL/8 = 10MHz */ // SYSTEM.SCKCR.BIT.PCKB = 3; /* PLL/8 = 10MHz */ // //SYSTEM.SCKCR.BIT.PCKA = 3; /* PLL/8 = 10MHz */ // SYSTEM.SCKCR.BIT.BCK = 3; /* PLL/8 = 10MHz */ // SYSTEM.SCKCR.BIT.PSTOP1 = 1; /* BUS CLK OUT Disabled */ // SYSTEM.SCKCR.BIT.ICK = 1; /* PLL/2 = 40MHz */ // SYSTEM.SCKCR.BIT.FCK = 2; /* PLL/4 = 20MHz */ #else /* ---- Set the VRCR register ---- */ SYSTEM.VRCR = 0x00; SYSTEM.MOFCR.BYTE = (0x30); /* Drive capability : 20 MHz crystal resonator */ SYSTEM.MOSCWTCR.BYTE = 0x0D; /* Main Clock Oscillator Wait Control Register */ /* 131072 cycles (approx. 6.55 ms). */ /* wait over 2 ms @20MHz */ SYSTEM.PLLWTCR.BYTE = 0x0B; /* PLL Wait Control Register */ /* 262144 states */ /* wait over 2.1 ms @PLL = 80Hz */ /* (20/2x8*8) */ SYSTEM.MOSCCR.BYTE = 0x00; /* EXTAL OFF */ 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++) { } SYSTEM.PLLCR.WORD = (0x0901); /* Division ratio and multiplication factor : divide-by-2, multiply-by-10 */ /* Input to PLL (EXTAL in) / 2 */ /* Therefore: PLL = EXTAL / 2 = 20M / 2 = 10MHz PLL * 8 = 80Mhz PLL *10 = 100MHz */ SYSTEM.PLLWTCR.BYTE = (0x09); /* Wait control register : 65536 cycles (approx. 655.36 us) */ SYSTEM.PLLCR2.BYTE = 0x00; /* ---- Wait processing for the clock oscillation stabilization ---- */ for(i=0;i<100;i++) { } 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. */ } SYSTEM.BCKCR.BYTE = 0x01; /* ---- Set the BCLK pin output ---- */ while (0x01 != SYSTEM.BCKCR.BYTE) { /* Confirm that the written value can be read correctly. */ } #endif while(SYSTEM.OPCCR.BIT.OPCMTSF == 1); SYSTEM.OPCCR.BIT.OPCMTSF = 0; /* High-speed operating mode */ while(SYSTEM.OPCCR.BIT.OPCMTSF == 1); #if (CLK_SRC_HOCO == 1) SYSTEM.SCKCR3.WORD = 0x0100; /* LOCO -> HOCO */ #else SYSTEM.SCKCR3.WORD = 0x0400; /* LOCO -> PLL */ #endif SYSTEM.PRCR.WORD = 0xA500; /* Protect on */ }
※コメント投稿者のブログIDはブログ作成者のみに通知されます