Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SiSpeed MAIX BIT (with mic) #3

Open
chutchinson opened this issue Aug 18, 2020 · 10 comments
Open

SiSpeed MAIX BIT (with mic) #3

chutchinson opened this issue Aug 18, 2020 · 10 comments

Comments

@chutchinson
Copy link

chutchinson commented Aug 18, 2020

I'm trying to write firmware for the Sispeed MAix BiT (with microphone); for a thermostat controller, using these crates, with an interest in providing examples or possibly contributing to cargo-flash in order to help automate the flashing process. That's just a bit out of my league at the moment, but those are my aspirations.

I can compile the blinky example and flash it to the device; however, no blinks. A similar program written in the Arduino IDE (C, of course) and flashed to the device (FLASH, instead of SRAM), works fine. Do I need to make an adjustment to the memory map? Are there any considerations for this specific device? Is anyone patient enough to point me to the section of the datasheet that has the answers? I'm willing to put the work in I just don't know where to start.

This is the datasheet referenced by the product SKU:

https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte_datasheet_20181011163248_en.pdf

https://dl.sipeed.com/MAIX/HDK/Sipeed-Maix-Bit/Maix-Bit%20V2.0(with%20MEMS%20microphone)

@chutchinson
Copy link
Author

chutchinson commented Aug 19, 2020

Okay, so it turns out that the ELF binary produced by Rust is based at address 0xffffffff80000000 instead of 0x80000000. I was unable to get OpenOCD to work, so I was relying on kflash. I ended up patching kflash to mask away the upper bits when flashing dataframes:

# kflash.py 1041
# self.flash_dataframe(segment.data(), segment['p_vaddr'])
self.flash_dataframe(segment.data(), segment['p_vaddr'] & 0xffffffff)

@diogoviannaaraujo
Copy link

@chutchinson Patched kflash.py as you described but still no Blinky blink, have you done any other modifications?

Im not in the default submodules commits, I've checkout master on examples and also on Hal and pac and rt, so it would compile. In what commits are your submodules at?

@chutchinson
Copy link
Author

@diogoviannaaraujo I am using master of hal/pac/rt; unfortunately there's quite a lot to get right for the build process, and it looks like these K210 crates are still very experimental. I am looking into providing support for the on-board FT2232 in cargo-flash, but until then...

Make sure you have the appropriate linker scripts for the K210 memory layout, and wired into the build process (.cargo/config, build.rs). In the repository these are memory.x and memory-k210.x linker scripts. Other than that, I am using cargo-binutils (objcopy) in conjunction with kflash to flash. My MAIX BIT appears to be a newer variant and is identified by kflash as a Maixduino.

Supposedly newer versions of kflash can directly flash an ELF binary, and nightly versions of rustc can compile RISC-V binaries with the medium code model (-mcmodel=medium) which can generate code with an 0x80000000 section base address. I will be looking into that soon.

# install with "cargo install cargo-binutils"
# build program in release mode and transform ELF binary into raw binary
cargo objcopy --release -- -O binary main.bin
# flash to SRAM (may need to specify dan/bit here)
./kflash.py -s -p /dev/ttyS13 -B maixduino "./main.bin"

@chutchinson
Copy link
Author

Okay, so using stable Rust 1.43 I can confirm that compiling with a static relocation model and medium code model results in a functional executable. An unpatched kflash is able to flash the resulting executable; if you patched the linker scripts to use higher memory addresses you can instead go back to the datasheet values.

My cargo configuration looks like this:

[target.riscv64gc-unknown-none-elf]
rustflags = [
  "-C", "link-arg=-Tmemory.x",
  "-C", "link-arg=-Tlink.x",
  "-C", "code-model=medium",
  "-C", "relocation-model=static",
]

[build]
target = "riscv64gc-unknown-none-elf"

And the k210 memory linker script (memory-k210.x):

_max_hart_id = 1;

MEMORY
{
    SRAM : ORIGIN = 0x80000000, LENGTH = 6M
    AI_SRAM : ORIGIN = 0x80600000, LENGTH = 2M
    SRAM_NOCACHE : ORIGIN = 0x40000000, LENGTH = 6M
    AI_SRAM_NOCACHE : ORIGIN = 0x40600000, LENGTH = 2M
}

@diogoviannaaraujo
Copy link

diogoviannaaraujo commented Aug 27, 2020

Nice, will give a try later. I was able to compile and convert to .bin with riscv-utils from brew. Flashing seemed to happen ok but no Blinky... Hope this new information can make a change on that.

Thanks <3

@chutchinson
Copy link
Author

@diogoviannaaraujo any progress on flashing your device?

@diogoviannaaraujo
Copy link

No, tried as described above but had no luck. The software flashes but nothing happens.

Bought a st-link v2 to try to use openocd instead of kflash, must be arriving today.

@chutchinson
Copy link
Author

@diogoviannaaraujo perhaps try modifying the sample to use a different IO pin? The Maixduino doesn't appear to have a dedicated RGB LED like the MAIX BIT, for example. You could try changing the IO pin to 12/13/14, or if you're testing on a Maixduino, IO pin 1:

https://github.com/sipeed/Maixduino/search?q=LED_BUILTIN&unscoped_q=LED_BUILTIN

@chutchinson
Copy link
Author

I added a repository with a blink example that works both on the Maixduino and MAIX BIT. I'm not sure which device you have, but it appears the example in this repository is not designed for a Maixduino. That device does not appear to have an RGB LED, and instead has LEDs for monitoring the RX/TX pins.

If you look at the datasheet, you can see that TX is on IO5:

https://www.waveshare.com/w/upload/8/89/Sipeed_Maixduino_Datasheet_V1.0.pdf

Here is my repository:

https://github.com/chutchinson/k210-examples

@diogoviannaaraujo
Copy link

diogoviannaaraujo commented Sep 5, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants