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 1 commit
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,10 @@ | ||
[target.xtensa-esp32-none-elf] | ||
runner = "xtensa-esp32-elf-gdb -q -x xtensa.gdb" | ||
|
||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-nostartfiles", | ||
"-C", "debuginfo=0", # not 2 | ||
"-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,94 @@ | ||
#![no_std] | ||
#![no_main] | ||
#![feature(asm)] | ||
|
||
extern crate esp32_hal as hal; | ||
extern crate panic_halt; | ||
extern crate xtensa_lx6_rt; | ||
|
||
use hal::prelude::*; | ||
|
||
/// 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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_ccount() + clocks; | ||
loop { | ||
if get_ccount() > target { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/// Performs a special register read to read the current cycle count. | ||
/// In the future, this can be precompiled to a archive (.a) and linked to so we don't | ||
/// have to require the asm nightly feature - see cortex-m-rt for more details | ||
pub fn get_ccount() -> u32 { | ||
jessebraham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let x: u32; | ||
unsafe { asm!("rsr.ccount a2" : "={a2}"(x) ) }; | ||
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,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.
This is no longer required, the new llvm fork supports debug info.
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.
Just for clarification, am I removing the entire
rustflags
array, its first 2 elements, or just thedebuginfo
line?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.
@MabezDev Which exact llvm fork are you using? If I use https://github.com/espressif/llvm-project/tree/xtensa_release_9.0.1 I still get CFI not supported errors.
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.
@arjanmels I'm using that fork; it should work. Note that if you're trying to compile .S assembly files, it will be passed to the gcc assembler at the moment, which will produce these errors. Inline assembly works though.
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.
Strange, not working for me. I recompiled llvm and rust, but no luck, must be missing something.
This is what I get if I check my version (afraid it may not be super helpfull:
$RUSTC --version --verbose
rustc 1.44.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.44.0-dev
LLVM version: 9.0
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.
That is weird, so you can't create debug info at all? I've defintely got it working on my machine: espressif/llvm-project#10 (comment)
Ive been pretty tied up this week, but today I've been revisiting the rust fork, looking to improve the ABI calls, and use the built in llvm module, which might fix your issue.
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.
No debug info not working for me. If I understand your comment for espressif/llvm-project#10 (comment) correct you are working with a local rebase, so theoretically could be something different?
More likely that I did something wrong perhaps, but I don't know what. Anyway I am managing ok without the debugger at the moment as I have the serial output up and running, but debugger would be nice of course.
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.
That rebase was temporary, the current default branch of the fork has the correct changes in it.