8000 Shrink builds and handle 0-length writes · domdfcoding/circuitpython@3940878 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3940878

Browse files
committed
Shrink builds and handle 0-length writes
1 parent f2ef586 commit 3940878

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

ports/nrf/boards/pca10100/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CIRCUITPY_RE = 0
2727
CIRCUITPY_RGBMATRIX = 0
2828
CIRCUITPY_SDCARDIO = 0
2929
CIRCUITPY_ULAB = 0
30+
CIRCUITPY_USB_MIDI = 0
3031

3132
MICROPY_PY_ASYNC_AWAIT = 0
3233

ports/nrf/boards/simmel/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line number 8000 Diff line numberDiff line change
@@ -43,3 +43,5 @@ CIRCUITPY_WATCHDOG = 1
4343

4444
# Override optimization to keep binary small
4545
OPTIMIZATION_FLAGS = -Os
46+
SUPEROPT_VM = 0
47+
SUPEROPT_GC = 0

ports/nrf/common-hal/_bleio/__init__.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ void check_sec_status(uint8_t sec_status) {
9696

9797
// Turn off BLE on a reset or reload.
9898
void bleio_reset() {
99+
// Set this explicitly to save data.
100+
common_hal_bleio_adapter_obj.base.type = &bleio_adapter_type;
99101
if (!common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) {
100102
return;
101103
}
@@ -107,12 +109,8 @@ void bleio_reset() {
107109
}
108110

109111
// The singleton _bleio.Adapter object, bound to _bleio.adapter
110-
// It currently only has properties and no state
111-
bleio_adapter_obj_t common_hal_bleio_adapter_obj = {
112-
.base = {
113-
.type = &bleio_adapter_type,
114-
},
115-
};
112+
// It currently only has properties and no state. Inited by bleio_reset
113+
bleio_adapter_obj_t common_hal_bleio_adapter_obj;
116114

117115
void common_hal_bleio_check_connected(uint16_t conn_handle) {
118116
if (conn_handle == BLE_CONN_HANDLE_INVALID) {

ports/nrf/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#endif
5252

5353
// These are in order from highest available frequency to lowest (32MHz first, then 8MHz).
54-
STATIC spim_peripheral_t spim_peripherals[] = {
54+
STATIC const spim_peripheral_t spim_peripherals[] = {
5555
#if NRFX_CHECK(NRFX_SPIM3_ENABLED)
5656
// SPIM3 exists only on nRF52840 and supports 32MHz max. All other SPIM's are only 8MHz max.
5757
// Allocate SPIM3 first.

ports/nrf/common-hal/busio/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct {
3838

3939
typedef struct {
4040
mp_obj_base_t base;
41-
spim_peripheral_t *spim_peripheral;
41+
const spim_peripheral_t *spim_peripheral;
4242
bool has_lock;
4343
uint8_t clock_pin_number;
4444
uint8_t MOSI_pin_number;

supervisor/shared/bluetooth/file_transfer.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,26 @@ STATIC uint8_t _process_write(const uint8_t *raw_buf, size_t command_len) {
275275
// Align the next chunk to a sector boundary.
276276
uint32_t offset = command->offset;
277277
size_t chunk_size = MIN(total_write_length - offset, 512 - (offset % 512));
278+
// Special case when truncating the file. (Deleting stuff off the end.)
279+
if (chunk_size == 0) {
280+
f_lseek(&active_file, offset);
281+
f_truncate(&active_file);
282+
f_close(&active_file);
283+
#if CIRCUITPY_USB_MSC
284+
usb_msc_unlock();
285+
#endif
286+
}
278287
response.offset = offset;
279288
response.free_space = chunk_size;
280289
common_hal_bleio_packet_buffer_write(&_transfer_packet_buffer, (const uint8_t *)&response, sizeof(struct write_pacing), NULL, 0);
290+
if (chunk_size == 0) {
291+
// Don't reload until everything is written out of the packet buffer.
292+
common_hal_bleio_packet_buffer_flush(&_transfer_packet_buffer);
293+
// Trigger an autoreload
294+
autoreload_now();
295+
return ANY_COMMAND;
296+
}
297+
281298
return WRITE_DATA;
282299
}
283300

@@ -474,7 +491,12 @@ STATIC uint8_t _process_listdir(uint8_t *raw_buf, size_t command_len) {
474491
STATIC uint8_t current_command[COMMAND_SIZE] __attribute__ ((aligned(4)));
475492
STATIC volatile size_t current_offset;
476493
STATIC uint8_t next_command;
494+
STATIC bool running = false;
477495
void supervisor_bluetooth_file_transfer_background(void) {
496+
if (running) {
497+
return;
498+
}
499+
running = true;
478500
mp_int_t size = 1;
479501
while (size > 0) {
480502
size = common_hal_bleio_packet_buffer_readinto(&_transfer_packet_buffer, current_command + current_offset, COMMAND_SIZE - current_offset);
@@ -527,9 +549,11 @@ void supervisor_bluetooth_file_transfer_background(void) {
527549
current_offset = 0;
528550
}
529551
}
552+
running = false;
530553
}
531554

532555
void supervisor_bluetooth_file_transfer_disconnected(void) {
533556
next_command = ANY_COMMAND;
557+
current_offset = 0;
534558
f_close(&active_file);
535559
}

0 commit comments

Comments
 (0)
0