Skip to content

Commit c584ef9

Browse files
committed
adds --task-stack-size build argument.
This sets the stack size for a FreeRTOS task. We ran into an issue with the HX8369 driver where there was not enough stack memory to pass some of the init parameters. This allows the user to adjust the stack size if they encounter this issue.
1 parent 47fc04a commit c584ef9

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

api_drivers/common_api_drivers/display/hx8369/_hx8369_init_type1.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def init(self):
2727
param_buf[:19] = bytearray([
2828
0x01, 0x00, 0x34, 0x06, 0x00, 0x0f, 0x0f, 0x2a, 0x32, 0x3f,
2929
0x3f, 0x07, 0x23, 0x01, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6])
30-
30+
3131
self.set_params(0xB1, param_mv[:19])
3232

3333
# SET Display 480x800
@@ -63,24 +63,21 @@ def init(self):
6363
self.set_params(0xE0, param_mv[:34])
6464

6565
# Set DGC
66-
param_buf[:64] = bytearray([
66+
param_buf[:127] = bytearray([
6767
0x01, 0x02, 0x08, 0x12, 0x1a, 0x22, 0x2a, 0x31, 0x36,
6868
0x3f, 0x48, 0x51, 0x58, 0x60, 0x68, 0x70, 0x78, 0x80,
6969
0x88, 0x90, 0x98, 0xa0, 0xa7, 0xaf, 0xb6, 0xbe, 0xc7,
7070
0xce, 0xd6, 0xde, 0xe6, 0xef, 0xf5, 0xfb, 0xfc, 0xfe,
7171
0x8c, 0xa4, 0x19, 0xec, 0x1b, 0x4c, 0x40, 0x02, 0x08,
7272
0x12, 0x1a, 0x22, 0x2a, 0x31, 0x36, 0x3f, 0x48, 0x51,
7373
0x58, 0x60, 0x68, 0x70, 0x78, 0x80, 0x88, 0x90, 0x98,
74-
0xa0])
75-
76-
param_buf[64:127] = bytearray([
77-
0xa7, 0xaf, 0xb6, 0xbe, 0xc7, 0xce, 0xd6, 0xde, 0xe6,
78-
0xef, 0xf5, 0xfb, 0xfc, 0xfe, 0x8c, 0xa4, 0x19, 0xec,
79-
0x1b, 0x4c, 0x40, 0x02, 0x08, 0x12, 0x1a, 0x22, 0x2a,
80-
0x31, 0x36, 0x3f, 0x48, 0x51, 0x58, 0x60, 0x68, 0x70,
81-
0x78, 0x80, 0x88, 0x90, 0x98, 0xa0, 0xa7, 0xaf, 0xb6,
82-
0xbe, 0xc7, 0xce, 0xd6, 0xde, 0xe6, 0xef, 0xf5, 0xfb,
83-
0xfc, 0xfe, 0x8c, 0xa4, 0x19, 0xec, 0x1b, 0x4c, 0x40])
74+
0xa0, 0xa7, 0xaf, 0xb6, 0xbe, 0xc7, 0xce, 0xd6, 0xde,
75+
0xe6, 0xef, 0xf5, 0xfb, 0xfc, 0xfe, 0x8c, 0xa4, 0x19,
76+
0xec, 0x1b, 0x4c, 0x40, 0x02, 0x08, 0x12, 0x1a, 0x22,
77+
0x2a, 0x31, 0x36, 0x3f, 0x48, 0x51, 0x58, 0x60, 0x68,
78+
0x70, 0x78, 0x80, 0x88, 0x90, 0x98, 0xa0, 0xa7, 0xaf,
79+
0xb6, 0xbe, 0xc7, 0xce, 0xd6, 0xde, 0xe6, 0xef, 0xf5,
80+
0xfb, 0xfc, 0xfe, 0x8c, 0xa4, 0x19, 0xec, 0x1b, 0x4c, 0x40])
8481

8582
self.set_params(0xC1, param_mv[:127])
8683

builder/esp32.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def get_espidf():
162162
ota = False
163163

164164
dual_core_threads = False
165+
task_stack_size = 16 * 1024
165166

166167

167168
def common_args(extra_args):
@@ -177,6 +178,7 @@ def common_args(extra_args):
177178
global optimize_size
178179
global ota
179180
global dual_core_threads
181+
global task_stack_size
180182

181183
if board == 'ARDUINO_NANO_ESP32':
182184
raise RuntimeError('Board is not currently supported')
@@ -269,6 +271,21 @@ def common_args(extra_args):
269271
action='store_true'
270272
)
271273

274+
def multiple_of_16(value):
275+
value = int(value)
276+
if value % 1024:
277+
raise ValueError('task stack size must be a multiple of 1024')
278+
279+
return value
280+
281+
esp_argParser.add_argument(
282+
'--task-stack-size',
283+
dest='task_stack_size',
284+
default=task_stack_size,
285+
type=multiple_of_16,
286+
action='store'
287+
)
288+
272289
esp_args, extra_args = esp_argParser.parse_known_args(extra_args)
273290

274291
BAUD = esp_args.baud
@@ -282,6 +299,7 @@ def common_args(extra_args):
282299
optimize_size = esp_args.optimize_size
283300
ota = esp_args.ota
284301
dual_core_threads = esp_args.dual_core_threads
302+
task_stack_size = esp_args.task_stack_size
285303

286304
return extra_args
287305

@@ -833,6 +851,24 @@ def set_thread_core():
833851
data = data.replace(pattern, text)
834852
break
835853

854+
data = data.split('\n')
855+
for i, line in enumerate(data[:]):
856+
if line.startswith('#ifndef MICROPY_CONFIG_ROM_LEVEL'):
857+
last_line = data[i - 2]
858+
859+
if not last_line.startswith('#define MICROPY_TASK_STACK_SIZE'):
860+
data.insert(i - 1, '')
861+
862+
multiple = int(task_stack_size / 1024)
863+
864+
data[i - 2] = (
865+
f'#define MICROPY_TASK_STACK_SIZE ({multiple} * 1024)'
866+
)
867+
868+
break
869+
870+
data = '\n'.join(data)
871+
836872
with open(MPCONFIGPORT_PATH, 'wb') as f:
837873
f.write(data.encode('utf-8'))
838874

0 commit comments

Comments
 (0)