Code Monkey home page Code Monkey logo

Comments (11)

AsafFisher avatar AsafFisher commented on August 16, 2024

Can you refer to the exact line where you see a 32-bit pointer read from the rom?

from rp-hal.

AsafFisher avatar AsafFisher commented on August 16, 2024

We use rom_table_lookup which is supplied by the bootrom, so technically speaking we are not accessing the rom directly. If this function read 16-bit pointer value then we are fine :)

Hopefully it works like that. If not, well no pi pico has ever worked properly :O

from rp-hal.

AsafFisher avatar AsafFisher commented on August 16, 2024

Screen Shot 2021-02-05 at 1 16 51 PM

from rp-hal.

thejpster avatar thejpster commented on August 16, 2024
const FUNC_TABLE: *const *const u16 = 0x14 as _;

rom_table_lookup(FUNC_TABLE, some_tag);

fn rom_table_lookup<T>(table: *const *const u16, tag: RomFnTableCode) -> T {
    unsafe {
        let rom_table_lookup: RomTableLookupFn<T> = core::mem::transmute(ROM_TABLE_LOOKUP_PTR);
        rom_table_lookup(*table, u16::from_le_bytes(tag) as u32)
    }
}

The deref of the table pointer with *tablewill read four bytes (a *const _) from memory: 0x14 .. 0x17. You should only read 0x14 and 0x15 and add two zero bytes. You should probably set FUNC_TABLE to be a *const u16, then do a core::ptr::volatile_read(), then cast the u16 to a usize, then pass that to the rom_table_function.

In your ASM listing, I think LDR R0, [R0] will do a 32-bit read from the address 0x14. That LDR should be an LDRH.

But maybe I'm wrong, and this code works fine as-is? Maybe I've read the datasheet wrong?

from rp-hal.

thejpster avatar thejpster commented on August 16, 2024

Note how the SDK code does a 16-bit read:

// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address)

from rp-hal.

AsafFisher avatar AsafFisher commented on August 16, 2024

I think it's the same because jumping to 0x0014 is the same as jumping to 0x00000014 but essentially you are right

from rp-hal.

AsafFisher avatar AsafFisher commented on August 16, 2024

And in thumb all 16 bit are extended to 32 bit register so yah...

I don't have the pico so I can't test it (:

Let me know if I am wrong

from rp-hal.

thejpster avatar thejpster commented on August 16, 2024

Jumping to 0x0014 is the same as jumping to 0x00000014, but using the ROM table doesn't involve jumping to 0x0014 - it involves reading a two-byte value stored at 0x0014..0x0015.

from rp-hal.

AsafFisher avatar AsafFisher commented on August 16, 2024

I didn't notice the double const*😳

from rp-hal.

AsafFisher avatar AsafFisher commented on August 16, 2024

I am fixing it right now, why should I use core::ptr::volatile_read and not just regular deref?

from rp-hal.

thejpster avatar thejpster commented on August 16, 2024

I would use it because it is more explicit that you are loading from a specific address in flash.

from rp-hal.

Related Issues (20)

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.