Hallo zusammen,
ich benutze einen LPC2138 mit einem 12MHz Quarz und den GNUARM C
Compiler. Ich habe folgende Funktion geschrieben um die CCLK
einzustellen. Mit dieser Funktion soll auch die CCLK nachträglich
verändert werden können. Leider funktioniert das verändern der CCLK
nicht (die MCU hängt oder startet manchmal neu). Was mache ich falsch?
1 | // Disconnect and disable
|
2 | SCB_PLLCON = 0x00;
|
3 | HAL_CORE_PLL_Feed();
|
4 | // Wait until PLL is unlocked
|
5 | while(0 != (SCB_PLLSTAT & 0x40))
|
6 | {
|
7 | }
|
8 | // Set M and P value and enable PLL
|
9 | SCB_PLLCFG = my_Config;
|
10 | SCB_PLLCON = 0x01;
|
11 | HAL_CORE_PLL_Feed();
|
12 | // Wait until PLL is locked
|
13 | while(0 == (SCB_PLLSTAT & 0x40))
|
14 | {
|
15 | }
|
16 | // Connect and enable PLL
|
17 | SCB_PLLCON = 0x03;
|
18 | HAL_CORE_PLL_Feed();
|
1 | static VOID HAL_CORE_PLL_Feed()
|
2 | {
|
3 | __asm volatile(
|
4 | // Disable FIQ and IRQ interrupts because of the feed-sequence
|
5 | // and remember old FIQ/IRQ state in register R4
|
6 | "MRS R7, CPSR\n" // save CPSR
|
7 | "MOV R0, R7\n"
|
8 | "ORR R0, #0xC0\n" // set I-Bit and F-Bit
|
9 | "MSR CPSR_c, R0\n" // disable IRQ and FIQ
|
10 | // Feed-sequence to apply changes to PLLCON
|
11 | "MOV R3, %0\n"
|
12 | "MOV R4, #0xAA\n"
|
13 | "MOV R5, #0x55\n"
|
14 | "STRB R4, [R3]\n" // write 0xAA to PLLFEED
|
15 | "STRB R5, [R3]\n" // write 0x55 to PLLFEED
|
16 | // Set FIQ/IRQ state to saved value
|
17 | "MSR CPSR_c, R7\n" // restore CPSR
|
18 | : : "r" (&SCB_PLLFEED)
|
19 | );
|
20 | }
|