From 4988a7322943721899d50da017be700d67bb4573 Mon Sep 17 00:00:00 2001 From: Alessandro Angelino Date: Tue, 6 Dec 2016 10:15:09 +0000 Subject: [PATCH] Add support for the DISCO_F429ZI target This commit includes: * Reduce stack and heap size for all boxes, where necessary and possible (printf used in threads is a constraint). * Use new Thread APIs. * Add ACLs and configurations for the DISCO_F429ZI target. --- source/client_a.cpp | 22 ++++++++++++-------- source/client_b.cpp | 10 ++++++---- source/main-hw.h | 43 ++++++++++++++++++++++++++++++---------- source/main.cpp | 11 ++++++---- source/secure_number.cpp | 2 +- 5 files changed, 60 insertions(+), 28 deletions(-) diff --git a/source/client_a.cpp b/source/client_a.cpp index fa7622a..fd7f5d6 100644 --- a/source/client_a.cpp +++ b/source/client_a.cpp @@ -30,11 +30,13 @@ static const UvisorBoxAclItem acl[] = { static void client_a_main(const void *); -/* Box configuration */ +/* Box configuration + * This box has a smaller interrupt and main thread stack sizes as we do nothing + * special in them. */ UVISOR_BOX_NAMESPACE("client_a"); -UVISOR_BOX_HEAPSIZE(8192); -UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE); -UVISOR_BOX_CONFIG(secure_number_client_a, acl, UVISOR_BOX_STACK_SIZE, box_context); +UVISOR_BOX_HEAPSIZE(3072); +UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, 512); +UVISOR_BOX_CONFIG(secure_number_client_a, acl, 512, box_context); static uint32_t get_a_number() { @@ -42,7 +44,7 @@ static uint32_t get_a_number() return (uvisor_ctx->number -= 500UL); } -static void box_async_runner(const void *) +static void box_async_runner(void) { while (1) { uvisor_rpc_result_t result; @@ -71,7 +73,7 @@ static void box_async_runner(const void *) } } -static void box_sync_runner(const void *) +static void box_sync_runner(void) { while (1) { /* Synchronous access to the number. */ @@ -91,7 +93,11 @@ static void client_a_main(const void *) return; } + /* Create new threads. */ + /* Note: The stack must be at least 1kB since threads will use printf. */ srand(uvisor_box_id_self()); - new Thread(box_sync_runner, NULL); - new Thread(box_async_runner, NULL); + Thread sync(osPriorityNormal, 1024, NULL); + sync.start(box_sync_runner); + Thread async(osPriorityNormal, 1024, NULL); + async.start(box_async_runner); } diff --git a/source/client_b.cpp b/source/client_b.cpp index f981fdf..2b0f5e4 100644 --- a/source/client_b.cpp +++ b/source/client_b.cpp @@ -31,11 +31,13 @@ static const UvisorBoxAclItem acl[] = { static void client_b_main(const void *); -/* Box configuration */ +/* Box configuration + * This box has a smaller interrupt stack size as we do nothing special in it. + * The main thread uses printf so it needs at least 1kB of stack. */ UVISOR_BOX_NAMESPACE("client_b"); -UVISOR_BOX_HEAPSIZE(8192); -UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE); -UVISOR_BOX_CONFIG(secure_number_client_b, acl, UVISOR_BOX_STACK_SIZE, box_context); +UVISOR_BOX_HEAPSIZE(3072); +UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, 1024); +UVISOR_BOX_CONFIG(secure_number_client_b, acl, 512, box_context); static uint32_t get_a_number() { diff --git a/source/main-hw.h b/source/main-hw.h index ea4bb72..884f29a 100644 --- a/source/main-hw.h +++ b/source/main-hw.h @@ -17,18 +17,15 @@ #ifndef __UVISOR_HELLOWORLD_MAIN_HW_H__ #define __UVISOR_HELLOWORLD_MAIN_HW_H__ -/* The vector containing the challenge is shared with the push-button ISR, so - * that it can attempt to access it from an IRQ context. */ +extern DigitalOut led_red; +extern DigitalOut led_green; +extern DigitalOut led_blue; + +#if defined(TARGET_K64F) #define LED_ON false #define LED_OFF true -#define MAIN_LED LED_BLUE -#define HALT_LED LED_RED - -#define MAIN_BTN SW2 -#define MAIN_BTN_PUPD PullUp - #define MAIN_ACL(acl_list_name) \ static const UvisorBoxAclItem acl_list_name[] = { \ {SIM, sizeof(*SIM), UVISOR_TACLDEF_PERIPH}, \ @@ -48,8 +45,32 @@ {SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \ } -extern DigitalOut led_red; -extern DigitalOut led_green; -extern DigitalOut led_blue; +#elif defined(TARGET_DISCO_F429ZI) + +#define LED_ON true +#define LED_OFF false + +#define MAIN_ACL(acl_list_name) \ + static const UvisorBoxAclItem acl_list_name[] = { \ + {GPIOA, sizeof(*GPIOA), UVISOR_TACLDEF_PERIPH}, \ + {GPIOB, sizeof(*GPIOB), UVISOR_TACLDEF_PERIPH}, \ + {GPIOC, sizeof(*GPIOC), UVISOR_TACLDEF_PERIPH}, \ + {GPIOD, sizeof(*GPIOD), UVISOR_TACLDEF_PERIPH}, \ + {GPIOE, sizeof(*GPIOE), UVISOR_TACLDEF_PERIPH}, \ + {RTC, sizeof(*RTC), UVISOR_TACLDEF_PERIPH}, \ + {TIM5, sizeof(*TIM5), UVISOR_TACLDEF_PERIPH}, \ + {USART1, sizeof(*USART1), UVISOR_TACLDEF_PERIPH}, \ + {I2C1, sizeof(*I2C1), UVISOR_TACLDEF_PERIPH}, \ + {SPI1, sizeof(*SPI1), UVISOR_TACLDEF_PERIPH}, \ + {RCC, sizeof(*RCC), UVISOR_TACLDEF_PERIPH}, \ + {FLASH, sizeof(*FLASH), UVISOR_TACLDEF_PERIPH}, \ + {PWR, sizeof(*PWR), UVISOR_TACLDEF_PERIPH}, \ + {EXTI, sizeof(*EXTI), UVISOR_TACLDEF_PERIPH}, \ + {GPIOG, sizeof(*GPIOG), UVISOR_TACLDEF_PERIPH}, \ + {SYSCFG, sizeof(*SYSCFG), UVISOR_TACLDEF_PERIPH}, \ + {(void *) 0x42000000, 0x01000000, UVISOR_TACLDEF_PERIPH}, /* FIXME */ \ + } + +#endif /* Target-specific settings */ #endif /* __UVISOR_HELLOWORLD_MAIN_HW_H__ */ diff --git a/source/main.cpp b/source/main.cpp index ebd80fd..515dc53 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -46,7 +46,7 @@ static uint32_t get_a_number() return (number -= 400UL); } -static void main_async_runner(const void *) +static void main_async_runner(void) { while (1) { uvisor_rpc_result_t result; @@ -75,7 +75,7 @@ static void main_async_runner(const void *) } } -static void main_sync_runner(const void *) +static void main_sync_runner(void) { while (1) { /* Synchronous access to the number. */ @@ -94,8 +94,11 @@ int main(void) led_green = LED_OFF; /* Startup a few RPC runners. */ - Thread sync(main_sync_runner, NULL); - Thread async(main_async_runner, NULL); + /* Note: The stack must be at least 1kB since threads will use printf. */ + Thread sync(osPriorityNormal, 1024, NULL); + sync.start(main_sync_runner); + Thread async(osPriorityNormal, 1024, NULL); + async.start(main_async_runner); size_t count = 0; diff --git a/source/secure_number.cpp b/source/secure_number.cpp index 5cecf16..8f7cf01 100644 --- a/source/secure_number.cpp +++ b/source/secure_number.cpp @@ -36,7 +36,7 @@ static int set_number(uint32_t number); /* Box configuration */ UVISOR_BOX_NAMESPACE(NULL); -UVISOR_BOX_HEAPSIZE(8192); +UVISOR_BOX_HEAPSIZE(3072); UVISOR_BOX_MAIN(number_store_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE); UVISOR_BOX_CONFIG(box_number_store, acl, UVISOR_BOX_STACK_SIZE, box_context);