Skip to content
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

Add support for the DISCO_F429ZI target #23

Closed
wants to merge 7 commits into from
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $ screen /dev/tty.usbmodem1422 9600
You will see an output similar to the following one:

```
***** threaded blinky uvisor-rtos example *****
***** Threaded blinky uVisor example *****
Main loop count: 0
Main loop count: 1
Main loop count: 2
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
15 changes: 9 additions & 6 deletions source/led1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ static const UvisorBoxAclItem acl[] = {

static void led1_main(const void *);

/* Box configuration
* We do not need large stacks in either the main nor the interrupt thread, as
* we do not do anything special in them. */
UVISOR_BOX_NAMESPACE(NULL);
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_MAIN(led1_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(box_led1, acl, UVISOR_BOX_STACK_SIZE, box_context);
UVISOR_BOX_HEAPSIZE(3 * 1024);
UVISOR_BOX_MAIN(led1_main, osPriorityNormal, 512);
UVISOR_BOX_CONFIG(box_led1, acl, 512, box_context);

static void led1_main(const void *)
{
DigitalOut led1(LED1);
led1 = LED_OFF;
const uint32_t kB = 1024;

SecureAllocator alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);

while (1) {
static const size_t size = 500;
static const size_t size = 50;
uint16_t seed = (size << 8) | (uvisor_ctx->heartbeat & 0xFF);

led1 = !led1;
++uvisor_ctx->heartbeat;
alloc_fill_wait_verify_free(size, seed, 211);
specific_alloc_fill_wait_verify_free(alloc, 5*kB, seed, 107);
specific_alloc_fill_wait_verify_free(alloc, 5 * kB, seed, 107);
}
}
21 changes: 12 additions & 9 deletions source/led2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ static const UvisorBoxAclItem acl[] = {

static void led2_main(const void *);

/* Box configuration
* We do not need large stacks in either the main nor the interrupt thread, as
* we do not do anything special in them. */
UVISOR_BOX_NAMESPACE(NULL);
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_MAIN(led2_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(box_led2, acl, UVISOR_BOX_STACK_SIZE, box_context);
UVISOR_BOX_HEAPSIZE(3 * 1024);
UVISOR_BOX_MAIN(led2_main, osPriorityNormal, 512);
UVISOR_BOX_CONFIG(box_led2, acl, 512, box_context);

static void led2_main(const void *)
{
Expand All @@ -33,28 +36,28 @@ static void led2_main(const void *)
* page heap!
*/
/* Allocate one page. */
alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
/* Allocate another page. */
SecureAllocator alloc2 = secure_allocator_create_with_pages(4*kB, 1*kB);
SecureAllocator alloc2 = secure_allocator_create_with_pages(4 * kB, 1 * kB);
/* Deallocate alloc1 page, creating a hole. */
secure_allocator_destroy(alloc);
/* Allocate two pages. */
alloc = secure_allocator_create_with_pages(uvisor_get_page_size() + 3*kB, 6*kB);
alloc = secure_allocator_create_with_pages(uvisor_get_page_size() + 3 * kB, 6 * kB);
/* Deallocate alloc2 page, creating another hole. */
secure_allocator_destroy(alloc2);

while (1) {
static const size_t size = 300;
static const size_t size = 30;
uint16_t seed = (size << 8) | (uvisor_ctx->heartbeat & 0xFF);

led2 = !led2;
++uvisor_ctx->heartbeat;
alloc_fill_wait_verify_free(size, seed, 311);

/* Allocate in first page */
specific_alloc_fill_wait_verify_free(alloc, 6*kB, seed, 0);
specific_alloc_fill_wait_verify_free(alloc, 6 * kB, seed, 0);

/* Allocate in second page */
specific_alloc_fill_wait_verify_free(alloc, 6*kB, seed, 101);
specific_alloc_fill_wait_verify_free(alloc, 6 * kB, seed, 101);
}
}
22 changes: 12 additions & 10 deletions source/led3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ static const UvisorBoxAclItem acl[] = {

static void led3_main(const void *);

/* Box configuration
* We need at least 1kB in the main thread as we use printf in it. The interrupt
* stack size can be smaller as we do not do anything special in them. */
UVISOR_BOX_NAMESPACE(NULL);
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_MAIN(led3_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(box_led3, acl, UVISOR_BOX_STACK_SIZE, box_context);
UVISOR_BOX_HEAPSIZE(3 * 1024);
UVISOR_BOX_MAIN(led3_main, osPriorityNormal, 1024);
UVISOR_BOX_CONFIG(box_led3, acl, 512, box_context);

static void run_3(void)
{
Expand All @@ -37,34 +40,33 @@ static void led3_main(const void *)
DigitalOut led3(LED3);
led3 = LED_OFF;

Thread * thread1 = new Thread();
status = thread1->start(run_3);
Thread thread1(osPriorityNormal, 512, NULL);
status = thread1.start(run_3);
if (status != osOK) {
printf("Could not start box_led3 thread1.\r\n");
uvisor_error(USER_NOT_ALLOWED);
}

Thread * thread2 = new Thread();
status = thread2->start(run_3);
Thread thread2(osPriorityNormal, 512, NULL);
status = thread2.start(run_3);
if (status != osOK) {
printf("Could not start box_led3 thread2.\r\n");
uvisor_error(USER_NOT_ALLOWED);
}

/* Create page-backed allocator. */
const uint32_t kB = 1024;
SecureAllocator alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
/* Prepare the thread definition structure. */
osThreadDef_t thread_def;
thread_def.stacksize = DEFAULT_STACK_SIZE;
thread_def.stacksize = 512;
/* Allocate the stack inside the page allocator! */
thread_def.stack_pointer = (uint32_t *) secure_malloc(alloc, DEFAULT_STACK_SIZE);
thread_def.tpriority = osPriorityNormal;
thread_def.pthread = (void (*)(const void *)) &run_3;
/* Create a thread with the page allocator as heap. */
osThreadContextCreate(&thread_def, NULL, alloc);


while (1) {
static const size_t size = 20;
uint16_t seed = (size << 8) | (uvisor_ctx->heartbeat & 0xFF);
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 true
#define LED_OFF false

#define MAIN_LED LED_BLUE
#define HALT_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 false
#define LED_OFF true
#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__ */
20 changes: 10 additions & 10 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,40 @@

/* Create ACLs for main box. */
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);

static void main_alloc(void)
{
const uint32_t kB = 1024;
uint16_t seed = 0x10;
SecureAllocator alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);

while (1) {
alloc_fill_wait_verify_free(500, seed, 577);
specific_alloc_fill_wait_verify_free(alloc, 5*kB, seed, 97);
alloc_fill_wait_verify_free(50, seed, 577);
specific_alloc_fill_wait_verify_free(alloc, 5 * kB, seed, 97);
seed++;
}
}

int main(void)
{
osStatus status;
Thread * thread = new Thread();
status = thread->start(main_alloc);
Thread thread(osPriorityNormal, 512, NULL);
osStatus status = thread.start(main_alloc);
if (status != osOK) {
printf("Could not start main thread.\r\n");
uvisor_error(USER_NOT_ALLOWED);
}

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

size_t count = 0;

while (1)
{
while (1) {
printf("Main loop count: %d\r\n", count++);
Thread::wait(500);
}

return 0;
Expand Down
Loading