Skip to content

Commit a8fc837

Browse files
committed
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.
1 parent 5885a55 commit a8fc837

File tree

5 files changed

+60
-28
lines changed

5 files changed

+60
-28
lines changed

source/client_a.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ static const UvisorBoxAclItem acl[] = {
3030

3131
static void client_a_main(const void *);
3232

33-
/* Box configuration */
33+
/* Box configuration
34+
* This box has a smaller interrupt and main thread stack sizes as we do nothing
35+
* special in them. */
3436
UVISOR_BOX_NAMESPACE("client_a");
35-
UVISOR_BOX_HEAPSIZE(8192);
36-
UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
37-
UVISOR_BOX_CONFIG(secure_number_client_a, acl, UVISOR_BOX_STACK_SIZE, box_context);
37+
UVISOR_BOX_HEAPSIZE(3072);
38+
UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, 512);
39+
UVISOR_BOX_CONFIG(secure_number_client_a, acl, 512, box_context);
3840

3941
static uint32_t get_a_number()
4042
{
4143
/* Such random. Many secure. Much bits. Wow. */
4244
return (uvisor_ctx->number -= 500UL);
4345
}
4446

45-
static void box_async_runner(const void *)
47+
static void box_async_runner(void)
4648
{
4749
while (1) {
4850
uvisor_rpc_result_t result;
@@ -67,7 +69,7 @@ static void box_async_runner(const void *)
6769
}
6870
}
6971

70-
static void box_sync_runner(const void *)
72+
static void box_sync_runner(void)
7173
{
7274
while (1) {
7375
/* Synchronous access to the number. */
@@ -87,7 +89,11 @@ static void client_a_main(const void *)
8789
return;
8890
}
8991

92+
/* Create new threads. */
93+
/* Note: The stack must be at least 1kB since threads will use printf. */
9094
srand(uvisor_box_id_self());
91-
new Thread(box_sync_runner, NULL);
92-
new Thread(box_async_runner, NULL);
95+
Thread sync(osPriorityNormal, 1024, NULL);
96+
sync.start(box_sync_runner);
97+
Thread async(osPriorityNormal, 1024, NULL);
98+
async.start(box_async_runner);
9399
}

source/client_b.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ static const UvisorBoxAclItem acl[] = {
3131

3232
static void client_b_main(const void *);
3333

34-
/* Box configuration */
34+
/* Box configuration
35+
* This box has a smaller interrupt stack size as we do nothing special in it.
36+
* The main thread uses printf so it needs at least 1kB of stack. */
3537
UVISOR_BOX_NAMESPACE("client_b");
36-
UVISOR_BOX_HEAPSIZE(8192);
37-
UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
38-
UVISOR_BOX_CONFIG(secure_number_client_b, acl, UVISOR_BOX_STACK_SIZE, box_context);
38+
UVISOR_BOX_HEAPSIZE(3072);
39+
UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, 1024);
40+
UVISOR_BOX_CONFIG(secure_number_client_b, acl, 512, box_context);
3941

4042
static uint32_t get_a_number()
4143
{

source/main-hw.h

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
#ifndef __UVISOR_HELLOWORLD_MAIN_HW_H__
1818
#define __UVISOR_HELLOWORLD_MAIN_HW_H__
1919

20-
/* The vector containing the challenge is shared with the push-button ISR, so
21-
* that it can attempt to access it from an IRQ context. */
20+
extern DigitalOut led_red;
21+
extern DigitalOut led_green;
22+
extern DigitalOut led_blue;
23+
24+
#if defined(TARGET_K64F)
2225

2326
#define LED_ON false
2427
#define LED_OFF true
2528

26-
#define MAIN_LED LED_BLUE
27-
#define HALT_LED LED_RED
28-
29-
#define MAIN_BTN SW2
30-
#define MAIN_BTN_PUPD PullUp
31-
3229
#define MAIN_ACL(acl_list_name) \
3330
static const UvisorBoxAclItem acl_list_name[] = { \
3431
{SIM, sizeof(*SIM), UVISOR_TACLDEF_PERIPH}, \
@@ -48,8 +45,32 @@
4845
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
4946
}
5047

51-
extern DigitalOut led_red;
52-
extern DigitalOut led_green;
53-
extern DigitalOut led_blue;
48+
#elif defined(TARGET_DISCO_F429ZI)
49+
50+
#define LED_ON true
51+
#define LED_OFF false
52+
53+
#define MAIN_ACL(acl_list_name) \
54+
static const UvisorBoxAclItem acl_list_name[] = { \
55+
{GPIOA, sizeof(*GPIOA), UVISOR_TACLDEF_PERIPH}, \
56+
{GPIOB, sizeof(*GPIOB), UVISOR_TACLDEF_PERIPH}, \
57+
{GPIOC, sizeof(*GPIOC), UVISOR_TACLDEF_PERIPH}, \
58+
{GPIOD, sizeof(*GPIOD), UVISOR_TACLDEF_PERIPH}, \
59+
{GPIOE, sizeof(*GPIOE), UVISOR_TACLDEF_PERIPH}, \
60+
{RTC, sizeof(*RTC), UVISOR_TACLDEF_PERIPH}, \
61+
{TIM5, sizeof(*TIM5), UVISOR_TACLDEF_PERIPH}, \
62+
{USART1, sizeof(*USART1), UVISOR_TACLDEF_PERIPH}, \
63+
{I2C1, sizeof(*I2C1), UVISOR_TACLDEF_PERIPH}, \
64+
{SPI1, sizeof(*SPI1), UVISOR_TACLDEF_PERIPH}, \
65+
{RCC, sizeof(*RCC), UVISOR_TACLDEF_PERIPH}, \
66+
{FLASH, sizeof(*FLASH), UVISOR_TACLDEF_PERIPH}, \
67+
{PWR, sizeof(*PWR), UVISOR_TACLDEF_PERIPH}, \
68+
{EXTI, sizeof(*EXTI), UVISOR_TACLDEF_PERIPH}, \
69+
{GPIOG, sizeof(*GPIOG), UVISOR_TACLDEF_PERIPH}, \
70+
{SYSCFG, sizeof(*SYSCFG), UVISOR_TACLDEF_PERIPH}, \
71+
{(void *) 0x42000000, 0x01000000, UVISOR_TACLDEF_PERIPH}, /* FIXME */ \
72+
}
73+
74+
#endif /* Target-specific settings */
5475

5576
#endif /* __UVISOR_HELLOWORLD_MAIN_HW_H__ */

source/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static uint32_t get_a_number()
4646
return (number -= 400UL);
4747
}
4848

49-
static void main_async_runner(const void *)
49+
static void main_async_runner(void)
5050
{
5151
while (1) {
5252
uvisor_rpc_result_t result;
@@ -71,7 +71,7 @@ static void main_async_runner(const void *)
7171
}
7272
}
7373

74-
static void main_sync_runner(const void *)
74+
static void main_sync_runner(void)
7575
{
7676
while (1) {
7777
/* Synchronous access to the number. */
@@ -90,8 +90,11 @@ int main(void)
9090
led_green = LED_OFF;
9191

9292
/* Startup a few RPC runners. */
93-
Thread sync(main_sync_runner, NULL);
94-
Thread async(main_async_runner, NULL);
93+
/* Note: The stack must be at least 1kB since threads will use printf. */
94+
Thread sync(osPriorityNormal, 1024, NULL);
95+
sync.start(main_sync_runner);
96+
Thread async(osPriorityNormal, 1024, NULL);
97+
async.start(main_async_runner);
9598

9699
size_t count = 0;
97100

source/secure_number.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int set_number(uint32_t number);
3636

3737
/* Box configuration */
3838
UVISOR_BOX_NAMESPACE(NULL);
39-
UVISOR_BOX_HEAPSIZE(8192);
39+
UVISOR_BOX_HEAPSIZE(3072);
4040
UVISOR_BOX_MAIN(number_store_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
4141
UVISOR_BOX_CONFIG(box_number_store, acl, UVISOR_BOX_STACK_SIZE, box_context);
4242

0 commit comments

Comments
 (0)