├── README.md ├── arduino-uno-nim ├── .gitignore ├── LICENSE ├── blink.nim ├── build.sh ├── led.c ├── nim.cfg └── panicoverride.nim ├── teensy-3-assembly ├── .gitignore ├── README.md ├── blink.s └── layout.ld ├── teensy-3-c ├── .gitignore ├── README.md ├── blink.c └── layout.ld ├── teensy-3-rust ├── .cargo │ └── config ├── .gitignore ├── Cargo.toml ├── README.md ├── build.rs ├── layout.ld ├── src │ └── main.rs └── thumbv7em-none-eabi.json └── teensy-lc-assembly ├── .gitignore ├── Makefile ├── README.md ├── blink.s └── layout.ld /README.md: -------------------------------------------------------------------------------- 1 | # Bare Metal Embedded Examples 2 | 3 | Various examples for bare metal programming on various embedded devices 4 | 5 | ## Arduino uno in nim (atmega328p) 6 | [/arduino-uno-nim](arduino-uno-nim) 7 | 8 | Contains an example of programming the arduino uno using the nim programming language around a c library. 9 | 10 | ## Teensy 3.1 in assembler 11 | [/teensy-3-assembler](teensy-3-assembler) 12 | 13 | A minimal example of programming the teensy 3.1 using only assembler. 14 | -------------------------------------------------------------------------------- /arduino-uno-nim/.gitignore: -------------------------------------------------------------------------------- 1 | nimcache/ 2 | -------------------------------------------------------------------------------- /arduino-uno-nim/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Michael Daffin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /arduino-uno-nim/blink.nim: -------------------------------------------------------------------------------- 1 | {.compile: "logic.c".} 2 | proc loop(): void {.importc.} 3 | 4 | when isMainModule: 5 | loop() 6 | -------------------------------------------------------------------------------- /arduino-uno-nim/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | nim c -d:release --gc:none --cpu:avr --os:standalone --parallelBuild:1 --passC:-Os --passC:-DF_CPU=16000000UL --passC:-mmcu=atmega328p --passL:-mmcu=atmega328p --verbosity:2 hello.nim 6 | avr-objcopy -O ihex -R .eeprom hello hello.hex 7 | avrdude -F -V -c arduino -p ATMEGA328P -P $1 -b 115200 -U flash:w:hello.hex 8 | -------------------------------------------------------------------------------- /arduino-uno-nim/led.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BLINK_DELAY_MS 1000 5 | 6 | void led_setup(void) { 7 | DDRB |= _BV(DDB5); 8 | } 9 | 10 | void led_on() { 11 | PORTB |= _BV(PORTB5); 12 | } 13 | 14 | void led_off() { 15 | PORTB &= ~_BV(PORTB5); 16 | } 17 | 18 | void delay(int ms) { 19 | _delay_ms(ms); 20 | } 21 | -------------------------------------------------------------------------------- /arduino-uno-nim/nim.cfg: -------------------------------------------------------------------------------- 1 | avr.standalone.gcc.path = "/usr/bin" 2 | avr.standalone.gcc.exe = "avr-gcc" 3 | avr.standalone.gcc.linkerexe = "avr-gcc" 4 | -------------------------------------------------------------------------------- /arduino-uno-nim/panicoverride.nim: -------------------------------------------------------------------------------- 1 | proc printf(frmt: cstring) {.varargs, importc, header: "", cdecl.} 2 | proc exit(code: int) {.importc, header: "", cdecl.} 3 | 4 | {.push stack_trace: off, profiler:off.} 5 | 6 | proc rawoutput(s: string) = 7 | printf("%s\n", s) 8 | 9 | proc panic(s: string) = 10 | rawoutput(s) 11 | exit(1) 12 | 13 | {.pop.} 14 | -------------------------------------------------------------------------------- /teensy-3-assembly/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.elf 3 | *.hex 4 | *.o 5 | -------------------------------------------------------------------------------- /teensy-3-assembly/README.md: -------------------------------------------------------------------------------- 1 | # Assembler on the teensy 3.1 2 | 3 | This is an example of writing pure assembler on the teensy 3.1. It is based of the example by [glock45](https://forum.pjrc.com/threads/25762-Turn-the-LED-on-with-assembler-code-\(-Teensy-3-1-\)?p=47739&viewfull=1#post47739). 4 | 5 | ## Prerequisites 6 | You will need the assembler, linker and objcopy from the arm-none-eabi toolkit: 7 | * arm-none-eabi-as 8 | * arm-none-eabi-ld 9 | * arm-none-eabi-objcopy 10 | 11 | You can get them from packge `arm-none-eabi-gcc` on archlinux or `gcc-arm-none-eabi` on ubuntu. Otherwise you can get it from [CodeSourcery](https://sourcery.mentor.com/GNUToolchain/release1802?) or from your arduino install at `$ARDUINO_SDK/hardware/tools/arm/bin`. 12 | 13 | You will also need the teensy-loader or teensy-loader-cli which you can get [here](https://www.pjrc.com/teensy/loader.html) 14 | 15 | ## Linker script - layout.ld 16 | The linker script tells the linker where to place the various bits of code. For more details see [this tutorial](http://bravegnu.org/gnu-eprog/linker.html) 17 | 18 | ## Assembler code - blink.s 19 | A minimal example of the assembler needed to drive the led on a teensy 3.1. It only initlises parts of the arm chip that are needed to blink the led in order to make it easier to understand. For a more complete example see the the example by [karl lunt](http://www.seanet.com/~karllunt/bareteensy31.html). 20 | 21 | ## Compile and upload 22 | 23 | To compile and upload to the teensy run: 24 | 25 | ```bash 26 | arm-none-eabi-as -g -mcpu=cortex-m4 -mthumb -o blink.o blink.s 27 | arm-none-eabi-ld -T layout.ld -o blink.elf blink.o 28 | arm-none-eabi-objcopy -O ihex -R .eeprom blink.elf blink.hex 29 | echo "Reset teensy now" 30 | teensy-loader-cli -w --mcu=mk20dx256 blink.hex 31 | ``` 32 | 33 | ## References 34 | 1. [Turn the LED on with assembler code ( Teensy 3.1 )](https://forum.pjrc.com/threads/25762-Turn-the-LED-on-with-assembler-code-\(-Teensy-3-1-\)?p=47739&viewfull=1#post47739) 35 | 1. [Embedded Programming with the GNU Toolchain](http://bravegnu.org/gnu-eprog/) 36 | 2. [Bare-metal Teensy 3.x Development](http://www.seanet.com/~karllunt/bareteensy31.html) 37 | -------------------------------------------------------------------------------- /teensy-3-assembly/blink.s: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | Blink demo in assembler for the teensy 3.1. 25 | 26 | This text refers to the programmers manual for the MK20DX256VLH7. You can 27 | obtain it from: https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf 28 | */ 29 | 30 | .syntax unified 31 | 32 | .section ".vectors" 33 | // Interrupt vector definitions - page 63 34 | .long _estack // 0 ARM: Initial Stack Pointer 35 | .long _startup // 1 ARM: Initial Program Counter 36 | .long _halt // 2 ARM: Non-maskable Interrupt (NMI) 37 | .long _halt // 3 ARM: Hard Fault 38 | .long _halt // 4 ARM: MemManage Fault 39 | .long _halt // 5 ARM: Bus Fault 40 | .long _halt // 6 ARM: Usage Fault 41 | 42 | .section ".flashconfig" 43 | // Flash Configuration located at 0x400 - page 569 44 | .long 0xFFFFFFFF 45 | .long 0xFFFFFFFF 46 | .long 0xFFFFFFFF 47 | .long 0xFFFFFFFE 48 | 49 | // Start of program execution 50 | .section ".startup","x",%progbits 51 | .thumb_func 52 | .global _startup 53 | _startup: 54 | // Zero all the registers 55 | mov r0,#0 56 | mov r1,#0 57 | mov r2,#0 58 | mov r3,#0 59 | mov r4,#0 60 | mov r5,#0 61 | mov r6,#0 62 | mov r7,#0 63 | mov r8,#0 64 | mov r9,#0 65 | mov r10,#0 66 | mov r11,#0 67 | mov r12,#0 68 | 69 | cpsid i // Disable interrupts 70 | 71 | // Unlock watchdog - page 478 72 | ldr r6, = 0x4005200E // address from page 473 73 | ldr r0, = 0xC520 74 | strh r0, [r6] 75 | ldr r0, = 0xD928 76 | strh r0, [r6] 77 | 78 | // Disable watchdog - page 468 79 | ldr r6, = 0x40052000 // address from page 473 80 | ldr r0, = 0x01D2 81 | strh r0, [r6] 82 | 83 | cpsie i // Enable interrupts 84 | 85 | // Enable system clock on all GPIO ports - page 254 86 | ldr r6, = 0x40048038 87 | ldr r0, = 0x00043F82 // 0b1000011111110000010 88 | str r0, [r6] 89 | 90 | // Configure the led pin 91 | ldr r6, = 0x4004B014 // PORTC_PCR5 - page 223/227 92 | ldr r0, = 0x00000143 // Enables GPIO | DSE | PULL_ENABLE | PULL_SELECT - page 227 93 | str r0, [r6] 94 | 95 | // Set the led pin to output 96 | ldr r6, = 0x400FF094 // GPIOC_PDDR - page 1334,1337 97 | ldr r0, = 0x20 // pin 5 on port c 98 | str r0, [r6] 99 | 100 | // Main loop 101 | loop: 102 | bl led_on 103 | bl delay 104 | bl led_off 105 | bl delay 106 | b loop 107 | 108 | // Function to turn the led off 109 | .thumb_func 110 | .global led_off 111 | led_off: 112 | ldr r6, = 0x400FF080 // GPIOC_PDOR - page 1334,1335 113 | ldr r0, = 0x0 114 | str r0, [r6] 115 | mov pc, r14 116 | 117 | // Function to turn the led on 118 | .thumb_func 119 | .global led_on 120 | led_on: 121 | ldr r6, = 0x400FF080 // GPIOC_PDOR - page 1334,1335 122 | ldr r0, = 0x20 123 | str r0, [r6] 124 | mov pc, r14 125 | 126 | // Uncalibrated busy wait 127 | .thumb_func 128 | .global delay 129 | delay: 130 | ldr r1, = 0x2625A0 131 | delay_loop: 132 | sub r1, r1, #1 133 | cmp r1, #0 134 | bne delay_loop 135 | mov pc, r14 136 | 137 | _halt: b _halt 138 | .end 139 | -------------------------------------------------------------------------------- /teensy-3-assembly/layout.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | A very basic linker script for the teensy 3.1. Page references refer to the 25 | programmers manual for the MK20DX256VLH7 which can be found at: 26 | https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf 27 | */ 28 | 29 | MEMORY { 30 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K 31 | RAM (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K /* page 90 */ 32 | } 33 | 34 | SECTIONS { 35 | . = 0x00000000; 36 | .text : { 37 | KEEP(*(.vectors)) /* vectors must be placed first - page 63*/ 38 | . = 0x400; 39 | KEEP(*(.flashconfig*)) /* flash configuration starts at 0x400 - page 569 */ 40 | *(.startup) 41 | *(.text) 42 | } > FLASH 43 | 44 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* stack pointer start */ 45 | } 46 | -------------------------------------------------------------------------------- /teensy-3-c/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.elf 3 | *.hex 4 | *.o 5 | -------------------------------------------------------------------------------- /teensy-3-c/README.md: -------------------------------------------------------------------------------- 1 | # C on the teensy 3.1 2 | 3 | An example of writing pure c on the teensy 3.1. 4 | 5 | ## Prerequisites 6 | You will need the C compiler, linker and objcopy from the arm-none-eabi toolkit: 7 | * arm-none-eabi-gcc 8 | * arm-none-eabi-ld 9 | * arm-none-eabi-objcopy 10 | 11 | You can get them from packge `arm-none-eabi-gcc` on archlinux or `gcc-arm-none-eabi` on ubuntu. Otherwise you can get it from [CodeSourcery](https://sourcery.mentor.com/GNUToolchain/release1802?) or from your arduino install at `$ARDUINO_SDK/hardware/tools/arm/bin`. 12 | 13 | You will also need the teensy-loader or teensy-loader-cli which you can get [here](https://www.pjrc.com/teensy/loader.html) 14 | 15 | ## Linker script: `layout.ld` 16 | 17 | The linker script tells the linker where to place the various bits of code. For more details see [this tutorial](http://bravegnu.org/gnu-eprog/linker.html) 18 | 19 | ## C code: `blink.c` 20 | 21 | A minimal example of the C code needed to drive the led on a teensy 3.1. It only initlises parts of the arm chip that are needed to blink the led in order to make it easier to understand. For a more complete example see the the example by [karl lunt](http://www.seanet.com/~karllunt/bareteensy31.html). 22 | 23 | ## Compile and upload 24 | 25 | To compile and upload to the teensy run: 26 | 27 | ```bash 28 | arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -nostdlib -c -o blink.o blink.c 29 | arm-none-eabi-ld -T layout.ld -o blink.elf blink.o 30 | arm-none-eabi-objcopy -O ihex -R .eeprom blink.elf blink.hex 31 | echo "Reset teensy now" 32 | teensy-loader-cli -w --mcu=mk20dx256 blink.hex 33 | ``` 34 | 35 | ## References 36 | 1. [Embedded Programming with the GNU Toolchain](http://bravegnu.org/gnu-eprog/) 37 | 2. [Bare-metal Teensy 3.x Development](http://www.seanet.com/~karllunt/bareteensy31.html) 38 | 3. [STM32/ARM Cortex-M3 HOWTO](http://fun-tech.se/stm32/linker/) 39 | 4. [Teensy3 core code](https://github.com/PaulStoffregen/cores/blob/master/teensy3/mk20dx128.c) 40 | -------------------------------------------------------------------------------- /teensy-3-c/blink.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | Blink demo in c for the teensy 3.1. 25 | 26 | This text refers to the programmers manual for the MK20DX256VLH7. You can 27 | obtain it from: https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf 28 | */ 29 | 30 | #define WDOG_UNLOCK (*(volatile unsigned short *)0x4005200E) // Watchdog Unlock register 31 | #define WDOG_STCTRLH (*(volatile unsigned short *)0x40052000) // Watchdog Status and Control Register High 32 | #define GPIO_CONFIG (*(volatile unsigned short *)0x40048038) 33 | #define PORTC_PCR5 (*(volatile unsigned short *)0x4004B014) // PORTC_PCR5 - page 223/227 34 | #define GPIOC_PDDR (*(volatile unsigned short *)0x400FF094) // GPIOC_PDDR - page 1334,1337 35 | #define GPIOC_PDOR (*(volatile unsigned short *)0x400FF080) // GPIOC_PDOR - page 1334,1335 36 | 37 | extern unsigned long _sflashdata; 38 | extern unsigned long _sdata; 39 | extern unsigned long _edata; 40 | extern unsigned long _sbss; 41 | extern unsigned long _ebss; 42 | extern unsigned long _estack; 43 | 44 | void startup(); 45 | void nim_handler(); 46 | void hard_fault_handler(); 47 | void mem_fault_handler(); 48 | void bus_fault_handler(); 49 | void usage_fault_handler(); 50 | void loop(); 51 | void led_on(); 52 | void led_off(); 53 | void delay(int ms); 54 | 55 | __attribute__ ((section(".vectors"), used)) 56 | void (* const _vectors[7])(void) = { 57 | (void (*)(void))((unsigned long)&_estack), 58 | startup, 59 | nim_handler, 60 | hard_fault_handler, 61 | mem_fault_handler, 62 | bus_fault_handler, 63 | usage_fault_handler 64 | }; 65 | 66 | __attribute__ ((section(".flashconfig"), used)) 67 | const unsigned char flashconfigbytes[16] = { 68 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 69 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF 70 | }; 71 | 72 | __attribute__ ((section(".startup"))) 73 | void startup() { 74 | WDOG_UNLOCK = ((unsigned short)0xC520); 75 | WDOG_UNLOCK = ((unsigned short)0xD928); 76 | WDOG_STCTRLH = ((unsigned short)0x01D2); 77 | 78 | unsigned long *src = &_sflashdata; 79 | unsigned long *dest = &_sdata; 80 | 81 | while (dest < &_edata) *dest++ = *src++; 82 | dest = &_sbss; 83 | while (dest < &_ebss) *dest++ = 0; 84 | 85 | // Enable system clock on all GPIO ports - page 254 86 | GPIO_CONFIG = ((unsigned short)0x00043F82); // 0b1000011111110000010 87 | // Configure the led pin 88 | PORTC_PCR5 = ((unsigned short)0x00000143); // Enables GPIO | DSE | PULL_ENABLE | PULL_SELECT - page 227 89 | // Set the led pin to output 90 | GPIOC_PDDR = ((unsigned short)0x20); // pin 5 on port c 91 | 92 | loop(); 93 | } 94 | 95 | int n = 1000; // Used to test if the data section is copied correctly 96 | void loop() { 97 | while (1) { 98 | led_on(); 99 | delay(n); 100 | led_off(); 101 | delay(n); 102 | } 103 | } 104 | 105 | void led_on() { 106 | led_on: 107 | GPIOC_PDOR = ((unsigned short)0x20); 108 | } 109 | 110 | void led_off() { 111 | GPIOC_PDOR = ((unsigned short)0x0); 112 | } 113 | 114 | void delay(int ms) { 115 | volatile unsigned int i; 116 | for (i = 0; i <= ms * 2500; i++) {;} 117 | } 118 | 119 | void nim_handler() { while (1); } 120 | void hard_fault_handler() { while (1); } 121 | void mem_fault_handler() { while (1); } 122 | void bus_fault_handler() { while (1); } 123 | void usage_fault_handler() { while (1); } 124 | -------------------------------------------------------------------------------- /teensy-3-c/layout.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | A very basic linker script for the teensy 3.1. Page references refer to the 25 | programmers manual for the MK20DX256VLH7 which can be found at: 26 | https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf 27 | */ 28 | 29 | _sflashdata = LOADADDR(.data); 30 | 31 | MEMORY { 32 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K 33 | RAM (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K /* page 90 */ 34 | } 35 | 36 | SECTIONS { 37 | . = 0x00000000; 38 | .text : { 39 | KEEP(*(.vectors)) /* vectors must be placed first - page 63*/ 40 | . = 0x400; 41 | KEEP(*(.flashconfig*)) /* flash configuration starts at 0x400 - page 569 */ 42 | *(.startup*) 43 | *(.text*) 44 | *(.rodata*) 45 | . = ALIGN(4); 46 | } > FLASH 47 | 48 | .data : { 49 | . = ALIGN(4); 50 | _sdata = .; 51 | *(.fastrun*) 52 | *(.data*) 53 | . = ALIGN(4); 54 | _edata = .; 55 | } > RAM AT > FLASH 56 | 57 | .bss : { 58 | . = ALIGN(4); 59 | _sbss = .; 60 | *(.bss*) 61 | *(COMMON) 62 | . = ALIGN(4); 63 | _ebss = .; 64 | } > RAM 65 | 66 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* stack pointer start */ 67 | } 68 | -------------------------------------------------------------------------------- /teensy-3-rust/.cargo/config: -------------------------------------------------------------------------------- 1 | [target.thumbv7em-none-eabi] 2 | linker = "arm-none-eabi-gcc" 3 | ar = "arm-none-eabi-ar" 4 | -------------------------------------------------------------------------------- /teensy-3-rust/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.elf 3 | *.hex 4 | *.o 5 | target 6 | Cargo.lock 7 | -------------------------------------------------------------------------------- /teensy-3-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blink" 3 | version = "0.1.0" 4 | authors = ["Michael Daffin "] 5 | build = "build.rs" 6 | 7 | [dependencies] 8 | rust-libcore = "*" 9 | 10 | [profile.dev] 11 | opt-level = 0 12 | debug = true 13 | panic = "abort" 14 | 15 | [profile.release] 16 | opt-level = 2 17 | debug = false 18 | panic = "abort" 19 | -------------------------------------------------------------------------------- /teensy-3-rust/README.md: -------------------------------------------------------------------------------- 1 | # Rust on the teensy 3.1 2 | 3 | A bare metal example of blink written in rust for the teensy 3.1 4 | 5 | ## Requirements 6 | 7 | * rustc nightly 8 | * cargo 9 | * arm-none-eabi-gcc 10 | * arm-none-eabi-ar 11 | * arm-none-eabi-objcopy 12 | 13 | ## Compile and upload 14 | 15 | ```bash 16 | cargo build --target thumbv7em-none-eabi 17 | arm-none-eabi-objcopy -O ihex -R .eeprom target/thumbv7em-none-eabi/debug/blink blink.hex 18 | 19 | echo "Reset teensy now" 20 | teensy-loader-cli -w --mcu=mk20dx256 blink.hex 21 | ``` 22 | -------------------------------------------------------------------------------- /teensy-3-rust/build.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | fn main() { 4 | let outdir = env::var("OUT_DIR").unwrap(); 5 | println!("cargo:rustc-link-search=native={}", outdir); 6 | } 7 | -------------------------------------------------------------------------------- /teensy-3-rust/layout.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | A very basic linker script for the teensy 3.1. Page references refer to the 25 | programmers manual for the MK20DX256VLH7 which can be found at: 26 | https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf 27 | */ 28 | 29 | _sflashdata = LOADADDR(.data); 30 | 31 | MEMORY { 32 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K 33 | RAM (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K /* page 90 */ 34 | } 35 | 36 | SECTIONS { 37 | . = 0x00000000; 38 | .text : { 39 | KEEP(*(.vectors)) /* vectors must be placed first - page 63*/ 40 | . = 0x400; 41 | KEEP(*(.flashconfig*)) /* flash configuration starts at 0x400 - page 569 */ 42 | *(.startup*) 43 | *(.text*) 44 | *(.rodata*) 45 | . = ALIGN(4); 46 | } > FLASH 47 | 48 | .data : { 49 | . = ALIGN(4); 50 | _sdata = .; 51 | *(.fastrun*) 52 | *(.data*) 53 | . = ALIGN(4); 54 | _edata = .; 55 | } > RAM AT > FLASH 56 | 57 | .bss : { 58 | . = ALIGN(4); 59 | _sbss = .; 60 | *(.bss*) 61 | *(COMMON) 62 | . = ALIGN(4); 63 | _ebss = .; 64 | } > RAM 65 | 66 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* stack pointer start */ 67 | } 68 | -------------------------------------------------------------------------------- /teensy-3-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | #![feature(lang_items,core_intrinsics,asm,start)] 2 | #![no_std] 3 | 4 | use core::intrinsics::{volatile_store}; 5 | 6 | #[lang="eh_personality"] extern fn eh_personality() {} 7 | #[lang="panic_fmt"] 8 | #[no_mangle] 9 | pub extern fn rust_begin_unwind(_fmt: &core::fmt::Arguments, _file_line: &(&'static str, usize)) -> ! 10 | { 11 | loop {} 12 | } 13 | 14 | #[no_mangle] 15 | pub extern fn __aeabi_unwind_cpp_pr0() -> () 16 | { 17 | loop {} 18 | } 19 | 20 | #[no_mangle] 21 | pub extern fn __aeabi_unwind_cpp_pr1() -> () 22 | { 23 | loop {} 24 | } 25 | 26 | macro_rules! GPIOC_PDOR {() => (0x400FF080 as *mut u32);} // GPIOC_PDOR - page 1334,1335 27 | macro_rules! WDOG_UNLOCK {() => (0x4005200E as *mut u16);} // Watchdog Unlock register 28 | macro_rules! WDOG_STCTRLH {() => (0x40052000 as *mut u16);} // Watchdog Status and Control Register High 29 | macro_rules! GPIO_CONFIG {() => (0x40048038 as *mut u32);} 30 | macro_rules! PORTC_PCR5 {() => (0x4004B014 as *mut u32);} // PORTC_PCR5 - page 223/227 31 | macro_rules! GPIOC_PDDR {() => (0x400FF094 as *mut u32);} // GPIOC_PDDR - page 1334,1337 32 | macro_rules! GPIOC_PDOR {() => (0x400FF080 as *mut u32);} // GPIOC_PDOR - page 1334,1335 33 | 34 | extern { 35 | static mut _sflashdata: u32; 36 | static mut _sdata: u32; 37 | static mut _edata: u32; 38 | static mut _sbss: u32; 39 | static mut _ebss: u32; 40 | fn _estack(); 41 | } 42 | 43 | #[link_section=".vectors"] 44 | #[allow(non_upper_case_globals)] 45 | #[no_mangle] 46 | pub static ISRVectors: [Option; 16] = [ 47 | Some(_estack), // Stack pointer 48 | Some(startup), // Reset 49 | Some(isr_nmi), // NMI 50 | Some(isr_hardfault), // Hard Fault 51 | Some(isr_mmfault), // CM3 Memory Management Fault 52 | Some(isr_busfault), // CM3 Bus Fault 53 | Some(isr_usagefault), // CM3 Usage Fault 54 | Some(isr_reserved_1), // Reserved - Used as NXP Checksum 55 | None, // Reserved 56 | None, // Reserved 57 | None, // Reserved 58 | Some(isr_svcall), // SVCall 59 | Some(isr_debugmon), // Reserved for debug 60 | None, // Reserved 61 | Some(isr_pendsv), // PendSV 62 | Some(isr_systick), // SysTick 63 | ]; 64 | 65 | #[link_section=".flashconfig"] 66 | #[allow(non_upper_case_globals)] 67 | #[no_mangle] 68 | pub static flashconfigbytes: [usize; 4] = [ 69 | 0xFFFFFFFF, 70 | 0xFFFFFFFF, 71 | 0xFFFFFFFF, 72 | 0xFFFFFFFE, 73 | ]; 74 | 75 | pub unsafe extern fn startup() { 76 | let mut src: *mut u32 = &mut _sflashdata; 77 | let mut dest: *mut u32 = &mut _sdata; 78 | 79 | volatile_store(WDOG_UNLOCK!(), 0xC520); 80 | volatile_store(WDOG_UNLOCK!(), 0xD928); 81 | volatile_store(WDOG_STCTRLH!(), 0x01D2); 82 | 83 | while dest < &mut _edata as *mut u32 { 84 | *dest = *src; 85 | dest = ((dest as u32) + 4) as *mut u32; 86 | src = ((src as u32) + 4) as *mut u32; 87 | } 88 | 89 | dest = &mut _sbss as *mut u32; 90 | 91 | while dest < &mut _edata as *mut u32 { 92 | *dest = 0; 93 | dest = ((dest as u32) + 4) as *mut u32; 94 | } 95 | 96 | // Enable system clock on all GPIO ports - page 254 97 | *GPIO_CONFIG!() = 0x00043F82; // 0b1000011111110000010 98 | // Configure the led pin 99 | *PORTC_PCR5!() = 0x00000143; // Enables GPIO | DSE | PULL_ENABLE | PULL_SELECT - page 227 100 | // Set the led pin to output 101 | *GPIOC_PDDR!() = 0x20; // pin 5 on port c 102 | 103 | rust_loop(); 104 | } 105 | 106 | pub fn led_on() { 107 | unsafe { 108 | volatile_store(GPIOC_PDOR!(), 0x20); 109 | } 110 | } 111 | 112 | pub fn led_off() { 113 | unsafe { 114 | volatile_store(GPIOC_PDOR!(), 0x0); 115 | } 116 | } 117 | 118 | pub fn delay(ms: i32) { 119 | for _ in 0..ms*250 { 120 | unsafe { 121 | asm!("NOP"); 122 | } 123 | } 124 | } 125 | 126 | pub fn rust_loop() { 127 | loop { 128 | led_on(); 129 | delay(1000); 130 | led_off(); 131 | delay(1000); 132 | } 133 | } 134 | 135 | #[start] 136 | fn lang_start(_: isize, _: *const *const u8) -> isize { 137 | unsafe { 138 | startup(); 139 | } 140 | 0 141 | } 142 | 143 | 144 | pub unsafe extern fn isr_nmi() { loop {} } 145 | pub unsafe extern fn isr_hardfault() { loop {} } 146 | pub unsafe extern fn isr_mmfault() { loop {} } 147 | pub unsafe extern fn isr_busfault() { loop {} } 148 | pub unsafe extern fn isr_usagefault() { loop {} } 149 | pub unsafe extern fn isr_reserved_1() { loop {} } 150 | pub unsafe extern fn isr_svcall() { loop {} } 151 | pub unsafe extern fn isr_debugmon() { loop {} } 152 | pub unsafe extern fn isr_pendsv() { loop {} } 153 | pub unsafe extern fn isr_systick() { loop {} } 154 | -------------------------------------------------------------------------------- /teensy-3-rust/thumbv7em-none-eabi.json: -------------------------------------------------------------------------------- 1 | { 2 | "arch": "arm", 3 | "cpu": "cortex-m4", 4 | "data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", 5 | "disable-redzone": true, 6 | "executables": true, 7 | "llvm-target": "thumbv7em-none-eabi", 8 | "morestack": false, 9 | "os": "none", 10 | "relocation-model": "static", 11 | "target-endian": "little", 12 | "target-pointer-width": "32", 13 | "no-compiler-rt": true, 14 | "pre-link-args": [ 15 | "-mcpu=cortex-m4", "-mthumb", 16 | "-Tlayout.ld" 17 | ], 18 | "post-link-args": [ 19 | "-nostdlib", "-nostartfiles" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /teensy-lc-assembly/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.elf 3 | *.hex 4 | *.o 5 | -------------------------------------------------------------------------------- /teensy-lc-assembly/Makefile: -------------------------------------------------------------------------------- 1 | flash: blink.hex 2 | @echo "### Reset teensy now" 3 | teensy-loader-cli -w --mcu=mkl26z64 $< 4 | 5 | blink.hex: blink.elf 6 | arm-none-eabi-objcopy -O ihex -R .eeprom $< $@ 7 | 8 | blink.elf: blink.o layout.ld 9 | arm-none-eabi-ld -T layout.ld -o $@ $< 10 | 11 | blink.o: blink.s Makefile 12 | arm-none-eabi-as -g -mcpu=cortex-m0plus -mthumb -o $@ $< 13 | 14 | -------------------------------------------------------------------------------- /teensy-lc-assembly/README.md: -------------------------------------------------------------------------------- 1 | # Assembler on the teensy LC 2 | 3 | This is an example of writing pure assembler on the teensy LC. 4 | It is based on the one for teensy 3.1. 5 | See ../teensy-3-assembly/README.md 6 | 7 | ## Prerequisites 8 | You will need the assembler, linker and objcopy from the arm-none-eabi toolkit: 9 | * arm-none-eabi-as 10 | * arm-none-eabi-ld 11 | * arm-none-eabi-objcopy 12 | 13 | You can get them from packge `arm-none-eabi-gcc` on archlinux or `gcc-arm-none-eabi` on ubuntu. Otherwise you can get it from [CodeSourcery](https://sourcery.mentor.com/GNUToolchain/release1802?) or from your arduino install at `$ARDUINO_SDK/hardware/tools/arm/bin`. 14 | 15 | You will also need the teensy-loader or teensy-loader-cli which you can get [here](https://www.pjrc.com/teensy/loader.html) 16 | 17 | ## Linker script - layout.ld 18 | The linker script tells the linker where to place the various bits of code. For more details see [this tutorial](http://bravegnu.org/gnu-eprog/linker.html) 19 | 20 | ## Assembler code - blink.s 21 | A minimal example of the assembler needed to drive the led on a teensy LC. It only initlises parts of the arm chip that are needed to blink the led in order to make it easier to understand. For a more complete example see the the example by [karl lunt](http://www.seanet.com/~karllunt/bareteensy31.html). 22 | 23 | ## Compile and upload 24 | 25 | To compile and upload to the teensy, run `make`. 26 | -------------------------------------------------------------------------------- /teensy-lc-assembly/blink.s: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | Blink demo in assembler for the teensy LC. 25 | 26 | This text refers to the programmers manual for the MKL26Z64VFT4. You can 27 | obtain it from: https://www.pjrc.com/teensy/KL26P121M48SF4RM.pdf 28 | */ 29 | 30 | .syntax unified 31 | 32 | .section ".vectors" 33 | // Interrupt vector definitions - page 58 34 | .long _estack // 0 ARM: Initial Stack Pointer 35 | .long _startup // 1 ARM: Initial Program Counter 36 | .long _halt // 2 ARM: Non-maskable Interrupt (NMI) 37 | .long _halt // 3 ARM: Hard Fault 38 | 39 | .section ".flashconfig" 40 | // Flash Configuration located at 0x400 - page 443 41 | .long 0xFFFFFFFF 42 | .long 0xFFFFFFFF 43 | .long 0xFFFFFFFF 44 | .long 0xFFFFFFFE 45 | 46 | // Start of program execution 47 | .section ".startup","x",%progbits 48 | .thumb_func 49 | .global _startup 50 | _startup: 51 | // Zero all the registers 52 | movs r0,#0 53 | mov r1,r0 54 | mov r2,r0 55 | mov r3,r0 56 | mov r4,r0 57 | mov r5,r0 58 | mov r6,r0 59 | mov r7,r0 60 | mov r8,r0 61 | mov r9,r0 62 | mov r10,r0 63 | mov r11,r0 64 | mov r12,r0 65 | 66 | /* cpsid i // Disable interrupts*/ 67 | 68 | // COP Control Register (SIM_COPC) - page 232 69 | ldr r6, = 0x40048100 // address from page 208 70 | ldr r0, = 0 71 | str r0, [r6] 72 | 73 | /* cpsie i // Enable interrupts*/ 74 | 75 | // Enable system clock on all GPIO ports - page 222 76 | ldr r6, = 0x40048038 77 | ldr r0, = 0x00043F82 // 0b1000011111110000010 78 | str r0, [r6] 79 | 80 | // Configure the led pin 81 | ldr r6, = 0x4004B014 // PORTC_PCR5 - page 196 82 | ldr r0, = 0x00000143 // Enables GPIO | DSE | PULL_ENABLE | PULL_SELECT - page 200,201 83 | str r0, [r6] 84 | 85 | // Set the led pin to output 86 | ldr r6, = 0x400FF094 // GPIOC_PDDR - page 842 87 | ldr r0, = 0x20 // pin 5 on port c 88 | str r0, [r6] 89 | 90 | // Main loop 91 | loop: 92 | bl led_on 93 | bl delay 94 | bl led_off 95 | bl delay 96 | b loop 97 | 98 | // Function to turn the led off 99 | .thumb_func 100 | .global led_off 101 | led_off: 102 | ldr r6, = 0x400FF080 // GPIOC_PDOR - page 842,843 103 | ldr r0, = 0x0 104 | str r0, [r6] 105 | mov pc, r14 106 | 107 | // Function to turn the led on 108 | .thumb_func 109 | .global led_on 110 | led_on: 111 | ldr r6, = 0x400FF080 // GPIOC_PDOR - page 842,843 112 | ldr r0, = 0x20 113 | str r0, [r6] 114 | mov pc, r14 115 | 116 | // Uncalibrated busy wait 117 | .thumb_func 118 | .global delay 119 | delay: 120 | ldr r1, = 0x2625A0 121 | delay_loop: 122 | subs r1, r1, #1 123 | cmp r1, #0 124 | bne delay_loop 125 | mov pc, r14 126 | 127 | _halt: b _halt 128 | .end 129 | -------------------------------------------------------------------------------- /teensy-lc-assembly/layout.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Michael Daffin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | A very basic linker script for the teensy LC. Page references refer to the 25 | programmers manual for the MKL26Z64VFT4 which can be found at: 26 | https://www.pjrc.com/teensy/KL26P121M48SF4RM.pdf 27 | */ 28 | 29 | MEMORY { 30 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 62K /* page 79 */ 31 | RAM (rwx) : ORIGIN = 0x1FFFF800, LENGTH = 8K /* page 82 */ 32 | 33 | } 34 | 35 | SECTIONS { 36 | . = 0x00000000; 37 | .text : { 38 | KEEP(*(.vectors)) /* vectors must be placed first - page 58*/ 39 | . = 0x400; 40 | KEEP(*(.flashconfig*)) /* flash configuration starts at 0x400 - page 569 */ 41 | *(.startup) 42 | *(.text) 43 | } > FLASH 44 | 45 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* stack pointer start */ 46 | } 47 | --------------------------------------------------------------------------------