├── .gitignore ├── docs └── blash-rtt.gif ├── .vscode └── settings.json ├── .cargo └── config ├── Cargo.toml ├── README.md ├── memory.x ├── src └── main.rs └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /docs/blash-rtt.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjoernQ/bl602-rtt-example/main/docs/blash-rtt.gif -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf", 3 | "rust-analyzer.checkOnSave.allTargets": false 4 | } -------------------------------------------------------------------------------- /.cargo/config: -------------------------------------------------------------------------------- 1 | [target.riscv32imc-unknown-none-elf] 2 | rustflags = [ 3 | "-C", "link-arg=-Tmemory.x", 4 | "-C", "link-arg=-Tlink.x", 5 | "-C", "link-arg=-Thal_defaults.x", 6 | ] 7 | runner = "blash --rtt --" 8 | 9 | [build] 10 | target = "riscv32imc-unknown-none-elf" 11 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bl602-rtt-test" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | riscv-rt = "0.8.0" 8 | bl602-hal = { git = "https://github.com/sipeed/bl602-hal", branch="main" } 9 | riscv = "0.7.0" 10 | embedded-time = "0.12.0" 11 | nb = "1.0.0" 12 | blash-target = { git = "https://github.com/bjoernQ/blash-target", branch="main", features = ["panic_backtrace", "exception_backtrace"] } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BL602 RTT Example 2 | 3 | On the host side you have to use [blash](https://github.com/bjoernQ/blash) with the `rtt` option. (At the time of writing it's on a branch, not on `main` - please use the branch `backtrace`) 4 | 5 | A simple `cargo run` should flash the binary via `blash` and show the output. 6 | 7 | ![BL602 RTT](docs/blash-rtt.gif) 8 | 9 | To see full backtraces you should compile and run like this: `cargo run -Z build-std=core --target riscv32imc-unknown-none-elf` 10 | 11 | Uncomment the relevant parts in `main.rs` to make the code panic. 12 | -------------------------------------------------------------------------------- /memory.x: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | ROM (rx) : ORIGIN = 0x21000000, LENGTH = 128K 4 | ITCM (wxa) : ORIGIN = 0x22008000, LENGTH = 48K 5 | DTCM (wxa) : ORIGIN = 0x22014000, LENGTH = 48K 6 | XIP_FLASH (rwx) : ORIGIN = 0x23000000, LENGTH = 16M 7 | WIFI_RAM (wxa) : ORIGIN = 0x42030000, LENGTH = 112K 8 | } 9 | 10 | REGION_ALIAS("REGION_TEXT", XIP_FLASH); 11 | REGION_ALIAS("REGION_RODATA", XIP_FLASH); 12 | REGION_ALIAS("REGION_DATA", DTCM); 13 | REGION_ALIAS("REGION_BSS", DTCM); 14 | REGION_ALIAS("REGION_HEAP", DTCM); 15 | REGION_ALIAS("REGION_STACK", DTCM); -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![no_main] 3 | 4 | use bl602_hal as hal; 5 | use blash_target::{init_print, println}; 6 | use hal::{ 7 | clock::{Strict, SysclkFreq, UART_PLL_FREQ}, 8 | pac, 9 | prelude::*, 10 | }; 11 | 12 | #[riscv_rt::entry] 13 | fn main() -> ! { 14 | init_print!(); 15 | 16 | let dp = pac::Peripherals::take().unwrap(); 17 | let mut parts = dp.GLB.split(); 18 | 19 | // Set up all the clocks we need 20 | let _clocks = Strict::new() 21 | .use_pll(40_000_000u32.Hz()) 22 | .sys_clk(SysclkFreq::Pll160Mhz) 23 | .uart_clk(UART_PLL_FREQ.Hz()) 24 | .freeze(&mut parts.clk_cfg); 25 | 26 | println!("Start"); 27 | 28 | // panic!("You should see a backtrace in blash in case of a panic!"); 29 | 30 | // uncomment code below to trigger a "Load address misaligned" error 31 | // let _foo = unsafe { 32 | // let foo = 0x22010001 as *mut u32; 33 | // *foo as u32 34 | // }; 35 | 36 | let mut i = 0; 37 | 38 | loop { 39 | println!("Hello BL602!"); 40 | println!("Hello, world! Count is {}", i); 41 | i += 1; 42 | for _ in 0..250000 {} 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.7.18" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "autocfg" 16 | version = "1.0.1" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 19 | 20 | [[package]] 21 | name = "bare-metal" 22 | version = "0.2.5" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" 25 | dependencies = [ 26 | "rustc_version", 27 | ] 28 | 29 | [[package]] 30 | name = "bare-metal" 31 | version = "1.0.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" 34 | 35 | [[package]] 36 | name = "bit_field" 37 | version = "0.10.1" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" 40 | 41 | [[package]] 42 | name = "bl602-hal" 43 | version = "0.1.0" 44 | source = "git+https://github.com/sipeed/bl602-hal?branch=main#b67370136d5bb14192caef1df9041f0601a4fbc6" 45 | dependencies = [ 46 | "bl602-pac", 47 | "embedded-hal 0.2.6", 48 | "embedded-hal 1.0.0-alpha.5", 49 | "embedded-time", 50 | "nb 1.0.0", 51 | "paste", 52 | "riscv 0.6.0", 53 | "riscv-target", 54 | ] 55 | 56 | [[package]] 57 | name = "bl602-pac" 58 | version = "0.1.0" 59 | source = "git+https://github.com/sipeed/bl602-pac?branch=main#4c8e69856b39a505714bc4e636705a7be858b50b" 60 | dependencies = [ 61 | "bare-metal 1.0.0", 62 | "riscv 0.6.0", 63 | "vcell", 64 | ] 65 | 66 | [[package]] 67 | name = "bl602-rtt-test" 68 | version = "0.1.0" 69 | dependencies = [ 70 | "bl602-hal", 71 | "blash-target", 72 | "embedded-time", 73 | "nb 1.0.0", 74 | "riscv 0.7.0", 75 | "riscv-rt", 76 | ] 77 | 78 | [[package]] 79 | name = "blash-target" 80 | version = "0.1.0" 81 | source = "git+https://github.com/bjoernQ/blash-target?branch=main#a43a25edd641c0fdd46d37625270503645f143a9" 82 | dependencies = [ 83 | "bl602-hal", 84 | "jlink_rtt", 85 | "riscv 0.7.0", 86 | ] 87 | 88 | [[package]] 89 | name = "embedded-hal" 90 | version = "0.2.6" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "e36cfb62ff156596c892272f3015ef952fe1525e85261fa3a7f327bd6b384ab9" 93 | dependencies = [ 94 | "nb 0.1.3", 95 | "void", 96 | ] 97 | 98 | [[package]] 99 | name = "embedded-hal" 100 | version = "1.0.0-alpha.5" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | checksum = "a554c04648665230499563ccdfd1fcd719ef2d5a0af54bdc81c5d877fb556db4" 103 | dependencies = [ 104 | "nb 1.0.0", 105 | ] 106 | 107 | [[package]] 108 | name = "embedded-time" 109 | version = "0.12.1" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | checksum = "d7a4b4d10ac48d08bfe3db7688c402baadb244721f30a77ce360bd24c3dffe58" 112 | dependencies = [ 113 | "num", 114 | ] 115 | 116 | [[package]] 117 | name = "jlink_rtt" 118 | version = "0.2.0" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | checksum = "42f6af40154f64bd7095b5245d6933fef99b0a28c432b38a676cfafaa0aedfc2" 121 | 122 | [[package]] 123 | name = "lazy_static" 124 | version = "1.4.0" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 127 | 128 | [[package]] 129 | name = "memchr" 130 | version = "2.4.1" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 133 | 134 | [[package]] 135 | name = "nb" 136 | version = "0.1.3" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" 139 | dependencies = [ 140 | "nb 1.0.0", 141 | ] 142 | 143 | [[package]] 144 | name = "nb" 145 | version = "1.0.0" 146 | source = "registry+https://github.com/rust-lang/crates.io-index" 147 | checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" 148 | 149 | [[package]] 150 | name = "num" 151 | version = "0.3.1" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f" 154 | dependencies = [ 155 | "num-complex", 156 | "num-integer", 157 | "num-iter", 158 | "num-rational", 159 | "num-traits", 160 | ] 161 | 162 | [[package]] 163 | name = "num-complex" 164 | version = "0.3.1" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5" 167 | dependencies = [ 168 | "num-traits", 169 | ] 170 | 171 | [[package]] 172 | name = "num-integer" 173 | version = "0.1.44" 174 | source = "registry+https://github.com/rust-lang/crates.io-index" 175 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" 176 | dependencies = [ 177 | "autocfg", 178 | "num-traits", 179 | ] 180 | 181 | [[package]] 182 | name = "num-iter" 183 | version = "0.1.42" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" 186 | dependencies = [ 187 | "autocfg", 188 | "num-integer", 189 | "num-traits", 190 | ] 191 | 192 | [[package]] 193 | name = "num-rational" 194 | version = "0.3.2" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" 197 | dependencies = [ 198 | "autocfg", 199 | "num-integer", 200 | "num-traits", 201 | ] 202 | 203 | [[package]] 204 | name = "num-traits" 205 | version = "0.2.14" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 208 | dependencies = [ 209 | "autocfg", 210 | ] 211 | 212 | [[package]] 213 | name = "paste" 214 | version = "1.0.5" 215 | source = "registry+https://github.com/rust-lang/crates.io-index" 216 | checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" 217 | 218 | [[package]] 219 | name = "proc-macro2" 220 | version = "0.4.30" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" 223 | dependencies = [ 224 | "unicode-xid", 225 | ] 226 | 227 | [[package]] 228 | name = "quote" 229 | version = "0.6.13" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" 232 | dependencies = [ 233 | "proc-macro2", 234 | ] 235 | 236 | [[package]] 237 | name = "r0" 238 | version = "1.0.0" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "bd7a31eed1591dcbc95d92ad7161908e72f4677f8fabf2a32ca49b4237cbf211" 241 | 242 | [[package]] 243 | name = "rand" 244 | version = "0.5.6" 245 | source = "registry+https://github.com/rust-lang/crates.io-index" 246 | checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" 247 | dependencies = [ 248 | "rand_core 0.3.1", 249 | ] 250 | 251 | [[package]] 252 | name = "rand_core" 253 | version = "0.3.1" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 256 | dependencies = [ 257 | "rand_core 0.4.2", 258 | ] 259 | 260 | [[package]] 261 | name = "rand_core" 262 | version = "0.4.2" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" 265 | 266 | [[package]] 267 | name = "regex" 268 | version = "1.5.4" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" 271 | dependencies = [ 272 | "aho-corasick", 273 | "memchr", 274 | "regex-syntax", 275 | ] 276 | 277 | [[package]] 278 | name = "regex-syntax" 279 | version = "0.6.25" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 282 | 283 | [[package]] 284 | name = "riscv" 285 | version = "0.6.0" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "a2f0b705d428e9d0f78e2bb73093887ee58a83c9688de3faedbb4c0631c4618e" 288 | dependencies = [ 289 | "bare-metal 0.2.5", 290 | "bit_field", 291 | "riscv-target", 292 | ] 293 | 294 | [[package]] 295 | name = "riscv" 296 | version = "0.7.0" 297 | source = "registry+https://github.com/rust-lang/crates.io-index" 298 | checksum = "6907ccdd7a31012b70faf2af85cd9e5ba97657cc3987c4f13f8e4d2c2a088aba" 299 | dependencies = [ 300 | "bare-metal 1.0.0", 301 | "bit_field", 302 | "riscv-target", 303 | ] 304 | 305 | [[package]] 306 | name = "riscv-rt" 307 | version = "0.8.0" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | checksum = "b7fe583b2216c75d6f35996919c09fd4011fbc8f6bf31e5fbc97483a6aaa8bdd" 310 | dependencies = [ 311 | "r0", 312 | "riscv 0.6.0", 313 | "riscv-rt-macros", 314 | "riscv-target", 315 | ] 316 | 317 | [[package]] 318 | name = "riscv-rt-macros" 319 | version = "0.1.6" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | checksum = "3525f8341898dec060782087b7a15969e1cfe52818afacc47709265c19a23d53" 322 | dependencies = [ 323 | "proc-macro2", 324 | "quote", 325 | "rand", 326 | "syn", 327 | ] 328 | 329 | [[package]] 330 | name = "riscv-target" 331 | version = "0.1.2" 332 | source = "registry+https://github.com/rust-lang/crates.io-index" 333 | checksum = "88aa938cda42a0cf62a20cfe8d139ff1af20c2e681212b5b34adb5a58333f222" 334 | dependencies = [ 335 | "lazy_static", 336 | "regex", 337 | ] 338 | 339 | [[package]] 340 | name = "rustc_version" 341 | version = "0.2.3" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 344 | dependencies = [ 345 | "semver", 346 | ] 347 | 348 | [[package]] 349 | name = "semver" 350 | version = "0.9.0" 351 | source = "registry+https://github.com/rust-lang/crates.io-index" 352 | checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 353 | dependencies = [ 354 | "semver-parser", 355 | ] 356 | 357 | [[package]] 358 | name = "semver-parser" 359 | version = "0.7.0" 360 | source = "registry+https://github.com/rust-lang/crates.io-index" 361 | checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 362 | 363 | [[package]] 364 | name = "syn" 365 | version = "0.15.44" 366 | source = "registry+https://github.com/rust-lang/crates.io-index" 367 | checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" 368 | dependencies = [ 369 | "proc-macro2", 370 | "quote", 371 | "unicode-xid", 372 | ] 373 | 374 | [[package]] 375 | name = "unicode-xid" 376 | version = "0.1.0" 377 | source = "registry+https://github.com/rust-lang/crates.io-index" 378 | checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" 379 | 380 | [[package]] 381 | name = "vcell" 382 | version = "0.1.3" 383 | source = "registry+https://github.com/rust-lang/crates.io-index" 384 | checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" 385 | 386 | [[package]] 387 | name = "void" 388 | version = "1.0.2" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" 391 | --------------------------------------------------------------------------------