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

Is there a guide to adding alternate pins? #560

Closed
saosebastiao opened this issue Jan 4, 2025 · 6 comments
Closed

Is there a guide to adding alternate pins? #560

saosebastiao opened this issue Jan 4, 2025 · 6 comments

Comments

@saosebastiao
Copy link

I'm currently trying to write a firmware for an existing board which uses alternate function pins which are not mapped in the PAC for embassy-stm32. Is there any guidance on how those alternate functions could be added to this repo?

@Dirbaio
Copy link
Member

Dirbaio commented Jan 4, 2025

the data comes from XMLs like this one that are provided by ST as part of STM32CubeMX, and parsed by this code.

which AF is missing? I'd start by checking the XML to see if it's in some "special" format that gpio_af.rs is missing. if it's really missing from the XMLs it'd need adding ifs to the rust code to add exceptions. That shouldn't happen tho, the XMLs have been quite complete so far.

@saosebastiao
Copy link
Author

I don't have anything exhaustive, I was just trying to generate an embassy-rs SPI3 instance for an STM32G474CE, and it would not accept pin PC12 as a SPI3_MOSI pin, which the data sheet lists as being available under Alternate Function 6 (see page 75/236.).

            let spi = spi::Spi::new(
                p.SPI3, 
                p.PC10, 
                p.PC12, // This causes error, but PB5 does not.  
                p.PC11, 
                p.DMA1_CH5, 
                p.DMA1_CH6, 
                spi3_config    
            );

stm32g474ce.pdf

However, it does appear to be present in the XMLs https://github.com/embassy-rs/stm32-data-sources/blob/1a3751550575f8ffee5e45307713a3e08bc9ffb4/cubedb/mcu/IP/GPIO-STM32G47x_gpio_v1_0_Modes.xml#L3337-L3359, so I'm not exactly sure how it would end not working with the compiled code.

@Dirbaio
Copy link
Member

Dirbaio commented Jan 7, 2025

STM32G474CE only exists in two packages STM32G474CETx (LQFP48), STM32G474CEUx (UFQFPN48), both of which don't have the PC12 pin. So it's correct that you can't use PC12 for SPI3_MOSI, because PC12 doesn't exist at all.

However, due to reasons, AFs for non-existing pins are filtered out, but the pins themselves aren't, so p.PC12 still exists in embassy-stm32. I can see how that's confusing 🥲 .

@saosebastiao
Copy link
Author

Oof, that's a very interesting gotcha. In a sense, the type system did an amazing job, cause it caught a perfectly valid and fairly expensive potential error (I was using the wrong microcontroller!), albeit with a root cause that was pretty hard to understand. Thanks for the help, I really appreciate it :)

@Dirbaio
Copy link
Member

Dirbaio commented Jan 7, 2025

the ghost pins were bothering me so I fixed them: 2624ca6 and embassy-rs/embassy#3738 change codegen so non-existing pins are completely gone now, so p.PC12 doesn't exist at all now,

@saosebastiao
Copy link
Author

Absolutely amazing, thank you so much!

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