Skip to content

Commit fd41c1a

Browse files
committed
Update based on PR Comments
1 parent 7a30176 commit fd41c1a

File tree

13 files changed

+24
-38
lines changed

13 files changed

+24
-38
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,10 @@ msgstr ""
11071107
msgid "Framebuffer requires %d bytes"
11081108
msgstr ""
11091109

1110+
#: ports/mimxrt10xx/common-hal/microcontroller/Processor.c
1111+
msgid "Frequency Out of Range Must be between 24Mhz and 1.008Ghz"
1112+
msgstr ""
1113+
11101114
#: shared-bindings/pwmio/PWMOut.c
11111115
msgid "Frequency must match existing PWMOut using this timer"
11121116
msgstr ""

ports/mimxrt10xx/boards/sparkfun_teensy_micromod/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@
1919

2020
#define CIRCUITPY_USB_DEVICE_INSTANCE 0
2121
#define CIRCUITPY_USB_HOST_INSTANCE 1
22-
23-
#define HAS_SETTABLE_CLOCK 1

ports/mimxrt10xx/boards/sparkfun_teensy_micromod/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ CHIP_FAMILY = MIMXRT1062
88
FLASH = W25Q128JV
99
CIRCUITPY__EVE = 1
1010
CIRCUITPY_USB_HOST = 1
11+
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1

ports/mimxrt10xx/boards/teensy40/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@
1616

1717
#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B0_03)
1818
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B0_02)
19-
20-
#define HAS_SETTABLE_CLOCK 1

ports/mimxrt10xx/boards/teensy40/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ CHIP_VARIANT = MIMXRT1062DVJ6A
77
CHIP_FAMILY = MIMXRT1062
88
FLASH = W25Q16JV
99
CIRCUITPY__EVE = 1
10+
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1

ports/mimxrt10xx/boards/teensy41/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@
1919

2020
#define CIRCUITPY_USB_DEVICE_INSTANCE 0
2121
#define CIRCUITPY_USB_HOST_INSTANCE 1
22-
23-
#define HAS_SETTABLE_CLOCK 1

ports/mimxrt10xx/boards/teensy41/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ CHIP_FAMILY = MIMXRT1062
88
FLASH = W25Q64JV
99
CIRCUITPY__EVE = 1
1010
CIRCUITPY_USB_HOST = 1
11+
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1

ports/mimxrt10xx/common-hal/microcontroller/Processor.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
// https://raw.githubusercontent.com/adafruit/circuitpython/main/ports/mimxrt10xx/common-hal/microcontroller/Processor.c
29-
3028
#include <math.h>
3129

30+
#include "py/runtime.h"
31+
3232
#include "common-hal/microcontroller/Processor.h"
3333
#include "shared-bindings/microcontroller/Processor.h"
3434
#include "shared-bindings/microcontroller/ResetReason.h"
@@ -52,8 +52,11 @@ float common_hal_mcu_processor_get_temperature(void) {
5252
return temp;
5353
}
5454

55-
uint32_t common_hal_mcu_processor_set_sys_clock(mcu_processor_obj_t *self,
55+
uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
5656
uint32_t frequency) {
57+
if (frequency < 24000000 || frequency > 1008000000) {
58+
mp_raise_ValueError(translate("Frequency Out of Range Must be between 24Mhz and 1.008Ghz"));
59+
}
5760
SystemCoreClock = setarmclock(frequency);
5861
return SystemCoreClock;
5962
}

ports/mimxrt10xx/common-hal/microcontroller/Processor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
typedef struct {
3737
mp_obj_base_t base;
38-
// Stores no state currently.
3938
uint32_t frequency;
4039
} mcu_processor_obj_t;
4140

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/clocks.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ uint32_t setarmclock(uint32_t frequency) {
456456
// if voltage needs to increase, do it before switch clock speed
457457
CCM->CCGR6 |= CCM_CCGR6_DCDC(CCM_CCGR_ON);
458458
if ((dcdc & ((uint32_t)(0x1F << 0))) < ((uint32_t)(((voltage - 800) / 25) & 0x1F) << 0)) {
459-
// printf("Increasing voltage to %u mV\n", voltage);
460459
dcdc &= ~((uint32_t)(0x1F << 0));
461460
dcdc |= ((uint32_t)(((voltage - 800) / 25) & 0x1F) << 0);
462461
DCDC->REG3 = dcdc;
@@ -466,16 +465,13 @@ uint32_t setarmclock(uint32_t frequency) {
466465
}
467466

468467
if (!(cbcdr & CCM_CBCDR_PERIPH_CLK_SEL_L)) {
469-
// printf("need to switch to alternate clock during reconfigure of ARM PLL\n");
470468
const uint32_t need1s = CCM_ANALOG_PLL_USB1_ENABLE_L | CCM_ANALOG_PLL_USB1_POWER_L |
471469
CCM_ANALOG_PLL_USB1_LOCK_L | CCM_ANALOG_PLL_USB1_EN_USB_CLKS_L;
472470
uint32_t sel, div;
473471
if ((CCM_ANALOG->PLL_USB1 & need1s) == need1s) {
474-
// printf("USB PLL is running, so we can use 120 MHz\n");
475472
sel = 0;
476473
div = 3; // divide down to 120 MHz, so IPG is ok even if IPG_PODF=0
477474
} else {
478-
// printf("USB PLL is off, use 24 MHz crystal\n");
479475
sel = 1;
480476
div = 0;
481477
}
@@ -500,8 +496,6 @@ uint32_t setarmclock(uint32_t frequency) {
500496
while (CCM->CDHIPR & ((uint32_t)(1 << 5))) {
501497
; // wait
502498
}
503-
} else {
504-
// printf("already running from PERIPH_CLK2, safe to mess with ARM PLL\n");
505499
}
506500

507501
// TODO: check if PLL2 running, can 352, 396 or 528 can work? (no need for ARM PLL)
@@ -528,10 +522,9 @@ uint32_t setarmclock(uint32_t frequency) {
528522
if (mult < 54) {
529523
mult = 54;
530524
}
531-
// printf("Freq: 12 MHz * %u / %u / %u\n", mult, div_arm, div_ahb);
525+
532526
frequency = mult * 12000000 / div_arm / div_ahb;
533527

534-
// printf("ARM PLL=%x\n", CCM_ANALOG->PLL_ARM);
535528
const uint32_t arm_pll_mask = CCM_ANALOG_PLL_ARM_LOCK_L | CCM_ANALOG_PLL_ARM_BYPASS_L |
536529
CCM_ANALOG_PLL_ARM_ENABLE_L | CCM_ANALOG_PLL_ARM_POWERDOWN_L |
537530
CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK;
@@ -545,9 +538,6 @@ uint32_t setarmclock(uint32_t frequency) {
545538
while (!(CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_LOCK_L)) {
546539
; // wait for lock
547540
}
548-
// printf("ARM PLL=%x\n", CCM_ANALOG->PLL_ARM);
549-
} else {
550-
// printf("ARM PLL already running at required frequency\n");
551541
}
552542

553543
if ((CCM->CACRR & ((uint32_t)(0x07 << 0))) != (div_arm - 1)) {
@@ -588,11 +578,8 @@ uint32_t setarmclock(uint32_t frequency) {
588578
F_BUS_ACTUAL = frequency / div_ipg;
589579
// scale_cpu_cycles_to_microseconds = 0xFFFFFFFFu / (uint32_t)(frequency / 1000000u);
590580

591-
// printf("New Frequency: ARM=%u, IPG=%u\n", frequency, frequency / div_ipg);
592-
593581
// if voltage needs to decrease, do it after switch clock speed
594582
if ((dcdc & ((uint32_t)(0x1F << 0))) > ((uint32_t)(((voltage - 800) / 25) & 0x1F) << 0)) {
595-
// printf("Decreasing voltage to %u mV\n", voltage);
596583
dcdc &= ~((uint32_t)(0x1F << 0));
597584
dcdc |= ((uint32_t)(0x1F << 0));
598585
DCDC->REG3 = dcdc;

0 commit comments

Comments
 (0)