Clean up FS-BB48 example
This commit is contained in:
@@ -6,7 +6,7 @@ PROJECT = sample
|
||||
|
||||
CHOPSTX = ..
|
||||
LDSCRIPT= sample.ld
|
||||
CSRC = sample.c reset.c usb_kl27z.c usb-cdc.c crc32.c
|
||||
CSRC = sample.c first-pages.c usb_kl27z.c usb-cdc.c
|
||||
|
||||
###################################
|
||||
CROSS = arm-none-eabi-
|
||||
@@ -16,7 +16,7 @@ OBJCOPY = $(CROSS)objcopy
|
||||
|
||||
MCU = cortex-m0plus
|
||||
CWARN = -Wall -Wextra -Wstrict-prototypes
|
||||
DEFS = -DMAKE_ENTRY_PUBLIC -DFREE_STANDING -DMHZ=48
|
||||
DEFS = -DFREE_STANDING -DMHZ=48
|
||||
OPT = -O3 -Os -g
|
||||
LIBS =
|
||||
|
||||
|
||||
@@ -1,11 +1,77 @@
|
||||
/*
|
||||
* CRC32.c - CRC32 calculation routines.
|
||||
* first-pages.c - First pages for MKL27Z256.
|
||||
*
|
||||
* Copyright (C) 2016 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* Copying and distribution of this file, with or without modification,
|
||||
* are permitted in any medium without royalty provided the copyright
|
||||
* notice and this notice are preserved. This file is offered as-is,
|
||||
* without any warranty.
|
||||
*
|
||||
*
|
||||
* First two pages of Flash ROM is difficult to use because of
|
||||
* predefined purposes. It's defined as a default vector page and
|
||||
* flash configuration page.
|
||||
*
|
||||
* We put something useful to those two pages, together with the
|
||||
* data for predefined purposes.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint8_t __main_stack_end__;
|
||||
|
||||
static void __attribute__ ((naked,section(".flash_config_page")))
|
||||
reset (void)
|
||||
{
|
||||
uint32_t r3 = 0xe000ed08;
|
||||
|
||||
asm volatile ("str %2, [%0]\n\t" /* Set SCR->VTOR */
|
||||
"ldr %0, [%2, #4]\n\t" /* Jump to the entry */
|
||||
"bx %0\n\t"
|
||||
".align 2\n"
|
||||
: "=r" (r3)
|
||||
: "0" (r3), "r" (0x00000800)
|
||||
: "memory");
|
||||
|
||||
/* Never reach here. */
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
stack_entry[] __attribute__ ((section(".first_page.first_words"),used)) = {
|
||||
(uint32_t)(&__main_stack_end__ - 32),
|
||||
(uint32_t)reset,
|
||||
};
|
||||
|
||||
/*
|
||||
* NOTE: We don't use backdoor comparison key. The area is used by
|
||||
* CRC32 table.
|
||||
*/
|
||||
static uint32_t
|
||||
flash_config[] __attribute__ ((section(".flash_config"),used)) = {
|
||||
0xffffffff, /* Protection bytes */
|
||||
0xffff3ffe, /* FSEC=0xfe, FOPT=0x3f */
|
||||
/* FOPT=0x3f:
|
||||
* BOOTSRC_SEL=00: Boot from flash
|
||||
*/
|
||||
/* FSEC=0xfe:
|
||||
* unsecure
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* CRC32 calculation routines.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Table of CRC32, generated by gen_crc_table.py
|
||||
*/
|
||||
static unsigned int crc32_table[256] = {
|
||||
static unsigned int
|
||||
crc32_table[256] __attribute__ ((section(".first_page"))) = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
@@ -53,24 +119,28 @@ static unsigned int crc32_table[256] = {
|
||||
|
||||
static unsigned int crc_reg;
|
||||
|
||||
__attribute__ ((section(".flash_config_page")))
|
||||
void
|
||||
crc32_init (void)
|
||||
{
|
||||
crc_reg = 0xffffffff;
|
||||
}
|
||||
|
||||
__attribute__ ((section(".flash_config_page")))
|
||||
unsigned int
|
||||
crc32_value (void)
|
||||
{
|
||||
return crc_reg;
|
||||
}
|
||||
|
||||
__attribute__ ((section(".flash_config_page")))
|
||||
void
|
||||
crc32_u8 (unsigned char bits_eight)
|
||||
{
|
||||
crc_reg = crc32_table[(crc_reg & 0xff) ^ bits_eight] ^ (crc_reg >> 8);
|
||||
}
|
||||
|
||||
__attribute__ ((section(".flash_config_page")))
|
||||
void
|
||||
crc32_u32 (unsigned int u)
|
||||
{
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* sys.c - No system routines, but only RESET handler for MKL27Z256.
|
||||
*
|
||||
* Copyright (C) 2016 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* Copying and distribution of this file, with or without modification,
|
||||
* are permitted in any medium without royalty provided the copyright
|
||||
* notice and this notice are preserved. This file is offered as-is,
|
||||
* without any warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void __attribute__ ((naked))
|
||||
reset (void)
|
||||
{
|
||||
asm volatile ("cpsid i\n\t" /* Mask all interrupts. */
|
||||
"mov r0, pc\n\t" /* r0 = PC & ~0x0fff */
|
||||
"mov r1, #0x10\n\t"
|
||||
"lsl r1, #8\n\t"
|
||||
"sub r1, r1, #1\n\t"
|
||||
"bic r0, r0, r1\n\t"
|
||||
"ldr r2, [r0]\n\t"
|
||||
"msr MSP, r2\n\t" /* Main (exception handler) stack. */
|
||||
"b entry\n\t"
|
||||
: /* no output */ : /* no input */ : "memory");
|
||||
/* Never reach here. */
|
||||
}
|
||||
|
||||
extern uint8_t __main_stack_end__;
|
||||
extern void preempt (void);
|
||||
extern void chx_timer_expired (void);
|
||||
extern void chx_handle_intr (void);
|
||||
|
||||
static void nmi (void)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
static void __attribute__ ((naked))
|
||||
hard_fault (void)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
static void mem_manage (void)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
static void bus_fault (void)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
static void usage_fault (void)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
static void none (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
typedef void (*handler)(void);
|
||||
extern uint8_t __main_stack_end__;
|
||||
|
||||
handler vector[] __attribute__ ((section(".vectors"))) = {
|
||||
(handler)(&__main_stack_end__ - 32),
|
||||
reset,
|
||||
nmi, /* nmi */
|
||||
hard_fault, /* hard fault */
|
||||
/* 0x10 */
|
||||
mem_manage, /* mem manage */
|
||||
bus_fault, /* bus fault */
|
||||
usage_fault, /* usage fault */
|
||||
none,
|
||||
/* 0x20 */
|
||||
none, none, none, /* reserved */
|
||||
none, /* SVCall */
|
||||
none, /* Debug */
|
||||
none, /* reserved */
|
||||
preempt, /* PendSV */
|
||||
chx_timer_expired, /* SysTick */
|
||||
/* 0x40 */
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
/* 0x60 */
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
/* 0x80 */
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
/* 0xA0 */
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
||||
/* 0xc0 */
|
||||
};
|
||||
|
||||
uint32_t flash_config[] __attribute__ ((section(".flash_config"))) = {
|
||||
0xffffffff, 0xffffffff, /* Backdoor comparison key. */
|
||||
0xffffffff, /* Protection bytes */
|
||||
0xffff3ffe, /* FSEC=0xfe, FOPT=0x3f */
|
||||
/* FOPT=0x3f:
|
||||
* BOOTSRC_SEL=00: Boot from flash
|
||||
*/
|
||||
/* FSEC=0xfe:
|
||||
* unsecure
|
||||
*/
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* MK27Z memory setup.
|
||||
*/
|
||||
__main_stack_size__ = 0x0100; /* Exception handlers */
|
||||
__main_stack_size__ = 0x0100; /* Exception handlers */
|
||||
__process0_stack_size__ = 0x0300; /* Main program */
|
||||
__process1_stack_size__ = 0x0200; /* first thread program */
|
||||
__process2_stack_size__ = 0x0100; /* second thread program */
|
||||
__process3_stack_size__ = 0x0200; /* third thread program */
|
||||
__process1_stack_size__ = 0x0200; /* first thread program */
|
||||
__process2_stack_size__ = 0x0100; /* second thread program */
|
||||
__process3_stack_size__ = 0x0200; /* third thread program */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
@@ -23,15 +23,19 @@ SECTIONS
|
||||
|
||||
_text = .;
|
||||
|
||||
.f2 : ALIGN(16) SUBALIGN(8)
|
||||
{
|
||||
KEEP(*(.first_page.first_words))
|
||||
KEEP(*(.first_page))
|
||||
KEEP(*(.flash_config))
|
||||
KEEP(*(.flash_config_page))
|
||||
} > flash =0xffffffff
|
||||
|
||||
.text : ALIGN(16) SUBALIGN(16)
|
||||
{
|
||||
KEEP(*(.vectors))
|
||||
. = ALIGN(1024);
|
||||
KEEP(*(.flash_config))
|
||||
KEEP(*(.startup.vectors))
|
||||
. = ALIGN(16);
|
||||
*(.text.svc)
|
||||
*(.text.sched)
|
||||
*(.text.preempt)
|
||||
*(.text.startup.*)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
@@ -41,11 +45,10 @@ SECTIONS
|
||||
*(.glue_7)
|
||||
*(.gcc*)
|
||||
. = ALIGN(8);
|
||||
} > flash
|
||||
} > flash =0xffffffff
|
||||
|
||||
/DISCARD/ :
|
||||
{
|
||||
*(.startup.vectors)
|
||||
*(.bss.startup.0)
|
||||
}
|
||||
|
||||
@@ -55,7 +58,7 @@ SECTIONS
|
||||
PROVIDE(__exidx_start = .);
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
PROVIDE(__exidx_end = .);
|
||||
} > flash
|
||||
} > flash =0xffffffff
|
||||
|
||||
.eh_frame_hdr : {*(.eh_frame_hdr)} > flash
|
||||
|
||||
@@ -98,11 +101,6 @@ SECTIONS
|
||||
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(512);
|
||||
__usb_bdt__ = .;
|
||||
. += 512;
|
||||
__usb_buf__ = .;
|
||||
. += 8 /*control write*/ + 64 /*control read*/ + 64 + 64 + 8;
|
||||
. = ALIGN(4);
|
||||
PROVIDE(_data = .);
|
||||
*(.data)
|
||||
@@ -112,7 +110,7 @@ SECTIONS
|
||||
*(.ramtext)
|
||||
. = ALIGN(4);
|
||||
PROVIDE(_edata = .);
|
||||
} > ram AT > flash
|
||||
} > ram AT > flash =0xffffffff
|
||||
|
||||
.bss :
|
||||
{
|
||||
@@ -123,7 +121,9 @@ SECTIONS
|
||||
*(.bss.*)
|
||||
. = ALIGN(4);
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
. = ALIGN(512);
|
||||
__usb_bdt__ = .;
|
||||
. += 512;
|
||||
PROVIDE(_bss_end = .);
|
||||
} > ram
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ struct BD {
|
||||
#define TOK_PID(ctrl) ((ctrl >> 2) & 0x0f)
|
||||
|
||||
extern uint8_t __usb_bdt__;
|
||||
extern uint8_t __usb_buf__;
|
||||
|
||||
static struct BD *const BD_table = (struct BD *const)&__usb_bdt__;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user