Skip to content

Instantly share code, notes, and snippets.

View MabezDev's full-sized avatar
🦀
I may be slow to respond.

Scott Mabin MabezDev

🦀
I may be slow to respond.
View GitHub Profile
@MabezDev
MabezDev / 1.md
Last active October 23, 2018 17:10
Create a 16bit R5G6B5 raw image for embedded displays.
  • Import your image or create image with GIMP.

  • Export as bmp -> advanced options -> 16bit

  • Then to get the raw bytes run tail -c $bytes image.bmp > image.raw where $bytes is w * h * 2 of the image. This removes the BMP header.

Bootstrapping Rust with xtensa support

Build xtensa llvm from here https://esp32.com/viewtopic.php?t=9226&p=38466

But add the X86 target like so

cmake ../llvm-xtensa -DLLVM_TARGETS_TO_BUILD="Xtensa;X86" -DCMAKE_BUILD_TYPE=Release -G "Ninja"
/// Feed the WDT watchdog
pub fn feed_wdt() {
const RTC_WDT_BASE: u32 = 0x3ff48000;
const RTC_WDT_WPROTECT: u32 = RTC_WDT_BASE + 0xa4;
const RTC_WDT_FEED: u32 = RTC_WDT_BASE + 0xa0;
unsafe {
core::ptr::write_volatile(RTC_WDT_WPROTECT as *mut _, 0); // disable write protection
{
core::ptr::write_volatile(RTC_WDT_FEED as *mut _, 0x1); // feed the watch dog

To find the substitute path for the from section:

find $(rustc --print sysroot) -maxdepth 2 -mindepth 2  -type f -name "libstd-*" -exec strings {} \; | grep -o '^/rustc/[^/]\+/' | uniq

which produces something like /rustc/9a90d03ad171856dc016c2dcc19292ec49a8a26f/

Next install rust-src component if you haven't already. Then combine the output of rustc --print sysroot with /lib/rustlib/src/rust to find your downloaded sources.

use rtfm::Mutex; // or mutex_trait
pub enum Operation<T: Mutex<T = ...> {
FileSystem(T) // Note: can't use impl Mutex<T = Filesystem> here, so we have to introduce the T type param
// ...
}
// If the `Operation` enum is buried deep within a type, it poisens that type with the same type parameter
pub struct Server<T: Mutex<T = ...> {
op: Operation<T>
#[naked]
#[no_mangle]
#[link_section = ".rwtext"]
unsafe extern "C" fn save_context() {
asm!(
"
s32i a2, sp, +XT_STK_A2
s32i a3, sp, +XT_STK_A3
s32i a4, sp, +XT_STK_A4
s32i a5, sp, +XT_STK_A5
  1. Clone https://github.com/esp-rs/rust
  2. Ensure deps are met before starting the installation process, see the README.
  3. Run ./configure --experimental-targets=Xtensa --release-channel=nightly --enable-extended --tools=clippy,cargo,rustfmt
  4. Start the build with ./x.py build --stage 2
  5. Link the custom toolchain to rustup:
       rustup toolchain link esp build/$HOST/stage2
    

Where $HOST is your machines triple, i.e x86_64-unknown-linux-gnu

ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x420182d6
0x420182d6 - _ZN14esp_hal_common7embassy11time_driver12EmbassyTimer3now17hdd745a8ad9f1c59cE
at ??:??
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x16ec
0x3fcd5820 - _stack_start
//! embassy wait
//!
//! This is an example of asynchronously `Wait`ing for a pin state to change.
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use embassy_executor::Executor;
use embassy_time::{Duration, Timer};