@@ -477,9 +477,18 @@ def esp32_s3_args(extra_args):
477477 dest = 'oct_flash' ,
478478 action = 'store_true'
479479 )
480+ esp_argParser .add_argument (
481+ '--py-freertos' ,
482+ help = 'espose FreeRTOS to Python' ,
483+ dest = 'py_freertos' ,
484+ action = 'store_true'
485+ )
480486
481487 esp_args , extra_args = esp_argParser .parse_known_args (extra_args )
482488
489+ if esp_args .py_freertos :
490+ os .environ ['PY_FREERTOS' ] = '1'
491+
483492 oct_flash = esp_args .oct_flash
484493 board_variant = esp_args .board_variant
485494
@@ -984,6 +993,7 @@ def find_esp32_ports(chip):
984993
985994SDKCONFIG_PATH = f'build/sdkconfig.board'
986995
996+ MPTHREADPORT_H_PATH = 'lib/micropython/ports/esp32/mpthreadport.h'
987997MPTHREADPORT_PATH = 'lib/micropython/ports/esp32/mpthreadport.c'
988998MPCONFIGPORT_PATH = 'lib/micropython/ports/esp32/mpconfigport.h'
989999PANICHANDLER_PATH = 'lib/micropython/ports/esp32/panichandler.c'
@@ -996,8 +1006,55 @@ def find_esp32_ports(chip):
9961006
9971007
9981008def update_mpthreadport ():
999- # data = read_file('esp32', MPTHREADPORT_PATH)
1000- #
1009+ h_data = read_file ('esp32' , MPTHREADPORT_H_PATH )
1010+
1011+ if 'typedef mp_thread_mutex_t mp_thread_recursive_mutex_t;' not in h_data :
1012+ new_data = [
1013+ '} mp_thread_mutex_t;' ,
1014+ '' ,
1015+ '#if MICROPY_PY_THREAD_GIL == 0' ,
1016+ 'typedef mp_thread_mutex_t mp_thread_recursive_mutex_t;' ,
1017+ 'void mp_thread_recursive_mutex_init(mp_thread_recursive_mutex_t *mutex);' ,
1018+ 'int mp_thread_recursive_mutex_lock(mp_thread_recursive_mutex_t *mutex, int wait);' ,
1019+ 'void mp_thread_recursive_mutex_unlock(mp_thread_recursive_mutex_t *mutex);' ,
1020+ '#endif'
1021+ ]
1022+
1023+ h_data = h_data .replace (
1024+ '} mp_thread_mutex_t;' ,
1025+ '\n ' .join (new_data )
1026+ )
1027+
1028+ c_data = read_file ('esp32' , MPTHREADPORT_PATH )
1029+
1030+ new_data = [
1031+ '} mp_thread_t;' ,
1032+ '' ,
1033+ '#if MICROPY_PY_THREAD_GIL == 0' ,
1034+ 'void mp_thread_recursive_mutex_init(mp_thread_recursive_mutex_t *mutex)' ,
1035+ '{' ,
1036+ ' mutex->handle = xSemaphoreCreateRecursiveMutexStatic(&mutex->buffer);' ,
1037+ ' xSemaphoreGiveRecursive(mutex->handle);' ,
1038+ '}' ,
1039+ '' ,
1040+ 'int mp_thread_recursive_mutex_lock(mp_thread_recursive_mutex_t *mutex, int wait)' ,
1041+ '{' ,
1042+ ' return pdTRUE == xSemaphoreTakeRecursive(mutex->handle, pdMS_TO_TICKS((uint32_t)wait));' ,
1043+ '}' ,
1044+ '' ,
1045+ 'void mp_thread_recursive_mutex_unlock(mp_thread_recursive_mutex_t *mutex)' ,
1046+ '{' ,
1047+ ' xSemaphoreGiveRecursive(mutex->handle);' ,
1048+ '}' ,
1049+ '#endif'
1050+ ]
1051+ c_data = c_data .replace (
1052+ '} mp_thread_t;' ,
1053+ '\n ' .join (new_data )
1054+ )
1055+
1056+ write_file (MPTHREADPORT_PATH , c_data )
1057+
10011058 # if '_CORE_ID' not in data:
10021059 # data = data.replace('MP_TASK_COREID', '_CORE_ID')
10031060 #
@@ -1014,7 +1071,7 @@ def update_mpthreadport():
10141071 #
10151072 # data = data.replace('#if MICROPY_PY_THREAD', '\n'.join(new_data), 1)
10161073 #
1017- # write_file(MPTHREADPORT_PATH, data )
1074+ write_file (MPTHREADPORT_H_PATH , h_data )
10181075 pass
10191076
10201077
@@ -1420,7 +1477,7 @@ def compile(*args): # NOQA
14201477 app_size = app_size .split ('micropython.bin size' , 1 )[1 ]
14211478 app_size = int (app_size .split (':' , 1 )[0 ].strip (), 16 )
14221479
1423- partition .set_app_size (app_size )
1480+ partition .set_app_size (app_size ) # NOQA
14241481 partition .save ()
14251482
14261483 sys .stdout .write (
0 commit comments