Skip to content

Commit 95fafb9

Browse files
authored
Merge pull request #8 from AlessandroA/stm32f4_support
Add support for the DISCO_F429ZI target
2 parents 24b2ebb + 223f44b commit 95fafb9

File tree

7 files changed

+101
-57
lines changed

7 files changed

+101
-57
lines changed

.gitignore

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
# Misc hidden files
12
.DS_Store
2-
.build
3-
gdb.script
43
*.sw*
4+
5+
# mbed files and folders
6+
.build
7+
BUILD
8+
mbed-os
9+
mbed-os/*
510
mbed_settings.py*
6-
/mbed-os/
7-
/firmware.*
8-
/debug.elf
11+
.mbed
12+
13+
# Custom Makefile temp files
14+
gdb.script
15+
firmware.*
16+
debug.elf

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ This is a simple example to show how to write a uVisor-secured threaded applicat
44

55
Supported devices:
66

7-
| Target | Toolchain | Public box LED | Secure box LED | User button | Baud rate |
8-
|--------|-----------|----------------|----------------|-------------|-----------|
9-
| `K64F` | `GCC_ARM` | `LED_BLUE` | `LED_RED` | `SW2` | 9600 |
7+
| Target | Toolchain | Public box LED | Secure box LED | User button | Baud rate |
8+
|----------------|-----------|----------------|----------------|---------------|-----------|
9+
| `K64F` | `GCC_ARM` | `LED_BLUE` | `LED_RED` | `SW2` | 9600 |
10+
| `DISCO_F429ZI` | `GCC_ARM` | `LED1` | `LED2` | `USER_BUTTON` | 9600 |
1011

1112
Latest release: [mbed-os-5.3.0](https://github.com/ARMmbed/mbed-os-example-uvisor/releases/tag/mbed-os-5.3.0). Tested with [mbed-cli v1.0.0](https://github.com/ARMmbed/mbed-cli/releases/tag/1.0.0).
1213

1314
## Quickstart
1415

16+
The instructions here are specific to the `K64F` target, but can be easily extended to other supported targets as well.
17+
1518
For a release build, please enter:
1619

1720
```bash
@@ -31,13 +34,13 @@ $ screen /dev/tty.usbmodem1422 9600
3134
You will see an output similar to the following one (assuming you press the user button after 4 loops count):
3235

3336
```
34-
**** IRQ blinky uvisor-rtos example *****
37+
**** IRQ blinky uVisor example *****
3538
Main loop count: 0
3639
Main loop count: 1
3740
Main loop count: 2
3841
Main loop count: 3
3942
40-
Pressed SW2, printing from interrupt - LED changed to 0
43+
Pressed switch, printing from interrupt - LED changed to 0
4144
4245
Main loop count: 4
4346
Main loop count: 5

mbed_app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"target_overrides": {
3-
"K64F": {
3+
"*": {
44
"target.features_add": ["UVISOR"],
55
"target.extra_labels_add": ["UVISOR_SUPPORTED"]
66
}

source/led.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,54 @@ static const UvisorBoxAclItem acl[] = {
2929

3030
static void my_box_main(const void *);
3131

32+
/* Box configuration
33+
* We need 1kB of stack both in the main and interrupt threads as both of them
34+
* use printf. */
3235
UVISOR_BOX_NAMESPACE(NULL);
33-
UVISOR_BOX_HEAPSIZE(8192);
34-
UVISOR_BOX_MAIN(my_box_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
35-
UVISOR_BOX_CONFIG(my_box, acl, UVISOR_BOX_STACK_SIZE, my_box_context);
36+
UVISOR_BOX_HEAPSIZE(3072);
37+
UVISOR_BOX_MAIN(my_box_main, osPriorityNormal, 1024);
38+
UVISOR_BOX_CONFIG(my_box, acl, 1024, my_box_context);
3639

3740
static void my_box_switch_irq(void)
3841
{
39-
/* flip LED state */
42+
/* Flip LED state. */
4043
*uvisor_ctx->led = !*uvisor_ctx->led;
4144

42-
/* print LED state on serial port */
43-
uvisor_ctx->pc->printf(
44-
"\nPressed SW2, printing from interrupt - LED changed to %i\n\n",
45-
(int)(*uvisor_ctx->led));
45+
/* Print LED state on serial port. */
46+
uvisor_ctx->pc->printf("\r\nPressed switch, printing from interrupt - LED changed to %i\r\n\r\n",
47+
(int) (*uvisor_ctx->led));
4648
}
4749

4850
static void my_box_main(const void *)
4951
{
50-
/* allocate serial port to ensure that code in this secure box
51-
* won't touch handle in the default security context when printing */
52-
RawSerial *pc;
53-
if(!(pc = new RawSerial(USBTX, USBRX)))
52+
/* Allocate the serial port to ensure that code in this secure box won't
53+
* touch handles in the default security context when printing. */
54+
RawSerial * pc;
55+
if (!(pc = new RawSerial(USBTX, USBRX))) {
5456
return;
55-
/* remember serial driver for IRQ routine */
57+
}
58+
59+
/* Remember serial driver for IRQ routine. */
5660
uvisor_ctx->pc = pc;
5761

58-
/* allocate a box-specific LED */
59-
if(!(uvisor_ctx->led = new DigitalOut(SECURE_LED)))
60-
pc->printf("ERROR: failed to allocate memories for LED\n");
61-
else
62-
{
63-
/* turn LED off by default */
62+
/* Allocate a box-specific LED. */
63+
if (!(uvisor_ctx->led = new DigitalOut(SECURE_LED))) {
64+
pc->printf("ERROR: failed to allocate memories for LED\r\n");
65+
} else {
66+
/* Turn LED off by default */
6467
*uvisor_ctx->led = LED_OFF;
6568

66-
/* allocate a box-specific switch handler */
67-
if(!(uvisor_ctx->sw = new InterruptIn(SW2)))
68-
pc->printf("ERROR: failed to allocate memories for SW1\n");
69-
else
70-
{
71-
/* register handler for switch SW1 */
72-
uvisor_ctx->sw->mode(PullUp);
69+
/* Allocate a box-specific switch handler. */
70+
if (!(uvisor_ctx->sw = new InterruptIn(SECURE_SWITCH))) {
71+
pc->printf("ERROR: failed to allocate memories for switch\r\n");
72+
} else {
73+
/* Register handler for switch. */
74+
uvisor_ctx->sw->mode(SECURE_SWITCH_PULL);
7375
uvisor_ctx->sw->fall(my_box_switch_irq);
7476

75-
/* no problem to return here as everything is initialized */
77+
/* No problem to return here as everything is initialized. */
7678
return;
7779
}
78-
7980
delete uvisor_ctx->led;
8081
}
8182
delete pc;

source/main-hw.h

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@
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+
#if defined(TARGET_K64F)
2221

23-
#define LED_ON false
24-
#define LED_OFF true
25-
26-
#define MAIN_LED LED_BLUE
27-
#define SECURE_LED LED_RED
28-
29-
#define MAIN_BTN SW2
30-
#define MAIN_BTN_PUPD PullUp
22+
#define MAIN_LED LED1
23+
#define SECURE_LED LED2
24+
#define LED_ON false
25+
#define LED_OFF true
26+
#define SECURE_SWITCH SW2
27+
#define SECURE_SWITCH_PULL PullUp
3128

3229
#define MAIN_ACL(acl_list_name) \
3330
static const UvisorBoxAclItem acl_list_name[] = { \
@@ -48,4 +45,40 @@
4845
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
4946
}
5047

48+
#elif defined(TARGET_DISCO_F429ZI)
49+
50+
#define MAIN_LED LED1
51+
#define SECURE_LED LED2
52+
#define LED_ON true
53+
#define LED_OFF false
54+
#define SECURE_SWITCH USER_BUTTON
55+
#define SECURE_SWITCH_PULL PullDown
56+
57+
#define MAIN_ACL(acl_list_name) \
58+
static const UvisorBoxAclItem acl_list_name[] = { \
59+
{GPIOA, sizeof(*GPIOA), UVISOR_TACLDEF_PERIPH}, \
60+
{GPIOB, sizeof(*GPIOB), UVISOR_TACLDEF_PERIPH}, \
61+
{GPIOC, sizeof(*GPIOC), UVISOR_TACLDEF_PERIPH}, \
62+
{GPIOD, sizeof(*GPIOD), UVISOR_TACLDEF_PERIPH}, \
63+
{GPIOE, sizeof(*GPIOE), UVISOR_TACLDEF_PERIPH}, \
64+
{RTC, sizeof(*RTC), UVISOR_TACLDEF_PERIPH}, \
65+
{TIM5, sizeof(*TIM5), UVISOR_TACLDEF_PERIPH}, \
66+
{USART1, sizeof(*USART1), UVISOR_TACLDEF_PERIPH}, \
67+
{I2C1, sizeof(*I2C1), UVISOR_TACLDEF_PERIPH}, \
68+
{SPI1, sizeof(*SPI1), UVISOR_TACLDEF_PERIPH}, \
69+
{RCC, sizeof(*RCC), UVISOR_TACLDEF_PERIPH}, \
70+
{FLASH, sizeof(*FLASH), UVISOR_TACLDEF_PERIPH}, \
71+
{PWR, sizeof(*PWR), UVISOR_TACLDEF_PERIPH}, \
72+
{EXTI, sizeof(*EXTI), UVISOR_TACLDEF_PERIPH}, \
73+
{GPIOG, sizeof(*GPIOG), UVISOR_TACLDEF_PERIPH}, \
74+
{SYSCFG, sizeof(*SYSCFG), UVISOR_TACLDEF_PERIPH}, \
75+
{(void *) 0x42000000, 0x01000000, UVISOR_TACLDEF_PERIPH}, /* FIXME */ \
76+
}
77+
78+
#else /* Target-specific settings */
79+
80+
#error "Unsupported target. Checkout the README.md file for the list of supported targets for this app."
81+
82+
#endif /* Target-specific settings */
83+
5184
#endif /* __UVISOR_HELLOWORLD_MAIN_HW_H__ */

source/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@ MAIN_ACL(g_main_acl);
2323

2424
/* Enable uVisor. */
2525
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_main_acl);
26-
UVISOR_SET_PAGE_HEAP(8*1024, 5);
26+
UVISOR_SET_PAGE_HEAP(8 * 1024, 5);
2727

2828
int main(void)
2929
{
30-
DigitalOut led1(MAIN_LED);
30+
DigitalOut led(MAIN_LED);
3131

32-
printf("\r\n***** IRQ blinky uvisor-rtos example *****\r\n");
32+
printf("\r\n***** IRQ blinky uVisor example *****\r\n");
3333

3434
size_t count = 0;
3535

36-
while (1)
37-
{
36+
while (1) {
3837
printf("Main loop count: %d\r\n", count++);
39-
led1 = !led1;
38+
led = !led;
4039

41-
/* blink once per second */
40+
/* Blink once per second. */
4241
Thread::wait(500);
4342
}
4443

test/log.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
**** IRQ blinky uvisor-rtos example *****
2+
**** IRQ blinky uVisor example *****
33
Main loop count: 0
44
Main loop count: 1
55
Main loop count: 2

0 commit comments

Comments
 (0)