Skip to content

Add support for the DISCO_F429ZI target #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Misc hidden files
.DS_Store
.build
gdb.script
*.sw*

# mbed files and folders
.build
BUILD
mbed-os
mbed-os/*
mbed_settings.py*
/mbed-os/
/firmware.*
/debug.elf
.mbed

# Custom Makefile temp files
gdb.script
firmware.*
debug.elf
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ This is a simple example to show how to write a uVisor-secured threaded applicat

Supported devices:

| Target | Toolchain | Public box LED | Secure box LED | User button | Baud rate |
|--------|-----------|----------------|----------------|-------------|-----------|
| `K64F` | `GCC_ARM` | `LED_BLUE` | `LED_RED` | `SW2` | 9600 |
| Target | Toolchain | Public box LED | Secure box LED | User button | Baud rate |
|----------------|-----------|----------------|----------------|---------------|-----------|
| `K64F` | `GCC_ARM` | `LED_BLUE` | `LED_RED` | `SW2` | 9600 |
| `DISCO_F429ZI` | `GCC_ARM` | `LED1` | `LED2` | `USER_BUTTON` | 9600 |

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).

## Quickstart

The instructions here are specific to the `K64F` target, but can be easily extended to other supported targets as well.

For a release build, please enter:

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

```
**** IRQ blinky uvisor-rtos example *****
**** IRQ blinky uVisor example *****
Main loop count: 0
Main loop count: 1
Main loop count: 2
Main loop count: 3

Pressed SW2, printing from interrupt - LED changed to 0
Pressed switch, printing from interrupt - LED changed to 0

Main loop count: 4
Main loop count: 5
Expand Down
2 changes: 1 addition & 1 deletion mbed_app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"target_overrides": {
"K64F": {
"*": {
"target.features_add": ["UVISOR"],
"target.extra_labels_add": ["UVISOR_SUPPORTED"]
}
Expand Down
57 changes: 29 additions & 28 deletions source/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,54 @@ static const UvisorBoxAclItem acl[] = {

static void my_box_main(const void *);

/* Box configuration
* We need 1kB of stack both in the main and interrupt threads as both of them
* use printf. */
UVISOR_BOX_NAMESPACE(NULL);
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_MAIN(my_box_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(my_box, acl, UVISOR_BOX_STACK_SIZE, my_box_context);
UVISOR_BOX_HEAPSIZE(3072);
UVISOR_BOX_MAIN(my_box_main, osPriorityNormal, 1024);
UVISOR_BOX_CONFIG(my_box, acl, 1024, my_box_context);

static void my_box_switch_irq(void)
{
/* flip LED state */
/* Flip LED state. */
*uvisor_ctx->led = !*uvisor_ctx->led;

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

static void my_box_main(const void *)
{
/* allocate serial port to ensure that code in this secure box
* won't touch handle in the default security context when printing */
RawSerial *pc;
if(!(pc = new RawSerial(USBTX, USBRX)))
/* Allocate the serial port to ensure that code in this secure box won't
* touch handles in the default security context when printing. */
RawSerial * pc;
if (!(pc = new RawSerial(USBTX, USBRX))) {
return;
/* remember serial driver for IRQ routine */
}

/* Remember serial driver for IRQ routine. */
uvisor_ctx->pc = pc;

/* allocate a box-specific LED */
if(!(uvisor_ctx->led = new DigitalOut(SECURE_LED)))
pc->printf("ERROR: failed to allocate memories for LED\n");
else
{
/* turn LED off by default */
/* Allocate a box-specific LED. */
if (!(uvisor_ctx->led = new DigitalOut(SECURE_LED))) {
pc->printf("ERROR: failed to allocate memories for LED\r\n");
} else {
/* Turn LED off by default */
*uvisor_ctx->led = LED_OFF;

/* allocate a box-specific switch handler */
if(!(uvisor_ctx->sw = new InterruptIn(SW2)))
pc->printf("ERROR: failed to allocate memories for SW1\n");
else
{
/* register handler for switch SW1 */
uvisor_ctx->sw->mode(PullUp);
/* Allocate a box-specific switch handler. */
if (!(uvisor_ctx->sw = new InterruptIn(SECURE_SWITCH))) {
pc->printf("ERROR: failed to allocate memories for switch\r\n");
} else {
/* Register handler for switch. */
uvisor_ctx->sw->mode(SECURE_SWITCH_PULL);
uvisor_ctx->sw->fall(my_box_switch_irq);

/* no problem to return here as everything is initialized */
/* No problem to return here as everything is initialized. */
return;
}

delete uvisor_ctx->led;
}
delete pc;
Expand Down
53 changes: 43 additions & 10 deletions source/main-hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
#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. */
#if defined(TARGET_K64F)

#define LED_ON false
#define LED_OFF true

#define MAIN_LED LED_BLUE
#define SECURE_LED LED_RED

#define MAIN_BTN SW2
#define MAIN_BTN_PUPD PullUp
#define MAIN_LED LED1
#define SECURE_LED LED2
#define LED_ON false
#define LED_OFF true
#define SECURE_SWITCH SW2
#define SECURE_SWITCH_PULL PullUp

#define MAIN_ACL(acl_list_name) \
static const UvisorBoxAclItem acl_list_name[] = { \
Expand All @@ -48,4 +45,40 @@
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
}

#elif defined(TARGET_DISCO_F429ZI)

#define MAIN_LED LED1
#define SECURE_LED LED2
#define LED_ON true
#define LED_OFF false
#define SECURE_SWITCH USER_BUTTON
#define SECURE_SWITCH_PULL PullDown

#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 */ \
}

#else /* Target-specific settings */

#error "Unsupported target. Checkout the README.md file for the list of supported targets for this app."

#endif /* Target-specific settings */

#endif /* __UVISOR_HELLOWORLD_MAIN_HW_H__ */
13 changes: 6 additions & 7 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ MAIN_ACL(g_main_acl);

/* Enable uVisor. */
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_main_acl);
UVISOR_SET_PAGE_HEAP(8*1024, 5);
UVISOR_SET_PAGE_HEAP(8 * 1024, 5);

int main(void)
{
DigitalOut led1(MAIN_LED);
DigitalOut led(MAIN_LED);

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

size_t count = 0;

while (1)
{
while (1) {
printf("Main loop count: %d\r\n", count++);
led1 = !led1;
led = !led;

/* blink once per second */
/* Blink once per second. */
Thread::wait(500);
}

Expand Down
2 changes: 1 addition & 1 deletion test/log.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

**** IRQ blinky uvisor-rtos example *****
**** IRQ blinky uVisor example *****
Main loop count: 0
Main loop count: 1
Main loop count: 2
Expand Down