Skip to content

Commit abedea7

Browse files
committed
Allocated memory for the PFS buffer dynamically. Saves 60 bytes.
1 parent 94fa768 commit abedea7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

inc/bluetooth/MicroBitPartialFlashingService.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class MicroBitPartialFlashingService
101101
uint8_t blockPacketCount = 0;
102102

103103
// Keep track of blocks of data
104-
uint32_t block[16];
104+
// uint32_t block[16]; // Replaced with pointer, memory allocated when PFS is used
105+
uint32_t *block = NULL;
105106
uint8_t blockNum = 0;
106107
uint32_t offset = 0;
107108

source/bluetooth/MicroBitPartialFlashingService.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ void MicroBitPartialFlashingService::flashData(uint8_t *data)
200200

201201
packetCount++;
202202

203+
// Reallocate block
204+
if(block == NULL) {
205+
(uint32_t*) malloc(16 * sizeof(uint32_t));
206+
}
207+
203208
// Add to block
204209
memcpy(block + (4*blockNum), data + 4, 16);
205210

0 commit comments

Comments
 (0)