Svd2rust - write to register offset

Hi all,
I am currently working on a peripheral access crate for a TI CC3220SF device. TI doesn't offer SVD files of this device so I took their XML format, converted that to SVD, and ran that SVD file through svd2rust to get my PAC. The PAC seems to be working since I am able to blink the on-board LEDs of my CC3220SF Launchpad.

Here is my issue though:
The GPIO peripheral of this chip is designed in a way that sending data to the GPIODATA register is kind of cumbersome and hard to do with the PAC that was generated by svd2rust. To write GPIO data, you must actually write the data to a specific offset of the GPIODATA register, rather than the GPIODATA register itself. A good, detailed explanation of the process to write GPIO data can be found in the CC3220 Technical Reference Manual in section 5.2.1 (www.ti.com/lit/ug/swru465/swru465.pdf) however I'll try to give my best, brief explanation: Bits 9 through 2 of the address bus are used as a mask on the data that is being written to this address. So for example I have a data register at 0x40005000 and I want to write the value 0x0A to this data, I actually have to write 0x0A to the address at 0x40005000 + (0x0A << 2) = 0x40005028.

To do this in my current LED blinky application, I have the following code:

    const DATA: *mut u32 = (0x40005038) as *mut u32; // ADDR = 0x40005000 + (0x0E << 2)
    let mut led_vals = 0x00;
    let mask = 0x0E
    gpio1.dir.write(|w| unsafe { w.bits(mask) }); // Set GPIO 9, 10, 11 as output
    unsafe {
        write_volatile(DATA, led_vals); // write GPIO data
    }

So to handle writing to the GPIODATA, I have to create an address pointer and use the core::ptr::write_volatile function to actually write some GPIODATA rather than just being to write the data through the PAC like I can do with the GPIODIR register: gpio1.dir.write(|w| unsafe {w.bits(mask)});

Has anyone had to do anything similar to this before or are there any ideas on how I can do this through the PAC rather than using the write_volatile function? Can I write to a register offset through the PAC? I'd like to avoid changing the SVD file but I will do that if necessary. Any advice or help would be appreciated. Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.