Update based on PR Comments
This commit is contained in:
parent
7a30176b49
commit
fd41c1ac5b
|
@ -1107,6 +1107,10 @@ msgstr ""
|
|||
msgid "Framebuffer requires %d bytes"
|
||||
msgstr ""
|
||||
|
||||
#: ports/mimxrt10xx/common-hal/microcontroller/Processor.c
|
||||
msgid "Frequency Out of Range Must be between 24Mhz and 1.008Ghz"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/pwmio/PWMOut.c
|
||||
msgid "Frequency must match existing PWMOut using this timer"
|
||||
msgstr ""
|
||||
|
|
|
@ -19,5 +19,3 @@
|
|||
|
||||
#define CIRCUITPY_USB_DEVICE_INSTANCE 0
|
||||
#define CIRCUITPY_USB_HOST_INSTANCE 1
|
||||
|
||||
#define HAS_SETTABLE_CLOCK 1
|
||||
|
|
|
@ -8,3 +8,4 @@ CHIP_FAMILY = MIMXRT1062
|
|||
FLASH = W25Q128JV
|
||||
CIRCUITPY__EVE = 1
|
||||
CIRCUITPY_USB_HOST = 1
|
||||
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1
|
||||
|
|
|
@ -16,5 +16,3 @@
|
|||
|
||||
#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B0_03)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B0_02)
|
||||
|
||||
#define HAS_SETTABLE_CLOCK 1
|
||||
|
|
|
@ -7,3 +7,4 @@ CHIP_VARIANT = MIMXRT1062DVJ6A
|
|||
CHIP_FAMILY = MIMXRT1062
|
||||
FLASH = W25Q16JV
|
||||
CIRCUITPY__EVE = 1
|
||||
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1
|
||||
|
|
|
@ -19,5 +19,3 @@
|
|||
|
||||
#define CIRCUITPY_USB_DEVICE_INSTANCE 0
|
||||
#define CIRCUITPY_USB_HOST_INSTANCE 1
|
||||
|
||||
#define HAS_SETTABLE_CLOCK 1
|
||||
|
|
|
@ -8,3 +8,4 @@ CHIP_FAMILY = MIMXRT1062
|
|||
FLASH = W25Q64JV
|
||||
CIRCUITPY__EVE = 1
|
||||
CIRCUITPY_USB_HOST = 1
|
||||
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// https://raw.githubusercontent.com/adafruit/circuitpython/main/ports/mimxrt10xx/common-hal/microcontroller/Processor.c
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "common-hal/microcontroller/Processor.h"
|
||||
#include "shared-bindings/microcontroller/Processor.h"
|
||||
#include "shared-bindings/microcontroller/ResetReason.h"
|
||||
|
@ -52,8 +52,11 @@ float common_hal_mcu_processor_get_temperature(void) {
|
|||
return temp;
|
||||
}
|
||||
|
||||
uint32_t common_hal_mcu_processor_set_sys_clock(mcu_processor_obj_t *self,
|
||||
uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self,
|
||||
uint32_t frequency) {
|
||||
if (frequency < 24000000 || frequency > 1008000000) {
|
||||
mp_raise_ValueError(translate("Frequency Out of Range Must be between 24Mhz and 1.008Ghz"));
|
||||
}
|
||||
SystemCoreClock = setarmclock(frequency);
|
||||
return SystemCoreClock;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
// Stores no state currently.
|
||||
uint32_t frequency;
|
||||
} mcu_processor_obj_t;
|
||||
|
||||
|
|
|
@ -456,7 +456,6 @@ uint32_t setarmclock(uint32_t frequency) {
|
|||
// if voltage needs to increase, do it before switch clock speed
|
||||
CCM->CCGR6 |= CCM_CCGR6_DCDC(CCM_CCGR_ON);
|
||||
if ((dcdc & ((uint32_t)(0x1F << 0))) < ((uint32_t)(((voltage - 800) / 25) & 0x1F) << 0)) {
|
||||
// printf("Increasing voltage to %u mV\n", voltage);
|
||||
dcdc &= ~((uint32_t)(0x1F << 0));
|
||||
dcdc |= ((uint32_t)(((voltage - 800) / 25) & 0x1F) << 0);
|
||||
DCDC->REG3 = dcdc;
|
||||
|
@ -466,16 +465,13 @@ uint32_t setarmclock(uint32_t frequency) {
|
|||
}
|
||||
|
||||
if (!(cbcdr & CCM_CBCDR_PERIPH_CLK_SEL_L)) {
|
||||
// printf("need to switch to alternate clock during reconfigure of ARM PLL\n");
|
||||
const uint32_t need1s = CCM_ANALOG_PLL_USB1_ENABLE_L | CCM_ANALOG_PLL_USB1_POWER_L |
|
||||
CCM_ANALOG_PLL_USB1_LOCK_L | CCM_ANALOG_PLL_USB1_EN_USB_CLKS_L;
|
||||
uint32_t sel, div;
|
||||
if ((CCM_ANALOG->PLL_USB1 & need1s) == need1s) {
|
||||
// printf("USB PLL is running, so we can use 120 MHz\n");
|
||||
sel = 0;
|
||||
div = 3; // divide down to 120 MHz, so IPG is ok even if IPG_PODF=0
|
||||
} else {
|
||||
// printf("USB PLL is off, use 24 MHz crystal\n");
|
||||
sel = 1;
|
||||
div = 0;
|
||||
}
|
||||
|
@ -500,8 +496,6 @@ uint32_t setarmclock(uint32_t frequency) {
|
|||
while (CCM->CDHIPR & ((uint32_t)(1 << 5))) {
|
||||
; // wait
|
||||
}
|
||||
} else {
|
||||
// printf("already running from PERIPH_CLK2, safe to mess with ARM PLL\n");
|
||||
}
|
||||
|
||||
// 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) {
|
|||
if (mult < 54) {
|
||||
mult = 54;
|
||||
}
|
||||
// printf("Freq: 12 MHz * %u / %u / %u\n", mult, div_arm, div_ahb);
|
||||
|
||||
frequency = mult * 12000000 / div_arm / div_ahb;
|
||||
|
||||
// printf("ARM PLL=%x\n", CCM_ANALOG->PLL_ARM);
|
||||
const uint32_t arm_pll_mask = CCM_ANALOG_PLL_ARM_LOCK_L | CCM_ANALOG_PLL_ARM_BYPASS_L |
|
||||
CCM_ANALOG_PLL_ARM_ENABLE_L | CCM_ANALOG_PLL_ARM_POWERDOWN_L |
|
||||
CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK;
|
||||
|
@ -545,9 +538,6 @@ uint32_t setarmclock(uint32_t frequency) {
|
|||
while (!(CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_LOCK_L)) {
|
||||
; // wait for lock
|
||||
}
|
||||
// printf("ARM PLL=%x\n", CCM_ANALOG->PLL_ARM);
|
||||
} else {
|
||||
// printf("ARM PLL already running at required frequency\n");
|
||||
}
|
||||
|
||||
if ((CCM->CACRR & ((uint32_t)(0x07 << 0))) != (div_arm - 1)) {
|
||||
|
@ -588,11 +578,8 @@ uint32_t setarmclock(uint32_t frequency) {
|
|||
F_BUS_ACTUAL = frequency / div_ipg;
|
||||
// scale_cpu_cycles_to_microseconds = 0xFFFFFFFFu / (uint32_t)(frequency / 1000000u);
|
||||
|
||||
// printf("New Frequency: ARM=%u, IPG=%u\n", frequency, frequency / div_ipg);
|
||||
|
||||
// if voltage needs to decrease, do it after switch clock speed
|
||||
if ((dcdc & ((uint32_t)(0x1F << 0))) > ((uint32_t)(((voltage - 800) / 25) & 0x1F) << 0)) {
|
||||
// printf("Decreasing voltage to %u mV\n", voltage);
|
||||
dcdc &= ~((uint32_t)(0x1F << 0));
|
||||
dcdc |= ((uint32_t)(0x1F << 0));
|
||||
DCDC->REG3 = dcdc;
|
||||
|
|
|
@ -347,6 +347,9 @@ CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO)
|
|||
CIRCUITPY_SERIAL_BLE ?= 0
|
||||
CFLAGS += -DCIRCUITPY_SERIAL_BLE=$(CIRCUITPY_SERIAL_BLE)
|
||||
|
||||
CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY?= 0
|
||||
CFLAGS += -DCIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY=$(CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY)
|
||||
|
||||
CIRCUITPY_SHARPDISPLAY ?= $(CIRCUITPY_FRAMEBUFFERIO)
|
||||
CFLAGS += -DCIRCUITPY_SHARPDISPLAY=$(CIRCUITPY_SHARPDISPLAY)
|
||||
|
||||
|
|
|
@ -73,24 +73,18 @@
|
|||
//| """The CPU operating frequency in Hertz. (read-only)"""
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t mcu_processor_set_sys_clock(mp_obj_t self, mp_obj_t freq) {
|
||||
#if defined(HAS_SETTABLE_CLOCK)
|
||||
uint32_t value_of_freq = MP_OBJ_SMALL_INT_VALUE(freq);
|
||||
common_hal_mcu_processor_set_sys_clock(self, value_of_freq);
|
||||
STATIC mp_obj_t mcu_processor_set_frequency(mp_obj_t self, mp_obj_t freq) {
|
||||
#if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY
|
||||
uint32_t value_of_freq = (uint32_t)mp_arg_validate_int_min(mp_obj_get_int(freq), 0, MP_QSTR_frequency);
|
||||
common_hal_mcu_processor_set_frequency(self, value_of_freq);
|
||||
#else
|
||||
mp_raise_msg(&mp_type_NotImplementedError,translate("Settable Clock Not Implemented for Your Board"));
|
||||
#endif
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mcu_processor_set_sys_clock_obj, mcu_processor_set_sys_clock);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mcu_processor_set_frequency_obj, mcu_processor_set_frequency);
|
||||
|
||||
const mp_obj_property_t mcu_processor_freq_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&mcu_processor_set_sys_clock_obj,
|
||||
MP_ROM_NONE,
|
||||
MP_ROM_NONE},
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mcu_processor_get_frequency(mp_obj_t self) {
|
||||
return mp_obj_new_int_from_uint(common_hal_mcu_processor_get_frequency());
|
||||
|
@ -101,7 +95,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mcu_processor_get_frequency_obj, mcu_processor_get_fre
|
|||
const mp_obj_property_t mcu_processor_frequency_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&mcu_processor_get_frequency_obj, // getter
|
||||
MP_ROM_NONE, // no setter
|
||||
(mp_obj_t)&mcu_processor_set_frequency_obj, // setter
|
||||
MP_ROM_NONE, // no deleter
|
||||
},
|
||||
};
|
||||
|
@ -188,7 +182,6 @@ STATIC const mp_rom_map_elem_t mcu_processor_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&mcu_processor_temperature_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_uid), MP_ROM_PTR(&mcu_processor_uid_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_voltage), MP_ROM_PTR(&mcu_processor_voltage_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setfrequency), MP_ROM_PTR(&mcu_processor_set_sys_clock_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mcu_processor_locals_dict, mcu_processor_locals_dict_table);
|
||||
|
|
|
@ -39,6 +39,6 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void);
|
|||
float common_hal_mcu_processor_get_temperature(void);
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]);
|
||||
float common_hal_mcu_processor_get_voltage(void);
|
||||
uint32_t common_hal_mcu_processor_set_sys_clock(mcu_processor_obj_t *self, uint32_t frequency);
|
||||
uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PROCESSOR_H
|
||||
|
|
Loading…
Reference in New Issue