Skip to content

Commit fb55686

Browse files
committed
ports/mimxrt: Add thread support.
Signed-off-by: tonyzhangnxp <tony.zhang@nxp.com>
1 parent 31e131b commit fb55686

File tree

19 files changed

+754
-10
lines changed

19 files changed

+754
-10
lines changed

ports/mimxrt/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ SRC_C += \
215215
systick.c \
216216
ticks.c \
217217
tusb_port.c \
218+
mpthreadport.c \
219+
pybthread.c\
220+
gccollect.c\
221+
218222

219223
SHARED_SRC_C += \
220224
shared/libc/printf.c \

ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ MICROPY_HW_FLASH_SIZE ?= 0x800000 # 8MB
88
MICROPY_PY_NETWORK_NINAW10 ?= 1
99
MICROPY_PY_SSL ?= 1
1010
MICROPY_SSL_MBEDTLS ?= 1
11+
12+
CFLAGS += -DMICROPY_PY_THREAD=0

ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ else
1414
JLINK_CONNECTION_SETTINGS = -USB
1515
endif
1616

17+
CFLAGS += -DMICROPY_PY_THREAD=0
18+
1719
deploy_jlink: $(BUILD)/firmware.hex
1820
$(Q)$(TOUCH) $(JLINK_COMMANDER_SCRIPT)
1921
$(ECHO) "ExitOnError 1" > $(JLINK_COMMANDER_SCRIPT)

ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ MICROPY_HW_FLASH_TYPE = qspi_nor_flash
66
MICROPY_HW_FLASH_SIZE = 0x1000000 # 16MB
77

88
MICROPY_BOOT_BUFFER_SIZE = (32 * 1024)
9+
10+
CFLAGS += -DMICROPY_PY_THREAD=0

ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1070evk"
55

6+
#if MICROPY_PY_THREAD
7+
#else
68
#define MICROPY_EVENT_POLL_HOOK \
79
do { \
810
extern void mp_handle_pending(bool); \
911
mp_handle_pending(true); \
1012
} while (0);
13+
#endif
1114

1215
// MIMXRT1170_EVK has 2 user LEDs
1316
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_04)

ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ MICROPY_PY_LWIP = 1
1414
MICROPY_PY_SSL = 1
1515
MICROPY_SSL_MBEDTLS = 1
1616

17+
CFLAGS += -DMICROPY_PY_THREAD=1
18+
1719
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
1820

1921
CFLAGS += -DCPU_MIMXRT1176DVMAA_cm7 \

ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ MICROPY_HW_FLASH_SIZE = 0x200000 # 2MB
77
MICROPY_HW_FLASH_RESERVED ?= 0x1000 # 4KB
88

99
CFLAGS += -DMICROPY_HW_FLASH_DQS=kFlexSPIReadSampleClk_LoopbackInternally
10+
CFLAGS += -DMICROPY_PY_THREAD=0
1011

1112
SRC_C += \
1213
hal/flexspi_nor_flash.c \

ports/mimxrt/gccollect.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013, 2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/gc.h"
28+
#include "py/mpthread.h"
29+
#include "shared/runtime/gchelper.h"
30+
#include "shared/runtime/softtimer.h"
31+
#include "gccollect.h"
32+
33+
void gc_collect(void) {
34+
// start the GC
35+
gc_collect_start();
36+
37+
// trace the stack and registers
38+
gc_helper_collect_regs_and_stack();
39+
40+
// trace root pointers from any threads
41+
#if MICROPY_PY_THREAD
42+
mp_thread_gc_others();
43+
#endif
44+
45+
// trace soft timer nodes
46+
soft_timer_gc_mark_all();
47+
48+
// end the GC
49+
gc_collect_end();
50+
}

ports/mimxrt/gccollect.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013, 2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef MICROPY_INCLUDED_STM32_GCCOLLECT_H
27+
#define MICROPY_INCLUDED_STM32_GCCOLLECT_H
28+
29+
// variables defining memory layout
30+
// (these probably belong somewhere else...)
31+
extern uint32_t _etext;
32+
extern uint32_t _sidata;
33+
extern uint32_t _ram_start;
34+
extern uint32_t _sdata;
35+
extern uint32_t _edata;
36+
extern uint32_t _sbss;
37+
extern uint32_t _ebss;
38+
extern uint32_t _heap_start;
39+
extern uint32_t _heap_end;
40+
extern uint32_t _sstack;
41+
extern uint32_t _estack;
42+
extern uint32_t _ram_end;
43+
44+
#endif // MICROPY_INCLUDED_STM32_GCCOLLECT_H

ports/mimxrt/main.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
#include "systick.h"
5757
#include "extmod/modnetwork.h"
5858

59+
#if MICROPY_PY_THREAD
60+
STATIC pyb_thread_t pyb_thread_main;
61+
#endif
62+
5963
extern uint8_t _sstack, _estack, _gc_heap_start, _gc_heap_end;
6064

6165
void board_init(void);
@@ -64,7 +68,9 @@ int main(void) {
6468
board_init();
6569
ticks_init();
6670
pendsv_init();
67-
71+
#if MICROPY_PY_THREAD
72+
pyb_thread_init(&pyb_thread_main);
73+
#endif
6874
#if MICROPY_PY_LWIP
6975
// lwIP doesn't allow to reinitialise itself by subsequent calls to this function
7076
// because the system timeout list (next_timeout) is only ever reset by BSS clearing.
@@ -96,6 +102,11 @@ int main(void) {
96102
led_init();
97103
#endif
98104

105+
// Python threading init
106+
#if MICROPY_PY_THREAD
107+
mp_thread_init();
108+
#endif
109+
99110
mp_stack_set_top(&_estack);
100111
mp_stack_set_limit(&_estack - &_sstack - 1024);
101112

@@ -163,12 +174,6 @@ int main(void) {
163174
return 0;
164175
}
165176

166-
void gc_collect(void) {
167-
gc_collect_start();
168-
gc_helper_collect_regs_and_stack();
169-
gc_collect_end();
170-
}
171-
172177
void nlr_jump_fail(void *val) {
173178
for (;;) {
174179
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy