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

Thread panic with PIC32MZ pic file #1

Open
jg2562 opened this issue Oct 6, 2021 · 13 comments
Open

Thread panic with PIC32MZ pic file #1

jg2562 opened this issue Oct 6, 2021 · 13 comments

Comments

@jg2562
Copy link

jg2562 commented Oct 6, 2021

When running edc2svd on the PIC32MZ2048EFG100.PIC and it cause a thread panic. The file was acquired directly from an MPLABS install, so it should be a valid example of it.

It appears to be a purposeful panic with cperi.len() being 0 for the file, so im not sure where this comes from.

dc2svd ./PIC32MZ2048EFG100.PIC PIC32MZ2048EFG100.svd           
cname = CPUPRI but name = EXLPRI
cname = SQI1MD but name = SQIMD
cname = SQI1MD but name = SQIMD
cname = SQI1MD but name = SQIMD
cname = SQI1MD but name = SQIMD
thread 'main' panicked at 'empty peripheral info for _ICDCON', /home/jack/.cargo/registry/src/github.com-1ecc6299db9ec823/edc2svd-0.3.0/src/main.rs:205:17
note: run with 'RUST_BACKTRACE=1' environment variable to display a backtrace
@kiffie
Copy link
Owner

kiffie commented Oct 8, 2021

There is some "guessing code" that guesses the peripheral if there is no baseofperipheral attribute. A solution could be to add another ifclause to the guessing code. Maybe, something like ms == "DOS-01539_icd_jtag_pb_v2.Module" or so. You can find the relevant line in the .PIC file by searching for "_ICDCON".

I spotted that the peripheral SFR name _ICDCON starts with an underscore. No idea if this makes sense.

I would be happy to integrate a PR to make edc2svd support this PIC32MZ device.

@jg2562
Copy link
Author

jg2562 commented Oct 8, 2021

So I gave it a shot, adding in these two if statements to the guessing code:

} else if ms == "DOS-01539_icd_jtag_pb_v2.Module" {
	String::from("_ICDCON")
} else if ms == "DOS-02823_clk_cru_upb_v2.Module" {
	String::from("REFQ1CON")

I think that is what you were mentioning but I wasnt entirely sure. The second if came from a very similiar panic. However, now im hitting an assertion panic at 150

cname = CPUPRI but name = EXLPRI
cname = SQI1MD but name = SQIMD
cname = SQI1MD but name = SQIMD
cname = SQI1MD but name = SQIMD
cname = SQI1MD but name = SQIMD
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"OFF190"`,
 right: `"OFF192"`', src/main.rs:150:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If you'd like here is the branch

@kiffie
Copy link
Owner

kiffie commented Oct 9, 2021

The assertion at line 150 is a consistency check of the source XML file, which failed. The SFR defintion that caused the error is

<edc:SFRDef edc:_addr="0x1F810840" edc:_begin="0x840" edc:_end="0x84c" edc:_modsrc="DOS-02907_WACD_int_evic_v3.Module" edc:_refcount="11" edc:access="--------------nnnnnnnnnnnnnnnnn-" edc:cname="OFF192" edc:desc="" edc:impl="0x3fffe" edc:isindirect="false" edc:isvolatile="true" edc:mclr="--------------00000000000000000-" edc:name="OFF190" edc:nzwidth="32" edc:por="--------------00000000000000000-" ltx:memberofperipheral="INT">

The nameand cname attributes differ from each other. According to the PIC32MZ datasheet (table 7-3) the correct register name is OFF192. It looks like a typo or copy-and-paste mistake in the .PIC file. Moreover, different SFRs in this .PIC file have edc:name=OFF190.

How to resolve this issue? Correcting the .PIC file manually? Always relying on the cname attribute? Unfortunately, it did not find documentation on the .PIC file format. Do you know why two attributes cname and name are used to specific the SFR names?

Currently, I tend to use cname rather than name and to add a command line option to disable the consistency check.

@jg2562
Copy link
Author

jg2562 commented Oct 13, 2021

I replaced some of the manual module checks that I added with a call to cloning the cname. I also tried to force name to be cname for all peripherials in the hope it would combat the copy paste errors. Im still getting a panic of
'empty peripheral info for DMACON'.

At this point, im not sure if im going about the correct path for these errors. I wish I knew why there were both cname and name attributes that were conflicting, but from what you were saying, relying on cname does look like the right idea, as these errors may continue to persist.

I also looked at the PIC32MZ datasheet at table 7-3 and I didnt find 0FF192, it looked like it ended at 0FF190, but pretty far out of my zone of knowledge here, so im probably misreading the sheet. Let me know if you have any more ideas on this though and thank you for all the help kiffie!

@kiffie
Copy link
Owner

kiffie commented Oct 13, 2021

I now have a running version. See below the changes I did (compared to my current version ignoring the format!(..) macro issue). The memberofperipheral of some XML elements is an empty string, which caused problems within the if/else clauses.

Could you try it and check if the SVD file is Ok and correct if necessary? I selected the name "SYSBUS" for a system bus arbiter of the PIC32. Please change, should this name be not Ok. Please also trigger a PR (Pull Request) from your fork/branch. I would like to merge this into my repository.

BTW, the register name is OFF192 starting with the letter O (not the digit 0).

--- a/src/main.rs
+++ b/src/main.rs
@@ -146,8 +146,8 @@ fn analyze_periph(periph: &Element, periph_out_e: &mut Element) {
             // get the phys. address and map it to the KSEG1 segment
             let addr = parse_u32(&attr["_addr"]).unwrap() | 0xA000_0000;
 
-            let name = &attr["name"];
-            assert_eq!(name, &attr["cname"]);
+            let name = &attr["cname"];
+            //assert_eq!(name, &attr["name"]); // TODO: fix this
 
             let mut portals = String::from("- - -");
             if let Some(p) = attr.get("portals") {
@@ -171,14 +171,10 @@ fn analyze_periph(periph: &Element, periph_out_e: &mut Element) {
             });
 
             // guess peripheral
-            let mop = match attr.get("memberofperipheral") {
-                Some(m) => if m.len() == 0 { None } else { Some(m) },
-                None => None,
-            };
             let mut cperi: String;
-            if let Some(bop) = attr.get("baseofperipheral") {
+            if let Some(bop) = attr.get("baseofperipheral").filter(|s| ! s.is_empty()) {
                 cperi = bop.clone();
-            } else if let Some(m) = mop {
+            } else if let Some(m) = attr.get("memberofperipheral").filter(|s| ! s.is_empty()) {
                 cperi = m.clone();
             } else if let Some(grp) = attr.get("grp") {
                 cperi = grp.clone();
@@ -191,6 +187,18 @@ fn analyze_periph(periph: &Element, periph_out_e: &mut Element) {
                     String::from("PPS")
                 }else if ms == "DOS-01475_lpwr_deep_sleep_ctrl_v2.Module" {
                     String::from("DSCTRL") // Deep Sleep Controller
+				} else if ms == "DOS-01500_dma_bvci_v2.Module" {
+					String::from("DMAC2") // DMA of PIC32MZ
+                } else if ms == "DOS-01539_icd_jtag_pb_v2.Module" {
+                    String::from("ICD") // ICD peripheral of PIC32MZ
+                } else if ms == "DOS-02823_clk_cru_upb_v2.Module" {
+                    String::from("OSC") // OSC of PIC32MZ
+                } else if ms == "DOS-02508_adc_sar_ctrl_upb_v1.Module" {
+                    String::from("ADC") // ADC on PIC32MZ
+                } else if ms == "DOS-02831_usb_clk_rst_v2.Module" {
+                    String::from("USB") // PIC32MZ USB register map 2
+                } else if ms == "DOS-EIP-00136_ssx_v1.Module" {
+                    String::from("SYSBUS") // PIC32MZ system bus arbiter
                 } else {
                     String::from("")
                 };

@jg2562
Copy link
Author

jg2562 commented Oct 14, 2021

Thanks for the code, it worked great!

I was able to convert it to a svd, then have the svd generate rust. However, after running the following code snippet as suggested by svd2rust, I tried generating the docs using cargo build and it complained about many redefinitions of structs, functions, and variables.###

Svd2rust commands

$ svd2rust -i PICMZ.svd

$ rm -rf src

$ form -i lib.rs -o src/ && rm lib.rs

$ cargo fmt

Last few errors from build

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:2953:5
     |
2953 |     pub const PTR: *const adc::RegisterBlock = 0xbf84_b06c as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
3009 |     pub const PTR: *const adc::RegisterBlock = 0xbf84_b0a0 as *const _;
     |     ------------------------------------------------------------------- other definition for `PTR`

error[E0592]: duplicate definitions with name `ptr`
    --> src/lib.rs:2956:5
     |
2956 |     pub const fn ptr() -> *const adc::RegisterBlock {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `ptr`
...
3012 |     pub const fn ptr() -> *const adc::RegisterBlock {
     |     ----------------------------------------------- other definition for `ptr`

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:2953:5
     |
2953 |     pub const PTR: *const adc::RegisterBlock = 0xbf84_b06c as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
3065 |     pub const PTR: *const adc::RegisterBlock = 0xbf84_b0dc as *const _;
     |     ------------------------------------------------------------------- other definition for `PTR`

error[E0592]: duplicate definitions with name `ptr`
    --> src/lib.rs:2956:5
     |
2956 |     pub const fn ptr() -> *const adc::RegisterBlock {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `ptr`
...
3068 |     pub const fn ptr() -> *const adc::RegisterBlock {
     |     ----------------------------------------------- other definition for `ptr`

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:3009:5
     |
3009 |     pub const PTR: *const adc::RegisterBlock = 0xbf84_b0a0 as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
3065 |     pub const PTR: *const adc::RegisterBlock = 0xbf84_b0dc as *const _;
     |     ------------------------------------------------------------------- other definition for `PTR`

error[E0592]: duplicate definitions with name `ptr`
    --> src/lib.rs:3012:5
     |
3012 |     pub const fn ptr() -> *const adc::RegisterBlock {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `ptr`
...
3068 |     pub const fn ptr() -> *const adc::RegisterBlock {
     |     ----------------------------------------------- other definition for `ptr`

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:3429:5
     |
3429 |     pub const PTR: *const usb::RegisterBlock = 0xbf88_4000 as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
3541 |     pub const PTR: *const usb::RegisterBlock = 0xbf8e_3000 as *const _;
     |     ------------------------------------------------------------------- other definition for `PTR`

error[E0592]: duplicate definitions with name `ptr`
    --> src/lib.rs:3432:5
     |
3432 |     pub const fn ptr() -> *const usb::RegisterBlock {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `ptr`
...
3544 |     pub const fn ptr() -> *const usb::RegisterBlock {
     |     ----------------------------------------------- other definition for `ptr`

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:3597:5
     |
3597 |     pub const PTR: *const sb::RegisterBlock = 0xbf8f_0510 as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
3653 |     pub const PTR: *const sb::RegisterBlock = 0xbf8f_8420 as *const _;
     |     ------------------------------------------------------------------ other definition for `PTR`

error[E0592]: duplicate definitions with name `ptr`
    --> src/lib.rs:3600:5
     |
3600 |     pub const fn ptr() -> *const sb::RegisterBlock {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `ptr`
...
3656 |     pub const fn ptr() -> *const sb::RegisterBlock {
     |     ---------------------------------------------- other definition for `ptr`

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:3625:5
     |
3625 |     pub const PTR: *const sysbus::RegisterBlock = 0xbf8f_8020 as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
3681 |     pub const PTR: *const sysbus::RegisterBlock = 0xbf8f_8820 as *const _;
     |     ---------------------------------------------------------------------- other definition for `PTR`

error[E0592]: duplicate definitions with name `ptr`
    --> src/lib.rs:3628:5
     |
3628 |     pub const fn ptr() -> *const sysbus::RegisterBlock {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `ptr`
...
3684 |     pub const fn ptr() -> *const sysbus::RegisterBlock {
     |     -------------------------------------------------- other definition for `ptr`

If statement conflicting implementations

error[E0119]: conflicting implementations of trait `core::fmt::Debug` for type `SYSBUS`
    --> src/lib.rs:3695:1
     |
3639 | impl core::fmt::Debug for SYSBUS {
     | -------------------------------- first implementation here
...
3695 | impl core::fmt::Debug for SYSBUS {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `SYSBUS`

error[E0592]: duplicate definitions with name `PTR`
    --> src/lib.rs:1329:5
     |
1329 |     pub const PTR: *const cru::RegisterBlock = 0xbf80_1200 as *const _;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `PTR`
...
1385 |     pub const PTR: *const cru::RegisterBlock = 0xbf80_1300 as *const _;
     |   

What are your thoughts on why its duplicating, is it originating from the edc file? As a side note some of the modules that show up in the if statement show up as a duplicate trait in the earlier output.

@kiffie
Copy link
Owner

kiffie commented Oct 17, 2021

I think the problem is that some <SFRDef> elements have a correct memberofperipheralattribute but other such elements do not. The above if clauses for peripheral name guessing must corrected. For example, CRU must be used rather than OSC and ADCHS rather than ADC, etc.

@jg2562
Copy link
Author

jg2562 commented Oct 19, 2021

I'm wondering how MPLAB properly handles it then, is it derived from somewhere else or from the other elements? Also, would the correct memberofperipheral attributes (or a way to find them) be defined in the data sheets?

@kiffie
Copy link
Owner

kiffie commented Oct 19, 2021

I do not know how they generate the C header files for the compiler and if/how other parts of MPLAB use the .PIC files. But the header files have a flat structure not including peripheral names.

The datasheets list the available peripherals but do not consistently define symbolic names for them. In think the most pragmatic approach would be to figure out the peripheral names used in the .PIC files and then adapt the guessing code to process the <SFRDef> elements where the peripheral name/ID is missing.

@jg2562
Copy link
Author

jg2562 commented Oct 19, 2021

I'm not sure if I know how to figure out the peripheral names from the .PIC file but i can attempt to give it a shot

@jg2562
Copy link
Author

jg2562 commented Oct 19, 2021

So I tried using the baseofperipherials or memberofperipherial attribute from another similar <SFRDef> as the guessed peripherial, It seems its actually able to compile, so I will try to get it uploaded to a board and see if I can do anything with it. But first i need to figure out how to do that.

Update: I wasnt able to make a lot of progress on getting it to upload in any reasonable fashion, I will give it a shot later this week, any advice will be greatly appreciated though!

@jg2562
Copy link
Author

jg2562 commented Oct 29, 2021

I was able to get it to be hacked onto pic32-pac/pic32mx2xx, after which I tried to compile blinky two it and it threw many errors as one might expect. I suspect most of the errors come from trying to compile for a chip pic32-hal was never designed for. However, im not sure what needs to be fixed to help with the problem.

Here are the errors if anyone wants to look them over

~/D/p/p/e/blinky master* ❯ cargo build                                                                                                        02:35
  Downloaded compiler_builtins v0.1.49
  Downloaded miniz_oxide v0.4.0
  Downloaded hashbrown v0.11.0
  Downloaded adler v0.2.3
  Downloaded 4 crates (302.2 KB) in 0.82s
   Compiling compiler_builtins v0.1.49
   Compiling core v0.0.0 (/home/jack/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.29
   Compiling semver-parser v0.7.0
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.80
   Compiling mips-mcu v0.1.0
   Compiling pic32mx2xx v0.3.0 (/home/jack/Documents/pic32/pic32-pac/pic32mx2xx)
   Compiling mips-rt v0.2.1
   Compiling semver v0.9.0
   Compiling rustc_version v0.2.3
   Compiling bare-metal v0.2.5
   Compiling quote v1.0.10
   Compiling mips-rt-macros v0.2.1
   Compiling enumflags2_derive v0.6.4
   Compiling rustc-std-workspace-core v1.99.0 (/home/jack/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/jack/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling nb v1.0.0
   Compiling void v1.0.2
   Compiling vcell v0.1.3
   Compiling r0 v0.2.2
   Compiling enumflags2 v0.6.4
   Compiling nb v0.1.3
   Compiling embedded-hal v0.2.6
   Compiling pic32-hal v0.4.1 (/home/jack/Documents/pic32/pic32-rs/pic32-hal)
warning: use of deprecated macro `llvm_asm`: will be removed from the compiler, use asm! instead
  --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:19:14
   |
19 |     unsafe { llvm_asm!("mfc0 $0, $$9" : "=r"(count) : : : "volatile") };
   |              ^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated macro `llvm_asm`: will be removed from the compiler, use asm! instead
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:134:18
    |
134 |         unsafe { llvm_asm!("mfc0 $0, $$11" : "=r"(compare) : : : "volatile") };
    |                  ^^^^^^^^

warning: use of deprecated macro `llvm_asm`: will be removed from the compiler, use asm! instead
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:141:18
    |
141 |         unsafe { llvm_asm!("mtc0   $0, $$11" : : "r"(compare) : : "volatile") };
    |                  ^^^^^^^^

warning: `pic32-hal` (lib) generated 3 warnings
   Compiling blinky v0.2.0 (/home/jack/Documents/pic32/pic32-rs/examples/blinky)
    Finished dev [unoptimized + debuginfo] target(s) in 37.03s
~/D/p/p/e/blinky master* 37s ❯ cargo build                                                                                                    02:41
   Compiling pic32mx2xx v0.3.0 (/home/jack/Documents/pic32/pic32-pac/pic32mx2xx)
   Compiling pic32-hal v0.4.1 (/home/jack/Documents/pic32/pic32-rs/pic32-hal)
error[E0433]: failed to resolve: could not find `pac` in the crate root
  --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:14:16
   |
14 | pub use crate::pac::interrupt::InterruptSource;
   |                ^^^ could not find `pac` in the crate root

error[E0433]: failed to resolve: could not find `pac` in the crate root
  --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:19:16
   |
19 | pub use crate::pac::interrupt::Interrupt;
   |                ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::pac`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:5:12
  |
5 | use crate::pac::INT;
  |            ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::clock::Osc`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/uart.rs:6:5
  |
6 | use crate::clock::Osc;
  |     ^^^^^^^^^^^^^^^^^ no `Osc` in `clock`

error[E0432]: unresolved import `crate::pac`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/uart.rs:7:12
  |
7 | use crate::pac::{UART1, UART2};
  |            ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::pac`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/spi.rs:4:12
  |
4 | use crate::pac::{SPI1, SPI2};
  |            ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::pac`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/i2c.rs:3:12
  |
3 | use crate::pac::{I2C1, I2C2};
  |            ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::pac`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:7:12
  |
7 | use crate::pac::INT; // interrupt controller
  |            ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::pac`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/dma.rs:4:12
  |
4 | use crate::pac::{DMAC, DMAC0, DMAC1, DMAC2, DMAC3};
  |            ^^^ could not find `pac` in the crate root

error[E0432]: unresolved import `crate::int::InterruptSource`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/i2c.rs:6:5
  |
6 | use crate::int::InterruptSource;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `InterruptSource` in `int`

error[E0432]: unresolved import `crate::int::InterruptSource`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/dma.rs:3:5
  |
3 | use crate::int::InterruptSource;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `InterruptSource` in `int`

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:110:38
    |
110 |     fn bitaddr<REG: RegisterSpec>(s: InterruptSource, breg: &Reg<REG>) -> (*mut u32, u32) {
    |                                      ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:119:25
    |
119 |     pub fn ei(&self, s: InterruptSource) {
    |                         ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:125:25
    |
125 |     pub fn di(&self, s: InterruptSource) {
    |                         ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:131:28
    |
131 |     pub fn is_ie(&self, s: InterruptSource) -> bool {
    |                            ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:137:29
    |
137 |     pub fn get_if(&self, s: InterruptSource) -> bool {
    |                             ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:144:31
    |
144 |     pub fn clear_if(&self, s: InterruptSource) {
    |                               ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `InterruptSource` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:150:29
    |
150 |     pub fn set_if(&self, s: InterruptSource) {
    |                             ^^^^^^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::interrupt::InterruptSource;
    |

error[E0412]: cannot find type `Interrupt` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:155:40
    |
155 |     fn byteaddr<REG: RegisterSpec>(iv: Interrupt, breg: &Reg<REG>) -> (*mut u32, usize) {
    |                                        ^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::Interrupt;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::Interrupt;
    |

error[E0412]: cannot find type `Interrupt` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:164:31
    |
164 |     pub fn set_ipl(&self, iv: Interrupt, ipl: Ipl) {
    |                               ^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::Interrupt;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::Interrupt;
    |

error[E0412]: cannot find type `Interrupt` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:172:27
    |
172 |     pub fn ipl(&self, iv: Interrupt) -> Ipl {
    |                           ^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::Interrupt;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::Interrupt;
    |

error[E0412]: cannot find type `Interrupt` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:179:31
    |
179 |     pub fn set_isl(&self, iv: Interrupt, isl: Isl) {
    |                               ^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::Interrupt;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::Interrupt;
    |

error[E0412]: cannot find type `Interrupt` in this scope
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/int.rs:186:27
    |
186 |     pub fn isl(&self, iv: Interrupt) -> Isl {
    |                           ^^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
5   | use crate::pac_crate::pic32mx2x4fxxxd::Interrupt;
    |
5   | use pic32mx2xx::pic32mx2x4fxxxd::Interrupt;
    |

warning: unused macro definition
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/gpio.rs:38:1
    |
38  | / macro_rules! port {
39  | |     ($PORTX:ident, $portx:ident, [
40  | |         $($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty $(, $has_ansel:expr)?),)+
41  | |     ]) => {
...   |
258 | |     }
259 | | }
    | |_^
    |
    = note: `#[warn(unused_macros)]` on by default

warning: use of deprecated macro `llvm_asm`: will be removed from the compiler, use asm! instead
  --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:19:14
   |
19 |     unsafe { llvm_asm!("mfc0 $0, $$9" : "=r"(count) : : : "volatile") };
   |              ^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated macro `llvm_asm`: will be removed from the compiler, use asm! instead
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:134:18
    |
134 |         unsafe { llvm_asm!("mfc0 $0, $$11" : "=r"(compare) : : : "volatile") };
    |                  ^^^^^^^^

warning: use of deprecated macro `llvm_asm`: will be removed from the compiler, use asm! instead
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/coretimer.rs:141:18
    |
141 |         unsafe { llvm_asm!("mtc0   $0, $$11" : : "r"(compare) : : "volatile") };
    |                  ^^^^^^^^

warning: unused import: `crate::time::Hertz`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/clock.rs:6:5
  |
6 | use crate::time::Hertz;
  |     ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `crate::time::U32Ext`
 --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/clock.rs:7:5
  |
7 | use crate::time::U32Ext;
  |     ^^^^^^^^^^^^^^^^^^^

error[E0592]: duplicate definitions with name `split`
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/uart.rs:44:13
    |
44  |             pub fn split(self) -> (Tx<$Uart>, Rx<$Uart>) {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             duplicate definitions for `split`
    |             other definition for `split`
...
132 | uart_impl!(uart1, UART1);
    | ------------------------ in this macro invocation
    |
    = note: this error originates in the macro `uart_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0592]: duplicate definitions with name `free`
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/spi.rs:114:13
    |
114 |             pub fn free(self) -> $Spi {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             duplicate definitions for `free`
    |             other definition for `free`
...
150 | spi!(spi1, SPI1);
    | ---------------- in this macro invocation
    |
    = note: this error originates in the macro `spi` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0592]: duplicate definitions with name `free`
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/i2c.rs:74:13
    |
74  |             pub fn free(self) -> $I2c {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             duplicate definitions for `free`
    |             other definition for `free`
...
212 | i2c_impl!(i2c1, I2C1);
    | --------------------- in this macro invocation
    |
    = note: this error originates in the macro `i2c_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0592]: duplicate definitions with name `i2c_busy`
   --> /home/jack/Documents/pic32/pic32-rs/pic32-hal/src/i2c.rs:79:13
    |
79  |             fn i2c_busy(&self) -> bool {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             duplicate definitions for `i2c_busy`
    |             other definition for `i2c_busy`
...
212 | i2c_impl!(i2c1, I2C1);
    | --------------------- in this macro invocation
    |
    = note: this error originates in the macro `i2c_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0412, E0432, E0433, E0592.
For more information about an error, try `rustc --explain E0412`.
warning: `pic32-hal` (lib) generated 6 warnings
error: could not compile `pic32-hal` due to 27 previous errors; 6 warnings emitted
warning: build failed, waiting for other jobs to finish...
error: build failed

@kiffie
Copy link
Owner

kiffie commented Oct 30, 2021

I implemented the HAL modules for the PIC32MX and the respective PAC only. To test your new generated PAC and get something that at least compiles, I propose to write a blinky program that uses the PAC directly. If you plan to use the Rust low level runtime for the MIPS core, it makes sense to double-check the startup code in in mips-rt because the PIC32MZEF has a different core. Adapting/extending the HAL for the PIC32MZEF would be a second step.

BTW, to generate a flash hex image, you need to include appropriate configuration words, too (or at least check what happens if you leave then unprogramed (= 0xff)).

If you do not want to fiddle with start-up code and configuration words you could consider compile the Rust program as a library and link it against a small C program that calls your Rust program. I never tried this but it should be possible.

I hope this helps. Happy hacking ;)

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