10000 Merge pull request #2407 from dhalbert/4.1.x-increase-cpx-stack-updat… · adafruit/circuitpython@483a6a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 483a6a9

Browse files
authored
Merge pull request #2407 from dhalbert/4.1.x-increase-cpx-stack-update-frozen
4.1.x increase cpx stack update frozen
2 parents 8d43848 + 6265ee0 commit 483a6a9

19 files changed

+89
-49
lines changed

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
// Explanation of how a user got into safe mode.
3434
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
3535

36+
// Increase stack size slightly due to CPX library import nesting
37+
#define CIRCUITPY_DEFAULT_STACK_SIZE (4632) // Must be divisible by 8 or will HardFault.
38+
3639
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
3740
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
3841

ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
// Explanation of how a user got into safe mode.
3434
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
3535

36+
// Increase stack size slightly due to CPX library import nesting
37+
#define CIRCUITPY_DEFAULT_STACK_SIZE (4632) // Must be divisible by 8 or will HardFault.
38+
3639
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
3740
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
3841

ports/atmel-samd/mpconfigport.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#define CIRCUITPY_MCU_FAMILY samd21
3535
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
3636
#define SPI_FLASH_MAX_BAUDRATE 8000000
37-
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
3837
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
3938
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
4039
#define MICROPY_PY_FUNCTION_ATTRS (0)
@@ -69,6 +68,7 @@
6968
#define MICROPY_PY_UJSON (1)
7069
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
7170
// MICROPY_PY_UERRNO_LIST - Use the default
71+
7272
#endif
7373

7474
// Turning off audioio, audiobusio, and touchio as necessary
@@ -78,6 +78,19 @@
7878

7979
#include "py/circuitpy_mpconfig.h"
8080

81+
82+
#ifdef SAMD21
83+
#ifndef CIRCUITPY_DEFAULT_STACK_SIZE
84+
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
85+
#endif
86+
#endif
87+
88+
#ifdef SAMD51
89+
#ifndef CIRCUITPY_DEFAULT_STACK_SIZE
90+
#define CIRCUITPY_DEFAULT_STACK_SIZE (24*1024)
91+
#endif
92+
#endif
93+
8194
#define MICROPY_PORT_ROOT_POINTERS \
8295
CIRCUITPY_COMMON_ROOT_POINTERS \
8396
mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT];

py/makeqstrdata.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,10 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
103103
# go through each qstr and print it out
104104
for _, _, qstr in qstrs.values():
105105
all_strings.append(qstr)
106-
all_strings_concat = "".join(all_strings).encode("utf-8")
106+
all_strings_concat = "".join(all_strings)
107107
counts = collections.Counter(all_strings_concat)
108-
# add other values
109-
for i in range(256):
110-
if i not in counts:
111-
counts[i] = 0
112108
cb = huffman.codebook(counts.items())
113-
values = bytearray()
109+
values = []
114< 10000 /td>110
length_count = {}
115111
renumbered = 0
116112
last_l = None
@@ -124,26 +120,27 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
124120
if last_l:
125121
renumbered <<= (l - last_l)
126122
canonical[ch] = '{0:0{width}b}'.format(renumbered, width=l)
127-
if chr(ch) in C_ESCAPES:
128-
s = C_ESCAPES[chr(ch)]
129-
else:
130-
s = chr(ch)
131-
print("//", ch, s, counts[ch], canonical[ch], renumbered)
123+
s = C_ESCAPES.get(ch, ch)
124+
print("//", ord(ch), s, counts[ch], canonical[ch], renumbered)
132125
renumbered += 1
133126
last_l = l
134127
lengths = bytearray()
135-
for i in range(1, max(length_count) + 1):
128+
print("// length count", length_count)
129+
for i in range(1, max(length_count) + 2):
136130
lengths.append(length_count.get(i, 0))
131+
print("// values", values, "lengths", len(lengths), lengths)
132+
print("// estimated total memory size", len(lengths) + 2*len(values) + sum(len(cb[u]) for u in all_strings_concat))
137133
print("//", values, lengths)
134+
values_type = "uint16_t" if max(ord(u) for u in values) > 255 else "uint8_t"
138135
with open(compression_filename, "w") as f:
139136
f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths))))
140-
f.write("const uint8_t values[256] = {{ {} }};\n".format(", ".join(map(str, values))))
137+
f.write("const {} values[] = {{ {} }};\n".format(values_type, ", ".join(str(ord(u)) for u in values)))
141138
return values, lengths
142139

143140
def decompress(encoding_table, length, encoded):
144141
values, lengths = encoding_table
145142
#print(l, encoded)
146-
dec = bytearray(length)
143+
dec = []
147144
this_byte = 0
148145
this_bit = 7
149146
b = encoded[this_byte]
@@ -173,14 +170,14 @@ def decompress(encoding_table, length, encoded):
173170
searched_length += lengths[bit_length]
174171

175172
v = values[searched_length + bits - max_code]
176-
dec[i] = v
177-
return dec
173+
dec.append(v)
174+
return ''.join(dec)
178175

179176
def compress(encoding_table, decompressed):
180-
if not isinstance(decompressed, bytes):
177+
if not isinstance(decompressed, str):
181178
raise TypeError()
182179
values, lengths = encoding_table
183-
enc = bytearray(len(decompressed))
180+
enc = bytearray(len(decompressed) * 3)
184181
#print(decompressed)
185182
#print(lengths)
186183
current_bit = 7
@@ -227,6 +224,8 @@ def compress(encoding_table, decompressed):
227224
current_bit -= 1
228225
if current_bit != 7:
229226
current_byte += 1
227+
if current_byte > len(decompressed):
228+
print("Note: compression increased length", repr(decompressed), len(decompressed), current_byte, file=sys.stderr)
230229
return enc[:current_byte]
231230

232231
def qstr_escape(qst):
@@ -345,9 +344,9 @@ def print_qstr_data(encoding_table, qcfgs, qstrs, i18ns):
345344
total_text_compressed_size = 0
346345
for original, translation in i18ns:
347346
translation_encoded = translation.encode("utf-8")
348-
compressed = compress(encoding_table, translation_encoded)
347+
compressed = compress(encoding_table, translation)
349348
total_text_compressed_size += len(compressed)
350-
decompressed = decompress(encoding_table, len(translation_encoded), compressed).decode("utf-8")
349+
decompressed = decompress(encoding_table, len(translation_encoded), compressed)
351350
for c in C_ESCAPES:
352351
decompressed = decompressed.replace(c, C_ESCAPES[c])
353352
print("TRANSLATION(\"{}\", {}, {{ {} }}) // {}".format(original, len(translation_encoded)+1, ", ".join(["0x{:02x}".format(x) for x in compressed]), decompressed))

supervisor/shared/rgb_led_status.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ static digitalio_digitalinout_obj_t status_neopixel;
3939

4040
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
4141
uint8_t rgb_status_brightness = 255;
42-
static uint8_t status_apa102_color[12] = {0, 0, 0, 0, 0xff, 0, 0, 0};
42+
43+
#define APA102_BUFFER_LENGTH 12
44+
static uint8_t status_apa102_color[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff};
45+
4346
#ifdef CIRCUITPY_BITBANG_APA102
4447
#include "shared-bindings/bitbangio/SPI.h"
4548
#include "shared-module/bitbangio/types.h"
@@ -104,10 +107,12 @@ void rgb_led_status_init() {
104107
apa102_sck_in_use = false;
105108
#ifdef CIRCUITPY_BITBANG_APA102
106109
shared_module_bitbangio_spi_try_lock(&status_apa102);
107-
shared_module_bitbangio_spi_configure(&status_apa102, 100000, 0, 1, 8);
110+
// Use 1MHz for clock rate. Some APA102's are spec'd 800kHz-1200kHz,
111+
// though many can run much faster. bitbang will probably run slower.
112+
shared_module_bitbangio_spi_configure(&status_apa102, 1000000, 0, 0, 8);
108113
#else
109114
common_hal_busio_spi_try_lock(&status_apa102);
110-
common_hal_busio_spi_configure(&status_apa102, 100000, 0, 1, 8);
115+
common_hal_busio_spi_configure(&status_apa102, 1000000, 0, 0, 8);
111116
#endif
112117
#endif
113118

@@ -120,7 +125,7 @@ void rgb_led_status_init() {
120125
common_hal_pulseio_pwmout_never_reset(&rgb_status_r);
121126
}
122127
}
123-
128+
124129
if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_G)) {
125130
pwmout_result_t green_result = common_hal_pulseio_pwmout_construct(&rgb_status_g, CP_RGB_STATUS_G, 0, 50000, false);
126131

@@ -186,9 +191,9 @@ void new_status_color(uint32_t rgb) {
186191
status_apa102_color[7] = (rgb_adjusted >> 16) & 0xff;
187192

188193
#ifdef CIRCUITPY_BITBANG_APA102
189-
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
194+
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
190195
#else
191-
common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8);
196+
common_hal_busio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
192197
#endif
193198
#endif
194199

@@ -229,20 +234,20 @@ void temp_status_color(uint32_t rgb) {
229234
if (apa102_mosi_in_use || apa102_sck_in_use) {
230235
return;
231236
}
232-
uint8_t colors[12] = {0, 0, 0, 0, 0xff, rgb_adjusted & 0xff, (rgb_adjusted >> 8) & 0xff, (rgb_adjusted >> 16) & 0xff, 0x0, 0x0, 0x0, 0x0};
237+
uint8_t colors[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, rgb_adjusted & 0xff, (rgb_adjusted >> 8) & 0xff, (rgb_adjusted >> 16) & 0xff, 0xff, 0xff, 0xff, 0xff};
233238
#ifdef CIRCUITPY_BITBANG_APA102
234-
shared_module_bitbangio_spi_write(&status_apa102, colors, 12);
239+
shared_module_bitbangio_spi_write(&status_apa102, colors, APA102_BUFFER_LENGTH);
235240
#else
236-
common_hal_busio_spi_write(&status_apa102, colors, 12);
241+
common_hal_busio_spi_write(&status_apa102, colors, APA102_BUFFER_LENGTH);
237242
#endif
238243
#endif
239244
#if defined(CP_RGB_STATUS_LED)
240245
uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF;
241246
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
242247
uint8_t blue_u8 = rgb_adjusted & 0xFF;
243-
248+
244249
uint16_t temp_status_color_rgb[3] = {0};
245-
250+
246251
#if defined(CP_RGB_STATUS_INVERTED_PWM)
247252
temp_status_color_rgb[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
248253
temp_status_color_rgb[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
@@ -265,9 +270,9 @@ void clear_temp_status() {
265270
#endif
266271
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
267272
#ifdef CIRCUITPY_BITBANG_APA102
268-
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
273+
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
269274
#else
270-
common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8);
275+
common_hal_busio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
271276
#endif
272277
#endif
273278
#if defined(CP_RGB_STATUS_LED)

supervisor/shared/translate.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,28 @@ void serial_write_compressed(const compressed_string_t* compressed) {
4242
serial_write(decompressed);
4343
}
4444

45+
STATIC int put_utf8(char *buf, int u) {
46+
if(u <= 0x7f) {
47+
*buf = u;
48+
return 1;
49+
} else if(u <= 0x07ff) {
50+
*buf++ = 0b11000000 | (u >> 6);
51+
*buf = 0b10000000 | (u & 0b00111111);
52+
return 2;
53+
} else { // u <= 0xffff)
54+
*buf++ = 0b11000000 | (u >> 12);
55+
*buf = 0b10000000 | ((u >> 6) & 0b00111111);
56+
*buf = 0b10000000 | (u & 0b00111111);
57+
return 3;
58+
}
59+
}
60+
4561
char* decompress(const compressed_string_t* compressed, char* decompressed) {
4662
uint8_t this_byte = 0;
4763
uint8_t this_bit = 7;
4864
uint8_t b = compressed->data[this_byte];
4965
// Stop one early because the last byte is always NULL.
50-
for (uint16_t i = 0; i < compressed->length - 1; i++) {
66+
for (uint16_t i = 0; i < compressed->length - 1;) {
5167
uint32_t bits = 0;
5268
uint8_t bit_length = 0;
5369
uint32_t max_code = lengths[0];
@@ -72,7 +88,7 @@ char* decompress(const compressed_string_t* compressed, char* decompressed) {
7288
max_code = (max_code << 1) + lengths[bit_length];
7389
searched_length += lengths[bit_length];
7490
}
75-
decompressed[i] = values[searched_length + bits - max_code];
91+
i += put_utf8(decompressed + i, values[searched_length + bits - max_code]);
7692
}
7793

7894
decompressed[compressed->length-1] = '\0';

tools/build_memory_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@
6161
space = M_PATTERN.sub(M_REPLACE, space)
6262
regions[region] = eval(space)
6363

64+
ram_region = regions["RAM"]
6465
free_flash = regions["FLASH"] - text - data
6566
free_ram = regions["RAM"] - data - bss
6667
print(free_flash, "bytes free in flash out of", regions["FLASH"], "bytes (", regions["FLASH"] / 1024, "kb ).")
67-
print(free_ram, "bytes free in ram for stack out of", regions["RAM"], "bytes (", regions["RAM"] / 1024, "kb ).")
68+
print("{} bytes free in ram for stack and heap out of {} bytes ({}kB).".format(free_ram, ram_region, ram_region / 1024))
6869
print()
6970

7071
# Check that we have free flash space. GCC doesn't fail when the text + data

0 commit comments

Comments
 (0)
0