Skip to content

Commit 649e7a5

Browse files
committed
Update docs on adding new chip support. Regen yaml
1 parent df62968 commit 649e7a5

File tree

5 files changed

+61
-74
lines changed

5 files changed

+61
-74
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,40 @@ $ target-gen elf target/$(RUST_TARGET)/release/esp-flashloader output/esp32.yaml
1010
```
1111

1212
Example for the updating the `esp32c3` flash algorithm.
13+
1314
```bash
1415
$ cargo build --release --features esp32c3 --target riscv32imc-unknown-none-elf
1516
$ target-gen elf target/riscv32imc-unknown-none-elf/release/esp-flashloader output/esp32.yaml --update --name esp32c3-flashloader
16-
```
17+
```
18+
19+
## Chip support
20+
21+
|name |supported|
22+
|-------|---------|
23+
|esp32c3| Y |
24+
25+
## Adding new chips
26+
27+
1. Add a feature for the chip inside `Cargo.toml`
28+
2. Add the ROM API linker script inside the `ld` directory.
29+
3. Inside the ROM API linker script, add a memory section detailing where the program will be loaded.
30+
```c
31+
MEMORY {
32+
/* Start 64k into the RAM region */
33+
IRAM : ORIGIN = 0x40390000, LENGTH = 0x40000
34+
}
35+
```
36+
It's important to note that the algorithm cannot be loaded at the start of RAM, because probe-rs has a header it loads prior to the algo hence the 64K offset.
37+
4. Add the following snippet to the bottom of the `main()` function inside `build.rs`, adapting it for the new chip name.
38+
```rust
39+
#[cfg(feature = "esp32c3")]
40+
{
41+
fs::copy("ld/esp32c3.x", out_dir.join("esp32c3.x")).unwrap();
42+
println!("cargo:rerun-if-changed=ld/esp32c3.x");
43+
println!("cargo:rustc-link-arg=-Tld/esp32c3.x");
44+
}
45+
```
46+
5. Follow the instructions above for building
47+
6. Use `target-gen` _without_ the `update` flag to generate a new yaml algorithm.
48+
7. merge the new flash algorithm into the the main `esp32.yaml`
49+
8. Upstream the new updates to probe-rs.

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ fn main() {
1414
println!("cargo:rerun-if-changed=ld/esp32c3.x");
1515
println!("cargo:rustc-link-arg=-Tld/esp32c3.x");
1616
}
17-
}
17+
}

build.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

output/esp32.yaml

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
name: "esp32"
2+
name: esp32
33
manufacturer: ~
44
variants:
5-
- name: "esp32c3"
5+
- name: esp32c3
66
part: ~
77
cores:
88
- name: main
@@ -12,51 +12,49 @@ variants:
1212
memory_map:
1313
- Nvm:
1414
range:
15-
start: 0x0
16-
end: 0x800000
15+
start: 0
16+
end: 8388608
1717
is_boot_memory: true
18-
cores:
18+
cores:
1919
- main
20-
- Ram: # Instruction bus access
20+
- Ram:
2121
range:
22-
start: 0x40380000
23-
end: 0x403E0000
22+
start: 1077411840
23+
end: 1077805056
2424
is_boot_memory: false
25-
cores:
25+
cores:
2626
- main
27-
- Ram: # Data bus access
27+
- Ram:
2828
range:
29-
start: 0x3FC80000
30-
end: 0x3FC90000
29+
start: 1070071808
30+
end: 1070137344
3131
is_boot_memory: false
32-
cores:
32+
cores:
3333
- main
3434
flash_algorithms:
3535
- esp32c3-flashloader
3636
flash_algorithms:
37-
- esp-flashloader:
38-
name: esp32c3-flashloader
39-
cores:
40-
- main
41-
description: "A flash loader for the esp32c3."
37+
- name: esp32c3-flashloader
38+
description: A flash loader for the esp32c3.
4239
default: true
4340
instructions: QREGxjcFOUADRQUHGcEBRS2glwDH/+eAoHCBRZcAx//ngIAUlwDH/+eAwBEZ5QFFtwU5QAVGI4jFBrJAQQGCgDGBFwPH/2cAYw4XA8f/ZwBjDRN3NgABxxMFoAqCgK6GsoU2hhcDx/9nAIMMAUWCgAAAAAA=
44-
pc_init: 1
45-
pc_uninit: 109
46-
pc_program_page: 83
47-
pc_erase_sector: 65
48-
pc_erase_all: 75
41+
load_address: 1077477376
42+
pc_init: 0
43+
pc_uninit: 108
44+
pc_program_page: 82
45+
pc_erase_sector: 64
46+
pc_erase_all: 74
4947
data_section_offset: 116
50-
load_address: 0x40390000
5148
flash_properties:
5249
address_range:
53-
start: 0x0
54-
end: 0x800000
50+
start: 0
51+
end: 67108864
5552
page_size: 2048
5653
erased_byte_value: 255
5754
program_page_timeout: 1000
5855
erase_sector_timeout: 2000
5956
sectors:
6057
- size: 4096
6158
address: 0
62-
59+
cores:
60+
- main

src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@ extern "C" {
7373
fn esp_rom_spiflash_erase_chip() -> i32;
7474
fn esp_rom_spiflash_erase_block(block_number: u32) -> i32;
7575
fn esp_rom_spiflash_erase_sector(sector_number: u32) -> i32;
76-
7776
/// address (4 byte alignment), data, length
7877
fn esp_rom_spiflash_write(dest_addr: u32, data: *const u8, len: u32) -> i32;
7978
/// address (4 byte alignment), data, length
8079
fn esp_rom_spiflash_read(src_addr: u32, data: *const u32, len: u32) -> i32;
81-
8280
fn esp_rom_spiflash_unlock() -> i32;
8381
// fn esp_rom_spiflash_lock(); // can't find in idf defs?
84-
8582
fn esp_rom_spiflash_attach(config: u32, legacy: bool);
8683

8784
fn uart_tx_one_char(byte: u8);
@@ -169,7 +166,7 @@ pub static FlashDevice: FlashDeviceDescription = FlashDeviceDescription {
169166
dev_name: [0u8; 128],
170167
dev_type: 5,
171168
dev_addr: 0x0,
172-
device_size: 0x4_000_000, /* set to max of 64MB */
169+
device_size: u32::MAX, /* Set to max, is limited by NVM size */
173170
page_size: 2048,
174171
_reserved: 0,
175172
empty: 0xFF,

0 commit comments

Comments
 (0)