This is an automated email from the ASF dual-hosted git repository. kasjer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 09cfd483b5a6fb48ba619509e72b04a6decd6307 Author: Jerzy Kasenberg <[email protected]> AuthorDate: Mon Oct 19 12:47:26 2026 +0200 flash_test: Add configurable buffer size Read and write commands used 32 byte buffer on stack, so each 32 bytes was separate flash driver call. That is slow for flash devices with high per call cost (e.g. flash of other MCU accessed over a link). FLASH_TEST_BUFFER_SIZE (default 0 keeps 32 byte stack buffer) selects size of static buffer used instead. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jerzy Kasenberg <[email protected]> --- test/flash_test/src/flash_test.c | 17 ++++++++++++++--- test/flash_test/syscfg.yml | 7 +++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test/flash_test/src/flash_test.c b/test/flash_test/src/flash_test.c index 0a3804a3a..9ea991cf1 100644 --- a/test/flash_test/src/flash_test.c +++ b/test/flash_test/src/flash_test.c @@ -42,6 +42,11 @@ dump_sector_range_info(struct streamer *streamer, int start_sector, uint32_t sta } } +#if MYNEWT_VAL(FLASH_TEST_BUFFER_SIZE) +/* Static, so it can be bigger than shell task stack allows */ +static char flash_cli_buf[MYNEWT_VAL(FLASH_TEST_BUFFER_SIZE)]; +#endif + static int flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer) @@ -55,7 +60,13 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, int devid = 0; int rc; char *eptr; +#if MYNEWT_VAL(FLASH_TEST_BUFFER_SIZE) + char *tmp_buf = flash_cli_buf; + const uint32_t tmp_buf_size = sizeof(flash_cli_buf); +#else char tmp_buf[32]; + const uint32_t tmp_buf_size = sizeof(tmp_buf); +#endif char pr_str[80]; /* arg_idx points to first argument after 'flash' */ int arg_idx = 1; @@ -192,7 +203,7 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, (long unsigned int) off, (long unsigned int) sz); sz += off; while (off < sz) { - sec_cnt = min(sizeof(tmp_buf), sz - off); + sec_cnt = min(tmp_buf_size, sz - off); if (hal_flash_read(devid, fa_off + off, tmp_buf, sec_cnt)) { streamer_printf(streamer, "flash read failure at %#lx\n", (long unsigned int) off); @@ -218,12 +229,12 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, (long unsigned int) off, (long unsigned int) sz); sz += off; - for (i = 0; i < sizeof(tmp_buf); i++) { + for (i = 0; i < tmp_buf_size; i++) { tmp_buf[i] = i + 1; } while (off < sz) { - sec_cnt = min(sizeof(tmp_buf), sz - off); + sec_cnt = min(tmp_buf_size, sz - off); if (hal_flash_write(devid, fa_off + off, tmp_buf, sec_cnt)) { streamer_printf(streamer, "flash write failure at %#lx\n", (long unsigned int) off); diff --git a/test/flash_test/syscfg.yml b/test/flash_test/syscfg.yml index 9d3c811a8..db60f35fb 100644 --- a/test/flash_test/syscfg.yml +++ b/test/flash_test/syscfg.yml @@ -18,3 +18,10 @@ # syscfg.defs: + FLASH_TEST_BUFFER_SIZE: + description: > + Size of buffer used by flash read and write commands. When 0, + 32 byte buffer on stack is used. Otherwise static buffer of this + size is used, so bigger chunks are passed to flash driver + (fewer requests for remote or slow flash devices). + value: 0
