Skip to content

Commit dd41474

Browse files
committed
test: unoq: implement direct RAM loading
1 parent 219fe72 commit dd41474

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

loader/main.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,33 @@ static int loader(const struct shell *sh)
139139

140140
gpio_pin_configure_dt(&spec, GPIO_INPUT | GPIO_PULL_DOWN);
141141
k_sleep(K_MSEC(200));
142-
if (gpio_pin_get_dt(&spec) == 0) {
142+
uint8_t* ram_firmware = NULL;
143+
uint32_t *ram_start = (uint32_t *)0x20000000;
144+
if (!sketch_valid) {
145+
ram_firmware = (uint8_t*)k_malloc(64 * 1024);
146+
if (!ram_firmware) {
147+
printk("Failed to allocate RAM for firmware\n");
148+
return -ENOMEM;
149+
}
150+
memset(ram_firmware, 0, 64 * 1024);
151+
*ram_start = &ram_firmware[0];
152+
}
153+
if (gpio_pin_get_dt(&spec) == 0 || (ram_firmware != NULL)) {
143154
matrixBegin();
144155
matrixSetGrayscaleBits(8);
145-
while (gpio_pin_get_dt(&spec) == 0) {
156+
while (gpio_pin_get_dt(&spec) == 0 || (ram_firmware != NULL)) {
146157
matrixPlay(_bootanimation, _bootanimation_len);
158+
if (ram_firmware != NULL) {
159+
printk("Trying to load firmware from RAM: %p\n", ram_firmware);
160+
// poll the first bytes, if filled try to use them for booting
161+
sketch_hdr = (struct sketch_header_v1 *)(ram_firmware + 7);
162+
if (sketch_hdr->ver == 0x1 && sketch_hdr->magic == 0x2341) {
163+
// Found valid data, use it for booting
164+
base_addr = (uintptr_t)ram_firmware;
165+
*ram_start = 0;
166+
break;
167+
}
168+
}
147169
}
148170
matrixPlay(_bootanimation_end, _bootanimation_end_len);
149171
uint8_t _framebuffer[104] = {0};

variants/b_u585i_iot02a_stm32u585xx/b_u585i_iot02a_stm32u585xx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CONFIG_LLEXT_STORAGE_WRITABLE=n
2-
CONFIG_HEAP_MEM_POOL_SIZE=32768
2+
CONFIG_HEAP_MEM_POOL_SIZE=131072
33
CONFIG_SHELL_STACK_SIZE=32768
44
CONFIG_MAIN_STACK_SIZE=32768
55
CONFIG_LLEXT_HEAP_SIZE=128

0 commit comments

Comments
 (0)