-
-
Notifications
You must be signed in to change notification settings - Fork 80
Save programs on Prime Hub as they get downloaded #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55e0701
e1754c0
8913e0a
5e3f2af
de725ff
d357484
0cb0071
8971de7
b62ffc1
4b29eb3
7c89fa8
9c31ae5
8a988ad
e75d2c1
5bf94d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| #include <pybricks/common.h> | ||
| #include <pybricks/util_mp/pb_obj_helper.h> | ||
| #include <pybricks/util_pb/pb_flash.h> | ||
|
|
||
| #include "shared/readline/readline.h" | ||
| #include "shared/runtime/gchelper.h" | ||
|
|
@@ -185,8 +186,32 @@ static uint32_t get_user_program(uint8_t **buf, uint32_t *free_len) { | |
|
|
||
| // If button was pressed, return code to run script in flash | ||
| if (err == PBIO_ERROR_CANCELED) { | ||
| #if (PYBRICKS_HUB_PRIMEHUB || PYBRICKS_HUB_ESSENTIALHUB) | ||
| // Open existing main.mpy file from flash | ||
| uint32_t size = 0; | ||
| if (pb_flash_file_open_get_size("/_pybricks/main.mpy", &size) != PBIO_SUCCESS) { | ||
| return 0; | ||
| } | ||
| // Check size and allocate buffer | ||
| if (size > MPY_MAX_BYTES) { | ||
| return 0; | ||
| } | ||
| *buf = m_malloc(size); | ||
| if (*buf == NULL) { | ||
| return 0; | ||
| } | ||
| // Read the file contents | ||
| if (pb_flash_file_read(*buf, size) != PBIO_SUCCESS) { | ||
| m_free(*buf); | ||
| return 0; | ||
| } | ||
| *free_len = size; | ||
| return size; | ||
| #else | ||
| // Load main program embedded in firmware | ||
| *buf = &_pb_user_mpy_data; | ||
| return _pb_user_mpy_size; | ||
| #endif | ||
| } | ||
|
|
||
| // Handle other errors | ||
|
|
@@ -220,6 +245,12 @@ static uint32_t get_user_program(uint8_t **buf, uint32_t *free_len) { | |
| } | ||
|
|
||
| *free_len = len; | ||
|
|
||
| #if (PYBRICKS_HUB_PRIMEHUB || PYBRICKS_HUB_ESSENTIALHUB) | ||
| // Save program as file | ||
| pb_flash_file_write("/_pybricks/main.mpy", *buf, len); | ||
| #endif // (PYBRICKS_HUB_PRIMEHUB || PYBRICKS_HUB_ESSENTIALHUB) | ||
|
|
||
| return len; | ||
| } | ||
|
|
||
|
|
@@ -328,6 +359,12 @@ static void run_user_program(uint32_t len, uint8_t *buf, uint32_t free_len) { | |
| } | ||
|
|
||
| static void stm32_main(void) { | ||
|
|
||
| #if (PYBRICKS_HUB_PRIMEHUB || PYBRICKS_HUB_ESSENTIALHUB) | ||
| mp_hal_delay_ms(500); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this delay for?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason Bluetooth wouldn't come up without it. This initial read/write operation takes fairly long, so maybe there's still a bit too much blocking going on while everything else is initializing. |
||
| pb_flash_init(); | ||
| #endif | ||
|
|
||
| soft_reset: | ||
| // Stack limit should be less than real stack size, so we have a chance | ||
| // to recover from limit hit. (Limit is measured in bytes.) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of copying the file to RAM, it would be nice to just pass the file reader to compiler.