Skip to content

Commit 8228baf

Browse files
authored
Merge pull request #13 from tock/imix
add imix bootloader
2 parents 2041c08 + 8d75aca commit 8228baf

File tree

8 files changed

+355
-0
lines changed

8 files changed

+355
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ script:
1717
- tools/run_cargo_fmt.sh diff
1818
- make -C boards/hail-bootloader
1919
- make -C boards/nrf52-bootloader
20+
- make -C boards/imix-bootloader
2021

boards/imix-bootloader/Cargo.lock

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

boards/imix-bootloader/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "imixbootloader"
3+
version = "0.1.0"
4+
authors = ["Tock Project Developers <[email protected]>"]
5+
build = "build.rs"
6+
7+
[profile.dev]
8+
panic = "abort"
9+
lto = true
10+
opt-level = 0
11+
debug = true
12+
13+
[profile.release]
14+
panic = "abort"
15+
lto = true
16+
17+
[dependencies]
18+
cortexm4 = { git = "https://github.com/tock/tock" }
19+
capsules = { git = "https://github.com/tock/tock" }
20+
kernel = { git = "https://github.com/tock/tock" }
21+
sam4l = { git = "https://github.com/tock/tock" }
22+
bootloader = { path = "../../bootloader" }
23+
24+
[build-dependencies]
25+
bootloader_attributes = { path = "../../tools/bootloader_attributes" }

boards/imix-bootloader/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Makefile for building the bootloader for Imix
2+
3+
TARGET=thumbv7em-none-eabi
4+
PLATFORM=imixbootloader
5+
6+
include ../Common.mk
7+
8+
TOCKLOADER = tockloader
9+
TOCKLOADER_JTAG_FLAGS = --jtag --board imix --arch cortex-m4 --jtag-device ATSAM4LC8C
10+
11+
# upload kernel over JTAG
12+
.PHONY: flash
13+
flash: target/$(TARGET)/release/$(PLATFORM).bin
14+
$(TOCKLOADER) flash --address 0x0 $(TOCKLOADER_JTAG_FLAGS) $<

boards/imix-bootloader/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The Imix Bootloader
2+
===================
3+
4+
Bootloader for Imix written on top of Tock.

boards/imix-bootloader/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extern crate bootloader_attributes;
2+
3+
fn main() {
4+
println!("cargo:rerun-if-changed=layout.ld");
5+
println!("cargo:rerun-if-changed=chip_layout.ld");
6+
println!("cargo:rerun-if-changed=../kernel_layout.ld");
7+
8+
let mut f = bootloader_attributes::get_file();
9+
bootloader_attributes::write_flags(&mut f, 512, "1.0.1");
10+
bootloader_attributes::write_attribute(&mut f, "board", "imix");
11+
bootloader_attributes::write_attribute(&mut f, "arch", "cortex-m4");
12+
bootloader_attributes::write_attribute(&mut f, "jldevice", "ATSAM4LC8C");
13+
bootloader_attributes::write_attribute(&mut f, "appaddr", "0x40000");
14+
}

boards/imix-bootloader/layout.ld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Memory Spaces Definitions, 448K flash, 64K ram */
2+
MEMORY
3+
{
4+
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000
5+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
6+
}
7+
8+
INCLUDE ../kernel_layout.ld

boards/imix-bootloader/src/main.rs

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
//! Board file for Imix bootloader.
2+
3+
#![no_std]
4+
#![no_main]
5+
#![feature(asm, const_fn, lang_items, panic_implementation)]
6+
7+
extern crate bootloader;
8+
extern crate cortexm4;
9+
#[macro_use(create_capability, static_init)]
10+
extern crate kernel;
11+
extern crate capsules;
12+
extern crate sam4l;
13+
14+
use core::panic::PanicInfo;
15+
16+
use kernel::capabilities;
17+
use kernel::hil;
18+
use kernel::hil::Controller;
19+
use kernel::Platform;
20+
21+
include!(concat!(env!("OUT_DIR"), "/attributes.rs"));
22+
23+
// No processes are supported.
24+
static mut PROCESSES: [Option<&'static kernel::procs::ProcessType>; 0] = [];
25+
26+
/// Dummy buffer that causes the linker to reserve enough space for the stack.
27+
#[no_mangle]
28+
#[link_section = ".stack_buffer"]
29+
pub static mut STACK_MEMORY: [u8; 0x2000] = [0; 0x2000];
30+
31+
struct ImixBootloader {
32+
bootloader: &'static bootloader::bootloader::Bootloader<
33+
'static,
34+
sam4l::usart::USART,
35+
sam4l::flashcalw::FLASHCALW,
36+
sam4l::gpio::GPIOPin,
37+
>,
38+
}
39+
40+
impl Platform for ImixBootloader {
41+
fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
42+
where
43+
F: FnOnce(Option<&kernel::Driver>) -> R,
44+
{
45+
// Bootloader does not support apps.
46+
match driver_num {
47+
_ => f(None),
48+
}
49+
}
50+
}
51+
52+
unsafe fn set_pin_primary_functions() {
53+
use sam4l::gpio::PeripheralFunction::{A, B, C, E};
54+
use sam4l::gpio::{PA, PB, PC};
55+
56+
// Right column: Imix pin name
57+
// Left column: SAM4L peripheral function
58+
PA[04].configure(Some(A)); // AD0 -- ADCIFE AD0
59+
PA[05].configure(Some(A)); // AD1 -- ADCIFE AD1
60+
PA[06].configure(Some(C)); // EXTINT1 -- EIC EXTINT1
61+
PA[07].configure(Some(A)); // AD1 -- ADCIFE AD2
62+
PA[08].configure(None); //... RF233 IRQ -- GPIO pin
63+
PA[09].configure(None); //... RF233 RST -- GPIO pin
64+
PA[10].configure(None); //... RF233 SLP -- GPIO pin
65+
PA[13].configure(None); //... TRNG EN -- GPIO pin
66+
PA[14].configure(None); //... TRNG_OUT -- GPIO pin
67+
PA[17].configure(None); //... NRF INT -- GPIO pin
68+
PA[18].configure(Some(A)); // NRF CLK -- USART2_CLK
69+
PA[20].configure(None); //... D8 -- GPIO pin
70+
PA[21].configure(Some(E)); // TWI2 SDA -- TWIM2_SDA
71+
PA[22].configure(Some(E)); // TWI2 SCL -- TWIM2 TWCK
72+
PA[25].configure(Some(A)); // USB_N -- USB DM
73+
PA[26].configure(Some(A)); // USB_P -- USB DP
74+
PB[00].configure(Some(A)); // TWI1_SDA -- TWIMS1 TWD
75+
PB[01].configure(Some(A)); // TWI1_SCL -- TWIMS1 TWCK
76+
PB[02].configure(Some(A)); // AD3 -- ADCIFE AD3
77+
PB[03].configure(Some(A)); // AD4 -- ADCIFE AD4
78+
PB[04].configure(Some(A)); // AD5 -- ADCIFE AD5
79+
PB[05].configure(Some(A)); // VHIGHSAMPLE -- ADCIFE AD6
80+
PB[06].configure(None); //... RTS3 -- USART3 RTS !! FTDI DTR BOOTLOADER SELECT
81+
PB[07].configure(None); //... NRF RESET -- GPIO
82+
PB[09].configure(Some(A)); // RX3 -- USART3 RX
83+
PB[10].configure(Some(A)); // TX3 -- USART3 TX
84+
PB[11].configure(Some(A)); // CTS0 -- USART0 CTS
85+
PB[12].configure(Some(A)); // RTS0 -- USART0 RTS
86+
PB[13].configure(Some(A)); // CLK0 -- USART0 CLK
87+
PB[14].configure(Some(A)); // RX0 -- USART0 RX
88+
PB[15].configure(Some(A)); // TX0 -- USART0 TX
89+
PC[00].configure(Some(A)); // CS2 -- SPI NPCS2
90+
PC[01].configure(Some(A)); // CS3 (RF233) -- SPI NPCS3
91+
PC[02].configure(Some(A)); // CS1 -- SPI NPCS1
92+
PC[03].configure(Some(A)); // CS0 -- SPI NPCS0
93+
PC[04].configure(Some(A)); // MISO -- SPI MISO
94+
PC[05].configure(Some(A)); // MOSI -- SPI MOSI
95+
PC[06].configure(Some(A)); // SCK -- SPI CLK
96+
PC[07].configure(Some(B)); // RTS2 (BLE) -- USART2_RTS
97+
PC[08].configure(Some(E)); // CTS2 (BLE) -- USART2_CTS
98+
//PC[09].configure(None); //... NRF GPIO -- GPIO
99+
//PC[10].configure(None); //... USER LED -- GPIO
100+
PC[09].configure(Some(E)); // ACAN1 -- ACIFC comparator
101+
PC[10].configure(Some(E)); // ACAP1 -- ACIFC comparator
102+
PC[11].configure(Some(B)); // RX2 (BLE) -- USART2_RX
103+
PC[12].configure(Some(B)); // TX2 (BLE) -- USART2_TX
104+
//PC[13].configure(None); //... ACC_INT1 -- GPIO
105+
//PC[14].configure(None); //... ACC_INT2 -- GPIO
106+
PC[13].configure(Some(E)); //... ACBN1 -- ACIFC comparator
107+
PC[14].configure(Some(E)); //... ACBP1 -- ACIFC comparator
108+
PC[16].configure(None); //... SENSE_PWR -- GPIO pin
109+
PC[17].configure(None); //... NRF_PWR -- GPIO pin
110+
PC[18].configure(None); //... RF233_PWR -- GPIO pin
111+
PC[19].configure(None); //... TRNG_PWR -- GPIO Pin
112+
PC[22].configure(None); //... KERNEL LED -- GPIO Pin
113+
PC[24].configure(None); //... USER_BTN -- GPIO Pin
114+
PC[25].configure(Some(B)); // LI_INT -- EIC EXTINT2
115+
PC[26].configure(None); //... D7 -- GPIO Pin
116+
PC[27].configure(None); //... D6 -- GPIO Pin
117+
PC[28].configure(None); //... D5 -- GPIO Pin
118+
PC[29].configure(None); //... D4 -- GPIO Pin
119+
PC[30].configure(None); //... D3 -- GPIO Pin
120+
PC[31].configure(None); //... D2 -- GPIO Pin
121+
}
122+
123+
#[no_mangle]
124+
pub unsafe fn reset_handler() {
125+
sam4l::init();
126+
127+
sam4l::pm::PM.setup_system_clock(sam4l::pm::SystemClockSource::PllExternalOscillatorAt48MHz {
128+
frequency: sam4l::pm::OscillatorFrequency::Frequency16MHz,
129+
startup_mode: sam4l::pm::OscillatorStartup::FastStart,
130+
});
131+
132+
// Source 32Khz and 1Khz clocks from RC23K (SAM4L Datasheet 11.6.8)
133+
sam4l::bpm::set_ck32source(sam4l::bpm::CK32Source::RC32K);
134+
135+
set_pin_primary_functions();
136+
137+
// Create main kernel object. This contains the main loop function.
138+
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
139+
140+
// Initialize USART3 for Uart
141+
sam4l::usart::USART3.set_mode(sam4l::usart::UsartMode::Uart);
142+
143+
pub static mut PAGEBUFFER: sam4l::flashcalw::Sam4lPage = sam4l::flashcalw::Sam4lPage::new();
144+
145+
sam4l::flashcalw::FLASH_CONTROLLER.configure();
146+
let bootloader = static_init!(
147+
bootloader::bootloader::Bootloader<
148+
'static,
149+
sam4l::usart::USART,
150+
sam4l::flashcalw::FLASHCALW,
151+
sam4l::gpio::GPIOPin,
152+
>,
153+
bootloader::bootloader::Bootloader::new(
154+
&sam4l::usart::USART3,
155+
&mut sam4l::flashcalw::FLASH_CONTROLLER,
156+
&sam4l::gpio::PB[06],
157+
&mut PAGEBUFFER,
158+
&mut bootloader::bootloader::BUF
159+
)
160+
);
161+
hil::uart::UART::set_client(&sam4l::usart::USART3, bootloader);
162+
hil::flash::HasClient::set_client(&sam4l::flashcalw::FLASH_CONTROLLER, bootloader);
163+
164+
let imix = ImixBootloader {
165+
bootloader: bootloader,
166+
};
167+
168+
let chip = static_init!(sam4l::chip::Sam4l, sam4l::chip::Sam4l::new());
169+
170+
imix.bootloader.initialize();
171+
172+
let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
173+
board_kernel.kernel_loop(&imix, chip, None, &main_loop_capability);
174+
}
175+
176+
/// Panic handler.
177+
#[cfg(not(test))]
178+
#[no_mangle]
179+
#[panic_implementation]
180+
pub unsafe extern "C" fn panic_fmt(_pi: &PanicInfo) -> ! {
181+
loop {}
182+
}

0 commit comments

Comments
 (0)