Giter Site home page Giter Site logo

ch32v00x-hal's Introduction

ch32v00x-hal

This is a WIP implementation of the embedded-hal traits for the CH32V0 family of microcontrollers.

  • CH32V003: Currently only chip in the family

UPDATE

CH641 is also a RISCV32EC core.

Peripheral status

  • PWR: Power control
  • RCC: Reset and Clock Control
  • IWDG: Independent Watchdog
  • WWDG: Window Watchdog
  • FPIC: Programmable Fast Interrupt Controller
  • GPIO: General Purpose Input/Output
  • AFIO: Alternate Function Input/Output
  • DMA: Direct Memory Access control
  • ADC: Analog to Digital Converter
  • ADTM: Advanced control Timer (TIM1)
  • GPTM: General Purpose Timer (TIM2)
  • USART: Universal Synchronous Asynchronous Receiver Transmitter
  • I2C: Inter-intergrated Circuit interface
  • SPI: Serial Peripheral Interface
  • ESIG: Electronic Signature
  • FLASH: Flash memory and user option bytes
  • EXTEND: Extended configuration
  • DBG: Debug support

Guide on Rust with riscv32ec

As of 2024-02-28, The RVE with +c extension for LLVM is merged and shipped with Rust nightly. Plese refer to .cargo/config.toml for the target override, and riscv32ec-unknown-none-elf.json for the target specification. Remember to use the latest nightly toolchain.

ch32v00x-hal's People

Contributors

andelf avatar merisy avatar noxime avatar fred314159265 avatar gnxlxnxx avatar david-sawatzke avatar lujoga avatar merisy-thing avatar 9names avatar agausmann avatar dicklessgreat avatar garbaz avatar

Stargazers

plops avatar  avatar Romain Reignier avatar  avatar  avatar Crispy avatar  avatar  avatar Marcus Ramse avatar Chris S avatar Nobuyuki Ishii avatar Decaday avatar CuprumWangzuo avatar  avatar Vladimir Roncevic avatar  avatar Sezercan avatar jershell avatar  avatar  avatar  avatar Elias Sjögreen avatar  avatar 第二扩展 avatar Vitaly Domnikov avatar  avatar

Watchers

Andreas Gnau avatar Vladimir Roncevic avatar  avatar  avatar  avatar  avatar  avatar  avatar

ch32v00x-hal's Issues

Can I enable sdi print on probe-rs?

I tried debug example on VSCode using probe-rs.
I found it result in infinite loop at first println!
call stack:

read_volatile<u32> #[inline] (...rustlib\src\rust\library\core\src\ptr\mod.rs:1580)
is_busy #[inline] (...\ch32v00x-hal-d817920771731cf2\cdd79fc\src\debug.rs:23)
write_str (...\ch32v00x-hal-d817920771731cf2\cdd79fc\src\debug.rs:38)
write (...\rustlib\src\rust\library\core\src\fmt\mod.rs:1144)
unwrap<(), core::fmt::Error> #[inline] (...\rustlib\src\rust\library\core\src\result.rs:1071)
__risc_v_rt__main (...\ch32v00x-hal-d817920771731cf2\cdd79fc\src\debug.rs:57)
<unknown function @ 0x20000018> (Unknown Source:0)

seems like DEBUG_DATA would not flush 0 and SDIPrint is always busy.

I tried the same program with wlink -v flash path/to/debug_program --enable-sdi-print --watch-serial and it works fine.
So I think probe-rs's setting is something wrong.
My current launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "preLaunchTask": "rust: cargo build",
            "type": "probe-rs-debug",
            "request": "launch",
            "name": "my_program",
            "cwd": "${workspaceFolder}",
            "chip": "ch32v003",
            "connectUnderReset": false,
            "speed": 4000,
            "flashingConfig": {
                "flashingEnabled": true,
                "resetAfterFlashing": true,
                "haltAfterReset": true,
            },
            "coreConfigs": [
                {
                    "programBinary": "path/to/debug_program",
                    "chip": "ch32v003",
                    "rttEnabled": true,
                    "options": {
                        "env": {
                            "DEFMT_LOG": "debug"
                        }
                    },
                }
            ],
            "consoleLogLevel": "Info", //Error, Warn, Info, Debug, Trace
            "wireProtocol": "Jtag"
        }
    ]
}

Blinky example: Flashing appears to work, but no action on PD6

Hi,

I have the CH32V00F4P6-R0-1v1 board & WCH-LinkE.

Running cargo run --release --example=blinky I get a promising output:

warning: Patch `riscv-rt v0.11.0 (https://github.com/9names/riscv-rt?branch=rv32e#963b8965)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: field `clocks` is never read
  --> src/pwr.rs:21:5
   |
19 | pub struct Pwr {
   |            --- field in this struct
20 |     pwr: PWR,
21 |     clocks: Clocks,
   |     ^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `ch32v00x-hal` (lib) generated 1 warning
    Finished `release` profile [optimized] target(s) in 0.06s
     Running `wlink -v flash --enable-sdi-print target/rv32ec/release/examples/blinky`
21:38:06 [DEBUG] (1) wlink::usb_device::libusb: Serial number: "BA3C8F063F12"
21:38:06 [INFO] Connected to WCH-Link v2.11(v31) (WCH-LinkE-CH32V305)
21:38:06 [INFO] Attached chip: CH32V003 [CH32V003F4P6] (ChipID: 0x00300500)
21:38:06 [INFO] Chip UID: cd-ab-a4-c0-11-bc-82-28
21:38:06 [INFO] Flash protected: false
21:38:06 [INFO] Read target/rv32ec/release/examples/blinky as ELF format
21:38:06 [DEBUG] (1) wlink::firmware: Found loadable segment, physical address: 0x00000000, virtual address: 0x00000000, flags: 0x5
21:38:06 [DEBUG] (1) wlink::firmware: Matching section: ".init" offset: 0x1000 size: 0x4
21:38:06 [DEBUG] (1) wlink::firmware: Section names: [".init"]
21:38:06 [DEBUG] (1) wlink::firmware: Found loadable segment, physical address: 0x00000004, virtual address: 0x00000004, flags: 0x4
21:38:06 [DEBUG] (1) wlink::firmware: Matching section: ".vector_table" offset: 0x1004 size: 0x98
21:38:06 [DEBUG] (1) wlink::firmware: Section names: [".vector_table"]
21:38:06 [DEBUG] (1) wlink::firmware: Found loadable segment, physical address: 0x0000009c, virtual address: 0x0000009c, flags: 0x5
21:38:06 [DEBUG] (1) wlink::firmware: Matching section: ".text" offset: 0x109c size: 0x266
21:38:06 [DEBUG] (1) wlink::firmware: Section names: [".text"]
21:38:06 [DEBUG] (1) wlink::firmware: Found loadable segment, physical address: 0x00000304, virtual address: 0x00000304, flags: 0x4
21:38:06 [DEBUG] (1) wlink::firmware: Matching section: ".rodata" offset: 0x1304 size: 0x3a
21:38:06 [DEBUG] (1) wlink::firmware: Section names: [".rodata"]
21:38:06 [DEBUG] (1) wlink::firmware: found 4 sections
21:38:06 [INFO] Flashing 830 bytes to 0x08000000
21:38:06 [DEBUG] (1) wlink::operations: Reattach chip
21:38:06 [DEBUG] (1) wlink::operations: Reattach chip
21:38:07 [INFO] Read protected: false
21:38:07 [DEBUG] (1) wlink::operations: Using write pack size 1024 data pack size 64
21:38:07 [DEBUG] (1) wlink::operations: Flash OP written
███████████████████████████████████████████████████████████ 830/830
21:38:07 [DEBUG] (1) wlink::operations: Fastprogram done
21:38:07 [INFO] Flash done
21:38:07 [INFO] Now reset...
21:38:07 [INFO] Now connect to the WCH-Link serial port to read SDI print

but sadly there is no action whatsoever on PD6.

Any ideas why that might be?

I should add: I have rustc nightly and wlink both up to date.

I'll next try getting a blinky example running from ch32v003fun, just to be sure that it's not my board that's the problem.

SPI feature request

Hi @andelf this is an awesome project, thank you for all the work on ch320-rs.

I there a plan for SPI support in the near future?

I'd like to contribute but am still learning the basics of embedded development and will likely not be able to implement the protocol, however if I can assist with simple testing please let me know.

possibly helpful resource

**note my target peripheral is the nrf24l01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.