This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Add a basic example which blinks an LED #10
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[target.xtensa-esp32-none-elf] | ||
runner = "xtensa-esp32-elf-gdb -q -x xtensa.gdb" | ||
|
||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-nostartfiles", | ||
"-C", "link-arg=-Wl,-Tlink.x", | ||
] | ||
target = "xtensa-esp32-none-elf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
// Put the linker script somewhere the linker can find it | ||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
File::create(out.join("memory.x")) | ||
.unwrap() | ||
.write_all(include_bytes!("memory.x")) | ||
.unwrap(); | ||
println!("cargo:rustc-link-search={}", out.display()); | ||
|
||
// Only re-run the build script when memory.x is changed, | ||
// instead of when any part of the source code changes. | ||
println!("cargo:rerun-if-changed=memory.x"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate esp32_hal as hal; | ||
extern crate panic_halt; | ||
extern crate xtensa_lx6_rt; | ||
|
||
use hal::prelude::*; | ||
use xtensa_lx6_rt::get_cycle_count; | ||
|
||
/// The default clock source is the onboard crystal | ||
/// In most cases 40mhz (but can be as low as 2mhz depending on the board) | ||
const CORE_HZ: u32 = 40_000_000; | ||
|
||
const WDT_WKEY_VALUE: u32 = 0x50D83AA1; | ||
|
||
#[no_mangle] | ||
fn main() -> ! { | ||
let dp = unsafe { hal::pac::Peripherals::steal() }; | ||
|
||
let mut rtccntl = dp.RTCCNTL; | ||
let mut timg0 = dp.TIMG0; | ||
let mut timg1 = dp.TIMG1; | ||
|
||
// (https://github.com/espressif/openocd-esp32/blob/97ba3a6bb9eaa898d91df923bbedddfeaaaf28c9/src/target/esp32.c#L431) | ||
// openocd disables the wdt's on halt | ||
// we will do it manually on startup | ||
disable_timg_wdts(&mut timg0, &mut timg1); | ||
disable_rtc_wdt(&mut rtccntl); | ||
|
||
let pins = dp.GPIO.split(); | ||
let mut led = pins.gpio2.into_open_drain_output(); | ||
|
||
loop { | ||
led.set_high().unwrap(); | ||
delay(CORE_HZ); | ||
led.set_low().unwrap(); | ||
delay(CORE_HZ); | ||
} | ||
} | ||
|
||
fn disable_rtc_wdt(rtccntl: &mut hal::pac::RTCCNTL) { | ||
/* Disables the RTCWDT */ | ||
rtccntl | ||
.wdtwprotect | ||
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) }); | ||
rtccntl.wdtconfig0.modify(|_, w| unsafe { | ||
w.wdt_stg0() | ||
.bits(0x0) | ||
.wdt_stg1() | ||
.bits(0x0) | ||
.wdt_stg2() | ||
.bits(0x0) | ||
.wdt_stg3() | ||
.bits(0x0) | ||
.wdt_flashboot_mod_en() | ||
.clear_bit() | ||
.wdt_en() | ||
.clear_bit() | ||
}); | ||
rtccntl.wdtwprotect.write(|w| unsafe { w.bits(0x0) }); | ||
} | ||
|
||
fn disable_timg_wdts(timg0: &mut hal::pac::TIMG0, timg1: &mut hal::pac::TIMG1) { | ||
timg0 | ||
.wdtwprotect | ||
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) }); | ||
timg1 | ||
.wdtwprotect | ||
.write(|w| unsafe { w.bits(WDT_WKEY_VALUE) }); | ||
|
||
timg0.wdtconfig0.write(|w| unsafe { w.bits(0x0) }); | ||
timg1.wdtconfig0.write(|w| unsafe { w.bits(0x0) }); | ||
} | ||
|
||
/// cycle accurate delay using the cycle counter register | ||
pub fn delay(clocks: u32) { | ||
// NOTE: does not account for rollover | ||
let target = get_cycle_count() + clocks; | ||
loop { | ||
if get_cycle_count() > target { | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Specify main memory areas */ | ||
MEMORY | ||
{ | ||
/* Use values from the ESP-IDF 'bootloader' component. | ||
/* TODO: Use human-readable lengths */ | ||
/* TODO: Use the full memory map - this is just a test */ | ||
/* vectors ( RX ) : ORIGIN = 0x40080000, len = 0x400 */ | ||
iram_seg ( RX ) : ORIGIN = 0x40080400, len = 0xFC00 | ||
dram_seg ( RW ) : ORIGIN = 0x3FFF0000, len = 0x1000 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't intend to change this but to keep this as a side note, in the PR #7 this can be calculated at run time depending on the clock source used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out. I'm fine with waiting until that PR has merged and updating the example if that's preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe merge this PR first because #7 has been superseded by #11