From ace22db85aefd0bc19ff2c1fa04d77e895505ba1 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 10 Jan 2025 15:15:10 +0000 Subject: [PATCH] Demo cleanup and optimization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16882 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- .../Makefile | 2 +- .../STM32L4R9xI_SB.ld | 85 ------------------- .../cfg/chconf.h | 2 +- .../main.c | 75 ++++++---------- .../cfg/chconf.h | 2 +- .../main.c | 65 +++++--------- demos/STM32/RT-VFS-FATFS/main.c | 5 +- 7 files changed, 50 insertions(+), 186 deletions(-) delete mode 100644 demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/STM32L4R9xI_SB.ld diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/Makefile b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/Makefile index 1aae46441..47ce05bb3 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/Makefile +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/Makefile @@ -126,7 +126,7 @@ include $(CHIBIOS)/os/hal/lib/streams/streams.mk include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk # Define linker script file here -LDSCRIPT= ./STM32L4R9xI_SB.ld +LDSCRIPT= $(STARTUPLD)/STM32L4R9xI.ld # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/STM32L4R9xI_SB.ld b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/STM32L4R9xI_SB.ld deleted file mode 100644 index 1c7656af5..000000000 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/STM32L4R9xI_SB.ld +++ /dev/null @@ -1,85 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* - * STM32L4R9xI memory setup. - */ -MEMORY -{ - flash0 (rx) : org = 0x08000000, len = 2M /* Host code. */ - flash1 (rx) : org = 0x00000000, len = 0 - flash2 (rx) : org = 0x00000000, len = 0 - flash3 (rx) : org = 0x00000000, len = 0 - flash4 (rx) : org = 0x00000000, len = 0 - flash5 (rx) : org = 0x00000000, len = 0 - flash6 (rx) : org = 0x00000000, len = 0 - flash7 (rx) : org = 0x00000000, len = 0 - ram0 (wx) : org = 0x20000000, len = 640k - 256k /* Host data. */ - ram1 (wx) : org = 0x20060000, len = 128k /* Sandbox 1. */ - ram2 (wx) : org = 0x20080000, len = 128k /* Sandbox 2. */ - ram3 (wx) : org = 0x00000000, len = 0 - ram4 (wx) : org = 0x00000000, len = 0 - ram5 (wx) : org = 0x00000000, len = 0 - ram6 (wx) : org = 0x00000000, len = 0 - ram7 (wx) : org = 0x00000000, len = 0 -} - -/* For each data/text section two region are defined, a virtual region - and a load region (_LMA suffix).*/ - -/* Flash region to be used for exception vectors.*/ -REGION_ALIAS("VECTORS_FLASH", flash0); -REGION_ALIAS("VECTORS_FLASH_LMA", flash0); - -/* Flash region to be used for constructors and destructors.*/ -REGION_ALIAS("XTORS_FLASH", flash0); -REGION_ALIAS("XTORS_FLASH_LMA", flash0); - -/* Flash region to be used for code text.*/ -REGION_ALIAS("TEXT_FLASH", flash0); -REGION_ALIAS("TEXT_FLASH_LMA", flash0); - -/* Flash region to be used for read only data.*/ -REGION_ALIAS("RODATA_FLASH", flash0); -REGION_ALIAS("RODATA_FLASH_LMA", flash0); - -/* Flash region to be used for various.*/ -REGION_ALIAS("VARIOUS_FLASH", flash0); -REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); - -/* Flash region to be used for RAM(n) initialization data.*/ -REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); - -/* RAM region to be used for Main stack. This stack accommodates the processing - of all exceptions and interrupts.*/ -REGION_ALIAS("MAIN_STACK_RAM", ram0); - -/* RAM region to be used for the process stack. This is the stack used by - the main() function.*/ -REGION_ALIAS("PROCESS_STACK_RAM", ram0); - -/* RAM region to be used for data segment.*/ -REGION_ALIAS("DATA_RAM", ram0); -REGION_ALIAS("DATA_RAM_LMA", flash0); - -/* RAM region to be used for BSS segment.*/ -REGION_ALIAS("BSS_RAM", ram0); - -/* RAM region to be used for the default heap.*/ -REGION_ALIAS("HEAP_RAM", ram0); - -/* Generic rules inclusion.*/ -INCLUDE rules.ld diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/cfg/chconf.h b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/cfg/chconf.h index 54f24de02..703413b1d 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/cfg/chconf.h +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/cfg/chconf.h @@ -836,7 +836,7 @@ /*===========================================================================*/ #define PORT_USE_SYSCALL TRUE -#define PORT_SWITCHED_REGIONS_NUMBER 2 +#define PORT_SWITCHED_REGIONS_NUMBER 1 #endif /* CHCONF_H */ diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/main.c b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/main.c index f93d32d90..713e63051 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/main.c +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_DYNAMIC_RAMBOX/main.c @@ -17,15 +17,11 @@ #include "ch.h" #include "hal.h" #include "sb.h" + #include "chprintf.h" - -//#include "rt_test_root.h" -//#include "oslib_test_root.h" - #include "nullstreams.h" #include "startup_defs.h" - #include "sdmon.h" /*===========================================================================*/ @@ -67,9 +63,6 @@ static const drv_streams_element_t sb1_streams[] = { /* Sandbox objects.*/ sb_class_t sbx1; -/* Privileged stacks for sandboxes.*/ -static SB_STACK(sbx1stk); - /* Arguments and environments for SB1.*/ static const char *sbx1_argv[] = { "msh", @@ -88,17 +81,16 @@ static const char *sbx1_envp[] = { /*===========================================================================*/ /* - * Green LED blinker thread, times are in milliseconds. + * LED blinker thread, times are in milliseconds. */ -static THD_WORKING_AREA(waThread1, 256); -static THD_FUNCTION(Thread1, arg) { +static THD_STACK(thd1_stack, 256); +static THD_FUNCTION(thd1_func, arg) { (void)arg; - chRegSetThreadName("blinker"); while (true) { palToggleLine(LINE_LED_GREEN); - chThdSleepMilliseconds(sdmon_ready ? 250 : 500); + chThdSleepMilliseconds(sdmon_ready ? 100 : 500); } } @@ -112,7 +104,7 @@ static void SBHandler(eventid_t id) { if (!sbIsThreadRunningX(&sbx1)) { msg_t msg = sbWait(&sbx1); - chprintf((BaseSequentialStream *)&SD2, "SB1 terminated (%08lx)\r\n", msg); + chprintf((BaseSequentialStream *)&SD2, "SBX1 terminated (%08lx)\r\n", msg); } } @@ -143,33 +135,26 @@ int main(void) { vfsInit(); sbHostInit(); - /* - * Starting a serial ports for I/O, initializing other streams too. - */ + /* Starting a serial ports for I/O, initializing other streams too.*/ sdStart(&SD2, NULL); nullObjectInit(&nullstream); - /* - * Activates the card insertion monitor. - */ + /* Activating the card insertion monitor.*/ sdmonInit(); - /* - * Creating a blinker thread. - */ - chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL); + /* Spawning a blinker thread.*/ + static thread_t thd1; + static const THD_DECL_STATIC(thd1_desc, "blinker", thd1_stack, + NORMALPRIO + 10, thd1_func, NULL, NULL); + chThdSpawnRunning(&thd1, &thd1_desc); - /* - * Initializing an overlay VFS object as a root on top of a FatFS driver. - * This is accessible from kernel space and covers the whole file system. - */ + /* Initializing an overlay VFS object as a root on top of a FatFS driver. + This is accessible from kernel space and covers the whole file system.*/ ffdrvObjectInit(&fatfs_driver); ovldrvObjectInit(&root_overlay_driver, (vfs_driver_c *)&fatfs_driver, NULL); - /* - * Initializing overlay drivers for the two sandbox roots. Those also use - * the FatFS driver but are restricted to "/sb1" and "/sb2" directories. - */ + /* Initializing overlay drivers for the two sandbox roots. Those also use + the FatFS driver but are restricted to "/sb1" and "/sb2" directories.*/ ovldrvObjectInit(&sb1_root_overlay_driver, (vfs_driver_c *)&fatfs_driver, "/sb1"); ret = ovldrvRegisterDriver(&sb1_root_overlay_driver, (vfs_driver_c *)stmdrvObjectInit(&sb1_dev_driver, @@ -179,33 +164,23 @@ int main(void) { chSysHalt("VFS"); } - /* - * Sandbox objects initialization. - */ + /* Sandbox object initialization.*/ sbObjectInit(&sbx1); - sbSetRegion(&sbx1, 0, STARTUP_RAM1_BASE, STARTUP_RAM1_SIZE, SB_REG_IS_CODE_AND_DATA); sbSetFileSystem(&sbx1, (vfs_driver_c *)&sb1_root_overlay_driver); - /* - * Listening to sandbox events. - */ + /* Listening to sandbox events.*/ chEvtRegister(&sb.termination_es, &elsb, (eventid_t)2); - /* - * Normal main() thread activity, in this demo it monitors the user button - * and checks for sandboxes state. - */ + /* Normal main() thread activity, (re)spawning sandboxed application.*/ while (true) { chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500))); if (sdmon_ready && !sbIsThreadRunningX(&sbx1)) { /* Small delay before relaunching.*/ - chThdSleepMilliseconds(1000); + chThdSleepMilliseconds(500); - /* - * Associating standard input, output and error to sandbox 1. - */ + /* Associating standard input, output and error to sandbox 1.*/ ret = vfsDrvOpen((vfs_driver_c *)&sb1_root_overlay_driver, "/dev/VSD1", VO_RDWR, &np); if (CH_RET_IS_ERROR(ret)) { @@ -217,10 +192,8 @@ int main(void) { sbRegisterDescriptor(&sbx1, STDERR_FILENO, (vfs_node_c *)roAddRef(np)); vfsClose(np); - /* - * Running the sandbox. - */ - ret = sbExecDynamic(&sbx1, NORMALPRIO-10, 8192, + /* Running the sandbox with 56kB of extra heap space.*/ + ret = sbExecDynamic(&sbx1, NORMALPRIO-10, 56*1024, "/bin/msh.elf", sbx1_argv, sbx1_envp); if (CH_RET_IS_ERROR(ret)) { chprintf((BaseSequentialStream *)&SD2, "SBX1 launch failed (%08lx)\r\n", ret); diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/cfg/chconf.h b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/cfg/chconf.h index 54f24de02..703413b1d 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/cfg/chconf.h +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/cfg/chconf.h @@ -836,7 +836,7 @@ /*===========================================================================*/ #define PORT_USE_SYSCALL TRUE -#define PORT_SWITCHED_REGIONS_NUMBER 2 +#define PORT_SWITCHED_REGIONS_NUMBER 1 #endif /* CHCONF_H */ diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/main.c b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/main.c index a8a4ef246..3b09dc7ba 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/main.c +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC_RAMBOX/main.c @@ -17,15 +17,11 @@ #include "ch.h" #include "hal.h" #include "sb.h" + #include "chprintf.h" - -//#include "rt_test_root.h" -//#include "oslib_test_root.h" - #include "nullstreams.h" #include "startup_defs.h" - #include "sdmon.h" /*===========================================================================*/ @@ -88,17 +84,16 @@ static const char *sbx1_envp[] = { /*===========================================================================*/ /* - * Green LED blinker thread, times are in milliseconds. + * LED blinker thread, times are in milliseconds. */ -static THD_WORKING_AREA(waThread1, 256); -static THD_FUNCTION(Thread1, arg) { +static THD_STACK(thd1_stack, 256); +static THD_FUNCTION(thd1_func, arg) { (void)arg; - chRegSetThreadName("blinker"); while (true) { palToggleLine(LINE_LED_GREEN); - chThdSleepMilliseconds(sdmon_ready ? 250 : 500); + chThdSleepMilliseconds(sdmon_ready ? 100 : 500); } } @@ -112,7 +107,7 @@ static void SBHandler(eventid_t id) { if (!sbIsThreadRunningX(&sbx1)) { msg_t msg = sbWait(&sbx1); - chprintf((BaseSequentialStream *)&SD2, "SB1 terminated (%08lx)\r\n", msg); + chprintf((BaseSequentialStream *)&SD2, "SBX1 terminated (%08lx)\r\n", msg); } } @@ -143,33 +138,26 @@ int main(void) { vfsInit(); sbHostInit(); - /* - * Starting a serial ports for I/O, initializing other streams too. - */ + /* Starting a serial ports for I/O, initializing other streams too.*/ sdStart(&SD2, NULL); nullObjectInit(&nullstream); - /* - * Activates the card insertion monitor. - */ + /* Activating the card insertion monitor.*/ sdmonInit(); - /* - * Creating a blinker thread. - */ - chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL); + /* Spawning a blinker thread.*/ + static thread_t thd1; + static const THD_DECL_STATIC(thd1_desc, "blinker", thd1_stack, + NORMALPRIO + 10, thd1_func, NULL, NULL); + chThdSpawnRunning(&thd1, &thd1_desc); - /* - * Initializing an overlay VFS object as a root on top of a FatFS driver. - * This is accessible from kernel space and covers the whole file system. - */ + /* Initializing an overlay VFS object as a root on top of a FatFS driver. + This is accessible from kernel space and covers the whole file system.*/ ffdrvObjectInit(&fatfs_driver); ovldrvObjectInit(&root_overlay_driver, (vfs_driver_c *)&fatfs_driver, NULL); - /* - * Initializing overlay drivers for the two sandbox roots. Those also use - * the FatFS driver but are restricted to "/sb1" and "/sb2" directories. - */ + /* Initializing overlay drivers for the two sandbox roots. Those also use + the FatFS driver but are restricted to "/sb1" and "/sb2" directories.*/ ovldrvObjectInit(&sb1_root_overlay_driver, (vfs_driver_c *)&fatfs_driver, "/sb1"); ret = ovldrvRegisterDriver(&sb1_root_overlay_driver, (vfs_driver_c *)stmdrvObjectInit(&sb1_dev_driver, @@ -179,33 +167,24 @@ int main(void) { chSysHalt("VFS"); } - /* - * Sandbox objects initialization. - */ + /* Sandbox object initialization.*/ sbObjectInit(&sbx1); sbSetRegion(&sbx1, 0, STARTUP_RAM1_BASE, STARTUP_RAM1_SIZE, SB_REG_IS_CODE_AND_DATA); sbSetFileSystem(&sbx1, (vfs_driver_c *)&sb1_root_overlay_driver); - /* - * Listening to sandbox events. - */ + /* Listening to sandbox events.*/ chEvtRegister(&sb.termination_es, &elsb, (eventid_t)2); - /* - * Normal main() thread activity, in this demo it monitors the user button - * and checks for sandboxes state. - */ + /* Normal main() thread activity, (re)spawning sandboxed application.*/ while (true) { chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500))); if (sdmon_ready && !sbIsThreadRunningX(&sbx1)) { /* Small delay before relaunching.*/ - chThdSleepMilliseconds(1000); + chThdSleepMilliseconds(500); - /* - * Associating standard input, output and error to sandbox 1. - */ + /* Associating standard input, output and error to sandbox 1.*/ ret = vfsDrvOpen((vfs_driver_c *)&sb1_root_overlay_driver, "/dev/VSD1", VO_RDWR, &np); if (CH_RET_IS_ERROR(ret)) { diff --git a/demos/STM32/RT-VFS-FATFS/main.c b/demos/STM32/RT-VFS-FATFS/main.c index e4811879b..5fcd92c06 100644 --- a/demos/STM32/RT-VFS-FATFS/main.c +++ b/demos/STM32/RT-VFS-FATFS/main.c @@ -272,7 +272,6 @@ static void ShellHandler(eventid_t id) { shelltp = NULL; } - /* * LED blinker thread, times are in milliseconds. */ @@ -315,9 +314,7 @@ int main(void) { /* Board-dependent setup code.*/ portab_setup(); - /* - * Spawning a blinker thread. - */ + /* Spawning a blinker thread.*/ static thread_t thd1; static const THD_DECL_STATIC(thd1_desc, "blinker", thd1_stack, NORMALPRIO + 10, thd1_func, NULL, NULL);