Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Use the GPIO trait on STM32F4's pin #325

Merged
merged 3 commits into from
Jul 3, 2015
Merged

Conversation

darayus
Copy link
Contributor

@darayus darayus commented Jul 3, 2015

This changes the GPIO interface for the STM32F4 so that it uses the GPIO trait. set_direction only partially works as it does not update the Pin's internal function variable to the new mode. The set_direction function would need to take a &mut self for this to happen.

@hacknbot
Copy link
Contributor

hacknbot commented Jul 3, 2015

Can one of the admins verify this patch?

@mcoffin
Copy link
Contributor

mcoffin commented Jul 3, 2015

test this please

}

/// Sets output GPIO direction.
fn set_direction(&self, new_mode: GpioDirection) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got some 4-space indenting in here. Until we decide to go through and refactor the whole project (which will make git blame useless) we'll stick to the 2-space existing standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that! I'll fix the indentation now

@mcoffin
Copy link
Contributor

mcoffin commented Jul 3, 2015

This also could be as good a time as any to try and roll over to the new ioreg! macro.

@darayus
Copy link
Contributor Author

darayus commented Jul 3, 2015

The indentation should be fixed now.

/// Sets output GPIO direction.
fn set_direction(&self, new_mode: GpioDirection) {
// TODO: Verify that this works
// TODO: Change the Pin.function field to the new mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please own these TODOs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

stm32f4: switch GPIO to new ioregs macro
@mcoffin
Copy link
Contributor

mcoffin commented Jul 3, 2015

retest this please

@mcoffin
Copy link
Contributor

mcoffin commented Jul 3, 2015

LGTM. Thanks for the contributions!

mcoffin added a commit that referenced this pull request Jul 3, 2015
Modernize STM32F4 GPIO implementation
@mcoffin mcoffin merged commit 1ea86b2 into hackndev:master Jul 3, 2015
reg_rw!(GPIO, u32, LCKR, set_LCKR, LCKR);
reg_rw!(GPIO, u32, AFRL, set_AFRL, AFRL);
reg_rw!(GPIO, u32, AFRH, set_AFRH, AFRH);
ioregs!(GPIO = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do placement code and get rid of linker part too, really. Does it make sense to add multiple placement definitions for a case like this or we're looking for some svd for stm32f4 to sort it for us?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@farcaller do you mean the #[link_name="..."] / iomem.ld part? Which alternatives are there? Maybe we should track this in an RFC issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah nice, did not see this. I just started to wrap my head around the codebase. So the placement getters still need some documentation, don't they? I just started a "new" empty port of the stm32f4 (just to get to know all the traits and structs). I hope I can document all obscurities on the way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they aren't mentioned in the ioreg crate docs actually. If you'll revive the stm32f4 codebase it would be awesome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes seems reasonable. At least NXP seems to be very permissive with their SVD files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other approach I see is to generate "terrible" code from the SVDs as a starting point and do one of two things from there:

  1. Change the generator to patch the intermediate representation of the SVD (which I believe is free from any licensing problems). This patching is probably vendor specific to deal with that vendors particular deficiencies.
  2. Have the SVD transformation be a one-time thing and patch the resulting ioregs! by hand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just discovered that the SVD for the STM32F4 also has some strange quirks. I'm going with option 2 for now. I'll just take the register definitions needed to implement the HAL and fix any quirks by hand. This way one saves a lot of work, but also allows easy fixing. Option 1 on the other hand is great if the ioregs! macros change in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are very little cases not covered by ioregs I think? I'd vouch for reasonable changes to SVD xml to make ioregs readable and store SVDs in tree if it aligns with the license.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if the license permits modifications and the generated definitions are ok, it makes sense. But as far as I understood the STM license does not permit modifications. So we have MCUs where we can use and fix SVDs and we have MCUs where we have to do it more selectively.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants