Skip to content

Commit 459f323

Browse files
authored
Merge pull request #4087 from DavePutz/cpu_temp_doc
Fixing microcontroller.cpu on multi-core cpus and adding microcontroller.cpus
2 parents 0c0b517 + e1838ff commit 459f323

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

ports/raspberrypi/common-hal/microcontroller/__init__.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void common_hal_mcu_reset(void) {
8080

8181
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
8282
// It currently only has properties, and no state.
83+
#if CIRCUITPY_PROCESSOR_COUNT > 1
8384
static const mcu_processor_obj_t processor0 = {
8485
.base = {
8586
.type = &mcu_processor_type,
@@ -92,14 +93,21 @@ static const mcu_processor_obj_t processor1 = {
9293
},
9394
};
9495

95-
const mp_rom_obj_tuple_t common_hal_mcu_processor_obj = {
96+
const mp_rom_obj_tuple_t common_hal_multi_processor_obj = {
9697
{&mp_type_tuple},
9798
CIRCUITPY_PROCESSOR_COUNT,
9899
{
99100
MP_ROM_PTR(&processor0),
100101
MP_ROM_PTR(&processor1)
101102
}
102103
};
104+
#endif
105+
106+
const mcu_processor_obj_t common_hal_mcu_processor_obj = {
107+
.base = {
108+
.type = &mcu_processor_type,
109+
},
110+
};
103111

104112
#if CIRCUITPY_NVM && CIRCUITPY_INTERNAL_NVM_SIZE > 0
105113
// The singleton nvm.ByteArray object.

shared-bindings/microcontroller/Processor.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@
4141
//|
4242
//| import microcontroller
4343
//| print(microcontroller.cpu.frequency)
44-
//| print(microcontroller.cpu.temperature)"""
44+
//| print(microcontroller.cpu.temperature)
45+
//|
46+
//| Note that on chips with more than one cpu (such as the RP2040)
47+
//| microcontroller.cpu will return the value for CPU 0.
48+
//| To get values from other CPUs use microcontroller.cpus indexed by
49+
//| the number of the desired cpu. i.e.
50+
//|
51+
//| print(microcontroller.cpus[0].temperature)
52+
//| print(microcontroller.cpus[1].frequency)"""
4553
//|
4654

4755
//| def __init__(self) -> None:

shared-bindings/microcontroller/__init__.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@
5353
//| cpu: Processor
5454
//| """CPU information and control, such as ``cpu.temperature`` and ``cpu.frequency``
5555
//| (clock frequency).
56-
//| This object is the sole instance of `microcontroller.Processor`."""
56+
//| This object is an instance of `microcontroller.Processor`."""
57+
//|
58+
59+
//| cpus: Processor
60+
//| """CPU information and control, such as ``cpus[0].temperature`` and ``cpus[1].frequency``
61+
//| (clock frequency) on chips with more than 1 cpu. The index selects which cpu.
62+
//| This object is an instance of `microcontroller.Processor`."""
5763
//|
5864

5965
//| def delay_us(delay: int) -> None:
@@ -155,6 +161,9 @@ const mp_obj_module_t mcu_pin_module = {
155161
STATIC const mp_rom_map_elem_t mcu_module_globals_table[] = {
156162
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_microcontroller) },
157163
{ MP_ROM_QSTR(MP_QSTR_cpu), MP_ROM_PTR(&common_hal_mcu_processor_obj) },
164+
#if CIRCUITPY_PROCESSOR_COUNT > 1
165+
{ MP_ROM_QSTR(MP_QSTR_cpus), MP_ROM_PTR(&common_hal_multi_processor_obj) },
166+
#endif
158167
{ MP_ROM_QSTR(MP_QSTR_delay_us), MP_ROM_PTR(&mcu_delay_us_obj) },
159168
{ MP_ROM_QSTR(MP_QSTR_disable_interrupts), MP_ROM_PTR(&mcu_disable_interrupts_obj) },
160169
{ MP_ROM_QSTR(MP_QSTR_enable_interrupts), MP_ROM_PTR(&mcu_enable_interrupts_obj) },

shared-bindings/microcontroller/__init__.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ extern const mp_obj_dict_t mcu_pin_globals;
4848
#if CIRCUITPY_PROCESSOR_COUNT == 1
4949
extern const mcu_processor_obj_t common_hal_mcu_processor_obj;
5050
#elif CIRCUITPY_PROCESSOR_COUNT > 1
51-
extern const mp_rom_obj_tuple_t common_hal_mcu_processor_obj;
51+
extern const mcu_processor_obj_t common_hal_mcu_processor_obj;
52+
extern const mp_rom_obj_tuple_t common_hal_multi_processor_obj;
5253
#else
5354
#error "Invalid processor count"
5455
#endif

0 commit comments

Comments
 (0)