From 6003782d71855e8eeddf5f395ad431584111b97c Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 2 Jan 2020 08:43:06 +0000 Subject: [PATCH] Improved sandbox demo. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13245 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- .../.cproject | 4 +- .../.project | 2 +- .../Makefile | 0 .../main.c | 4 +- .../sandbox.ld | 33 +++ .../.cproject | 54 +++++ .../.project | 33 +++ .../Makefile | 191 ++++++++++++++++++ .../RT-STM32L476-DISCOVERY-SB_CLIENT2/main.c | 50 +++++ .../sandbox.ld | 0 .../STM32L476xG_SB.ld | 10 +- ...RY-SB_HOST (OpenOCD, Flash and Run).launch | 104 +++++----- .../RT-STM32L476-DISCOVERY-SB_HOST/main.c | 119 ++++++++--- .../startup/ARMCMx-SB/compilers/GCC/crt0.S | 3 +- 14 files changed, 514 insertions(+), 93 deletions(-) rename demos/STM32/{RT-STM32L476-DISCOVERY-SB_CLIENT => RT-STM32L476-DISCOVERY-SB_CLIENT1}/.cproject (96%) rename demos/STM32/{RT-STM32L476-DISCOVERY-SB_CLIENT => RT-STM32L476-DISCOVERY-SB_CLIENT1}/.project (94%) rename demos/STM32/{RT-STM32L476-DISCOVERY-SB_CLIENT => RT-STM32L476-DISCOVERY-SB_CLIENT1}/Makefile (100%) rename demos/STM32/{RT-STM32L476-DISCOVERY-SB_CLIENT => RT-STM32L476-DISCOVERY-SB_CLIENT1}/main.c (87%) create mode 100644 demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/sandbox.ld create mode 100644 demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.cproject create mode 100644 demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.project create mode 100644 demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/Makefile create mode 100644 demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/main.c rename demos/STM32/{RT-STM32L476-DISCOVERY-SB_CLIENT => RT-STM32L476-DISCOVERY-SB_CLIENT2}/sandbox.ld (100%) diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/.cproject b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/.cproject similarity index 96% rename from demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/.cproject rename to demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/.cproject index a2ed5a478..32568e69b 100644 --- a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/.cproject +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/.cproject @@ -37,7 +37,7 @@ - + @@ -48,7 +48,7 @@ - + diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/.project b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/.project similarity index 94% rename from demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/.project rename to demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/.project index a84ee8b46..f662e30bf 100644 --- a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/.project +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/.project @@ -1,6 +1,6 @@ - RT-STM32L476-DISCOVERY-SB_CLIENT + RT-STM32L476-DISCOVERY-SB_CLIENT1 diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/Makefile b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/Makefile similarity index 100% rename from demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/Makefile rename to demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/Makefile diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/main.c b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/main.c similarity index 87% rename from demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/main.c rename to demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/main.c index 971985e65..d2a4880a3 100644 --- a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/main.c +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/main.c @@ -42,8 +42,8 @@ int main(void) { #endif while (true) { msg_t msg = sbMsgWait(); - printf("Hello World (%u)!!\r\n", (unsigned)msg); -// sbFileWrite(1U, (const uint8_t *)"Hello World!!\r\n", 15U); + printf("#1 Hello World (%u)!!\r\n", (unsigned)msg); +// sbFileWrite(1U, (const uint8_t *)"#1 Hello World!!\r\n", 15U); sbMsgReply(msg); // sbSleepMilliseconds(500); } diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/sandbox.ld b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/sandbox.ld new file mode 100644 index 000000000..d7d1f0d23 --- /dev/null +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT1/sandbox.ld @@ -0,0 +1,33 @@ +/* + 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. +*/ + +/* + * Sandbox memory setup. + */ +MEMORY +{ + flash0 (rx) : org = 0x080F0000, len = 32k + ram0 (wx) : org = 0x20016000, len = 4k +} + +/* Flash region to be used for exception vectors.*/ +REGION_ALIAS("CODE_SPACE", flash0); + +/* RAM region to be used for data.*/ +REGION_ALIAS("DATA_SPACE", ram0); + +/* Generic rules inclusion.*/ +INCLUDE rules.ld diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.cproject b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.cproject new file mode 100644 index 000000000..ea484a5c1 --- /dev/null +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.cproject @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.project b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.project new file mode 100644 index 000000000..9e2be71d1 --- /dev/null +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/.project @@ -0,0 +1,33 @@ + + + RT-STM32L476-DISCOVERY-SB_CLIENT2 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + sb + 2 + CHIBIOS/os/sb + + + diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/Makefile b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/Makefile new file mode 100644 index 000000000..b19f9ed5b --- /dev/null +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/Makefile @@ -0,0 +1,191 @@ +############################################################################## +# Build global options +# NOTE: Can be overridden externally. +# + +# Compiler options here. +ifeq ($(USE_OPT),) + USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 +endif + +# C specific options here (added to USE_OPT). +ifeq ($(USE_COPT),) + USE_COPT = +endif + +# C++ specific options here (added to USE_OPT). +ifeq ($(USE_CPPOPT),) + USE_CPPOPT = -fno-rtti +endif + +# Enable this if you want the linker to remove unused code and data. +ifeq ($(USE_LINK_GC),) + USE_LINK_GC = yes +endif + +# Linker extra options here. +ifeq ($(USE_LDOPT),) + USE_LDOPT = +endif + +# Enable this if you want link time optimizations (LTO). +ifeq ($(USE_LTO),) + USE_LTO = yes +endif + +# Enable this if you want to see the full log while compiling. +ifeq ($(USE_VERBOSE_COMPILE),) + USE_VERBOSE_COMPILE = no +endif + +# If enabled, this option makes the build process faster by not compiling +# modules not used in the current configuration. +ifeq ($(USE_SMART_BUILD),) + USE_SMART_BUILD = yes +endif + +# +# Build global options +############################################################################## + +############################################################################## +# Architecture or project specific options +# + +# Stack size to be allocated to the Cortex-M process stack. This stack is +# the stack used by the main() thread. +ifeq ($(USE_PROCESS_STACKSIZE),) + USE_PROCESS_STACKSIZE = 0x400 +endif + +# Stack size to the allocated to the Cortex-M main/exceptions stack. This +# stack is used for processing interrupts and exceptions. +ifeq ($(USE_EXCEPTIONS_STACKSIZE),) + USE_EXCEPTIONS_STACKSIZE = 0x400 +endif + +# Enables the use of FPU (no, softfp, hard). +ifeq ($(USE_FPU),) + USE_FPU = no +endif + +# FPU-related options. +ifeq ($(USE_FPU_OPT),) + USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16 +endif + +# +# Architecture or project specific options +############################################################################## + +############################################################################## +# Project, target, sources and paths +# + +# Define project name here +PROJECT = ch + +# Target settings. +MCU = cortex-m4 + +# Imported source files and paths. +CHIBIOS := ../../.. +CONFDIR := ./cfg +BUILDDIR := ./build +DEPDIR := ./.dep + +# Licensing files. +include $(CHIBIOS)/os/license/license.mk +# Startup files. +include $(CHIBIOS)/os/common/startup/ARMCMx-SB/compilers/GCC/mk/startup.mk +# HAL-OSAL files (optional). +#include $(CHIBIOS)/os/hal/hal.mk +#include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform.mk +#include $(CHIBIOS)/os/hal/boards/ST_STM32L476_DISCOVERY/board.mk +#include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk +# RTOS files (optional). +#include $(CHIBIOS)/os/rt/rt.mk +#include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk +include $(CHIBIOS)/os/sb/user/sbuser.mk +# Auto-build files in ./source recursively. +include $(CHIBIOS)/tools/mk/autobuild.mk +# Other files (optional). +#include $(CHIBIOS)/test/lib/test.mk +#include $(CHIBIOS)/test/rt/rt_test.mk +#include $(CHIBIOS)/test/oslib/oslib_test.mk + +# Define linker script file here. +LDSCRIPT= ./sandbox.ld + +# C sources that can be compiled in ARM or THUMB mode depending on the global +# setting. +CSRC = $(ALLCSRC) \ + $(TESTSRC) \ + $(CHIBIOS)/os/sb/various/syscalls.c \ + main.c + +# C++ sources that can be compiled in ARM or THUMB mode depending on the global +# setting. +CPPSRC = $(ALLCPPSRC) + +# List ASM source files here. +ASMSRC = $(ALLASMSRC) + +# List ASM with preprocessor source files here. +ASMXSRC = $(ALLXASMSRC) + +# Inclusion directories. +INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC) + +# Define C warning options here. +CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes + +# Define C++ warning options here. +CPPWARN = -Wall -Wextra -Wundef + +# +# Project, target, sources and paths +############################################################################## + +############################################################################## +# Start of user section +# + +# List all user C define here, like -D_DEBUG=1 +UDEFS = + +# Define ASM defines here +UADEFS = + +# List all user directories here +UINCDIR = + +# List the user directory to look for the libraries here +ULIBDIR = + +# List all user libraries here +ULIBS = + +# +# End of user section +############################################################################## + +############################################################################## +# Common rules +# + +RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk +include $(RULESPATH)/arm-none-eabi.mk +include $(RULESPATH)/rules.mk + +# +# Common rules +############################################################################## + +############################################################################## +# Custom rules +# + +# +# Custom rules +############################################################################## diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/main.c b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/main.c new file mode 100644 index 000000000..a36118cb4 --- /dev/null +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/main.c @@ -0,0 +1,50 @@ +/* + 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. +*/ + +#include +#include +#include +#include + +#include "sbuser.h" + +/* + * Application entry point. + */ +int main(void) { + + /* API layer initialization.*/ + sbApiInit(); + + /* + * Normal main() activity, in this demo it does nothing except + * sleeping in a loop. + */ +#if 0 + /* Test for exception on interrupt.*/ + asm volatile ("mov r0, #64"); + asm volatile ("mov sp, r0"); + while (true) { + } +#endif + while (true) { + msg_t msg = sbMsgWait(); + printf("#2 Hello World (%u)!!\r\n", (unsigned)msg); +// sbFileWrite(1U, (const uint8_t *)"#2 Hello World!!\r\n", 15U); + sbMsgReply(msg); +// sbSleepMilliseconds(500); + } +} diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/sandbox.ld b/demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/sandbox.ld similarity index 100% rename from demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT/sandbox.ld rename to demos/STM32/RT-STM32L476-DISCOVERY-SB_CLIENT2/sandbox.ld diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/STM32L476xG_SB.ld b/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/STM32L476xG_SB.ld index c90830ce6..16c6e1540 100644 --- a/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/STM32L476xG_SB.ld +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/STM32L476xG_SB.ld @@ -19,22 +19,22 @@ */ MEMORY { - flash0 (rx) : org = 0x08000000, len = 1M - 32k + flash0 (rx) : org = 0x08000000, len = 1M - 64k 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 = 0x08000000 + 1M - 32k, len = 32k + flash6 (rx) : org = 0x08000000 + 1M - 64k, len = 32k /* Flash for SB1.*/ + flash7 (rx) : org = 0x08000000 + 1M - 32k, len = 32k /* Flash for SB2.*/ ram0 (wx) : org = 0x20000000, len = 96k - 4k ram1 (wx) : org = 0x00000000, len = 0 ram2 (wx) : org = 0x00000000, len = 0 ram3 (wx) : org = 0x00000000, len = 0 ram4 (wx) : org = 0x10000000, len = 32k ram5 (wx) : org = 0x00000000, len = 0 - ram6 (wx) : org = 0x00000000, len = 0 - ram7 (wx) : org = 0x20000000 + 96k - 4k, len = 4k + ram6 (wx) : org = 0x20000000 + 96k - 8k, len = 4k /* RAM for SB1.*/ + ram7 (wx) : org = 0x20000000 + 96k - 4k, len = 4k /* RAM for SB2.*/ } /* For each data/text section two region are defined, a virtual region diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/debug/RT-STM32L476-DISCOVERY-SB_HOST (OpenOCD, Flash and Run).launch b/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/debug/RT-STM32L476-DISCOVERY-SB_HOST (OpenOCD, Flash and Run).launch index b7276b55a..f8a5b115b 100644 --- a/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/debug/RT-STM32L476-DISCOVERY-SB_HOST (OpenOCD, Flash and Run).launch +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/debug/RT-STM32L476-DISCOVERY-SB_HOST (OpenOCD, Flash and Run).launch @@ -1,52 +1,52 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/main.c b/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/main.c index 26dfb6945..068f5a1be 100644 --- a/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/main.c +++ b/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/main.c @@ -22,8 +22,39 @@ #include "chprintf.h" #include "sb.h" -/* SandBox object.*/ -sb_class_t sbx1; +/* Static memory areas used by sandboxes.*/ +extern uint32_t __flash6_base__, __flash6_end__, + __flash7_base__, __flash7_end__, + __ram6_base__, __ram6_end__, + __ram7_base__, __ram7_end__; + +/* Sandbox objects.*/ +sb_class_t sbx1, sbx2; + +/* Sandbox configurations.*/ +static const sb_config_t sb_config1 = { + .code_region = 0U, + .data_region = 1U, + .regions = { + {(uint32_t)&__flash6_base__, (uint32_t)&__flash6_end__, false}, + {(uint32_t)&__ram6_base__, (uint32_t)&__ram6_end__, true} + }, + .stdin_stream = (SandboxStream *)&SD2, + .stdout_stream = (SandboxStream *)&SD2, + .stderr_stream = (SandboxStream *)&SD2 +}; + +static const sb_config_t sb_config2 = { + .code_region = 0U, + .data_region = 1U, + .regions = { + {(uint32_t)&__flash7_base__, (uint32_t)&__flash7_end__, false}, + {(uint32_t)&__ram7_base__, (uint32_t)&__ram7_end__, true} + }, + .stdin_stream = (SandboxStream *)&SD2, + .stdout_stream = (SandboxStream *)&SD2, + .stderr_stream = (SandboxStream *)&SD2 +}; /* * LEDs blinker thread, times are in milliseconds. @@ -39,36 +70,24 @@ static THD_FUNCTION(Thread1, arg) { chThdSleepMilliseconds(50); palClearLine(LINE_LED_RED); chThdSleepMilliseconds(200); + (void) sbSendMessage(&sbx1, (msg_t)i); palSetLine(LINE_LED_GREEN); chThdSleepMilliseconds(50); palSetLine(LINE_LED_RED); chThdSleepMilliseconds(200); - (void) sbSendMessage(&sbx1, (msg_t)i); + (void) sbSendMessage(&sbx2, (msg_t)i); i++; } } /* - * Unprivileged thread. + * Unprivileged thread1. */ static THD_WORKING_AREA(waUnprivileged1, 128); static THD_FUNCTION(Unprivileged1, arg) { - extern uint32_t __flash7_base__, __flash7_end__, - __ram7_base__, __ram7_end__; - static const sb_config_t sb_config = { - .code_region = 0U, - .data_region = 1U, - .regions = { - {(uint32_t)&__flash7_base__, (uint32_t)&__flash7_end__, false}, - {(uint32_t)&__ram7_base__, (uint32_t)&__ram7_end__, true} - }, - .stdin_stream = (SandboxStream *)&SD2, - .stdout_stream = (SandboxStream *)&SD2, - .stderr_stream = (SandboxStream *)&SD2 - }; (void)arg; - chRegSetThreadName("unprivileged"); + chRegSetThreadName("unprivileged1"); /* Sandbox object initialization.*/ sbObjectInit(&sbx1); @@ -76,13 +95,13 @@ static THD_FUNCTION(Unprivileged1, arg) { /* Static MPU setup for the sandbox, both regions are used because in this demo it requires both a flash and a RAM regions.*/ mpuConfigureRegion(MPU_REGION_0, - sb_config.regions[0].base, + sb_config1.regions[0].base, MPU_RASR_ATTR_AP_RO_RO | MPU_RASR_ATTR_CACHEABLE_WT_NWA | MPU_RASR_SIZE_32K | MPU_RASR_ENABLE); mpuConfigureRegion(MPU_REGION_1, - sb_config.regions[1].base, + sb_config1.regions[1].base, MPU_RASR_ATTR_AP_RW_RW | MPU_RASR_ATTR_CACHEABLE_WB_WA | MPU_RASR_SIZE_4K | @@ -90,7 +109,42 @@ static THD_FUNCTION(Unprivileged1, arg) { /* This thread goes in the sandbox and is trapped there, it cannot return, only invoke the sandbox API.*/ - sbStart(&sbx1, &sb_config); + sbStart(&sbx1, &sb_config1); + + /* Function sbStart() only fails if the sandbox cannot be started + because code header problems.*/ +} + +/* + * Unprivileged thread2. + */ +static THD_WORKING_AREA(waUnprivileged2, 128); +static THD_FUNCTION(Unprivileged2, arg) { + + (void)arg; + chRegSetThreadName("unprivileged2"); + + /* Sandbox object initialization.*/ + sbObjectInit(&sbx2); + + /* Static MPU setup for the sandbox, both regions are used because in this + demo it requires both a flash and a RAM regions.*/ + mpuConfigureRegion(MPU_REGION_2, + sb_config2.regions[0].base, + MPU_RASR_ATTR_AP_RO_RO | + MPU_RASR_ATTR_CACHEABLE_WT_NWA | + MPU_RASR_SIZE_32K | + MPU_RASR_ENABLE); + mpuConfigureRegion(MPU_REGION_3, + sb_config2.regions[1].base, + MPU_RASR_ATTR_AP_RW_RW | + MPU_RASR_ATTR_CACHEABLE_WB_WA | + MPU_RASR_SIZE_4K | + MPU_RASR_ENABLE); + + /* This thread goes in the sandbox and is trapped there, it cannot + return, only invoke the sandbox API.*/ + sbStart(&sbx2, &sb_config2); /* Function sbStart() only fails if the sandbox cannot be started because code header problems.*/ @@ -100,8 +154,8 @@ static THD_FUNCTION(Unprivileged1, arg) { * Application entry point. */ int main(void) { - thread_t *tp; - msg_t msg; + thread_t *tp1, *tp2; +// msg_t msg; /* * System initializations. @@ -120,14 +174,19 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL); - /* Creating the unprivileged thread.*/ - chprintf((BaseSequentialStream *)&SD2, "Starting unprivileged thread\r\n"); - tp = chThdCreateStatic(waUnprivileged1, sizeof(waUnprivileged1), - NORMALPRIO - 10U, Unprivileged1, NULL); + /* Creating the unprivileged threads.*/ + chprintf((BaseSequentialStream *)&SD2, "Starting unprivileged thread 1\r\n"); + tp1 = chThdCreateStatic(waUnprivileged1, sizeof(waUnprivileged1), + NORMALPRIO - 10U, Unprivileged1, NULL); + chprintf((BaseSequentialStream *)&SD2, "Starting unprivileged thread 2\r\n"); + tp2 = chThdCreateStatic(waUnprivileged2, sizeof(waUnprivileged2), + NORMALPRIO - 10U, Unprivileged2, NULL); - /* Waiting for the unprivileged thread to exit or fail.*/ - msg = chThdWait(tp); - chprintf((BaseSequentialStream *)&SD2, "Exit code 0x%x\r\n", msg); + /* Waiting for the unprivileged threads to exit or fail.*/ + (void)tp1; + (void)tp2; +// msg = chThdWait(tp1); +// chprintf((BaseSequentialStream *)&SD2, "Exit code 0x%x\r\n", msg); /* Normal main() thread activity, in this demo it does nothing except sleeping in a loop and check the button state.*/ diff --git a/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S b/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S index 3f8692899..0e27ca88c 100644 --- a/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S +++ b/os/common/startup/ARMCMx-SB/compilers/GCC/crt0.S @@ -90,7 +90,6 @@ .cpu cortex-m3 .thumb - .text .section .sandbox, "ax" .align 4 @@ -99,7 +98,9 @@ _sandbox: .long 0xFE9154C0 .long 0x0C4519EF .long 16 .long 0 + b _crt0_entry + .text /* * CRT0 entry point. */