-
Notifications
You must be signed in to change notification settings - Fork 247
f4xx: UART fix missing Guard Time and Prescaler Register, f413 UART shouldn't include USART-only fields. #713
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
Conversation
ac2fdc0
to
8734c89
Compare
The GTPR was missing from UARTs on the f4 family. They are needed for IrDA operation. Correct functionality has been verified on: - STM32F446RET6 - STM32F429ZIT6 Fixes stm32-rs#711
8734c89
to
b732293
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good to me! Could you add the GT field to GTPR as well? As far as I can see it's present on all the F4 devices.
Hi @adamgreig , thanks for the review. I had deliberately left the GT field out because: As far as I could see the Guard Time bits are only used in SmartCard mode² ³, and it looks like the SmartCard mode is only present on USART peripherals¹. The prescaler (PSC) bits are used for both IrDA (on UART and USART peripherals) and also for SmartCards (USARTs only), so I only put the PSC bits in the PR (the PR only applies to UART peripherals, and not to USART peripherals). I don't really know anything about Smartcard communication, but I suppose it's conceivable that SmartCards can actually be used with UARTs (contrary to what the datasheet says)¹. So.... I don't know whether it's best to leave out the GT field, or put it in. I think it's probably either not present, or maybe present but not actually usable for anything, BICBW. Happy to go with whatever you think is best. References: RM0430 (STM32F412/423 reference manual, rev 8, 23-May-2018):
|
Ah, thanks, I missed that it wasn't present on the UARTs. Some of the RMs confirm this explicitly with a note that GT is not available on the UART fields. However, we don't distinguish the UARTs and USARTs for stm32f4; they all derive from the same USART register block, so I think we should add GT here so that it's usable for USARTs and just won't do anything for UARTs, same as the other smartcard mode features. |
Hi @adamgreig I had a bit of a dig around in the crates :-).
Unless I'm misunderstanding you, I don't think this is the case - the UARTs seem to be defined separately from the USARTs in the SVDs, and are a subset of them (well... 401, 407 and 469 all define UARTs distinctly, with the USART-specific fields not present, but the 413 SVD just re-uses the USART definition for the UART - so this PR corrects that too, and makes 413 consistent with the others). So, other USART-only fields are not present in the UART definitions exported by the
See: https://docs.rs/stm32f4/latest/stm32f4/stm32f469/usart1/cr3/index.html vs i.e. the UARTs are already (significantly) a subset of the USARTs in API presented by the
In the future, if So because of this, I think it might be more correct to omit the GT field from this PR after all. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the wait. You're right, let's get this in without the GT field.
bors r+
Build succeeded: |
now even worse. |
@burrbull does this just need repeating for uart5,7,8 or are you seeing problems with uart4 now? Looking at the memory map changes triggered by CI: https://github.com/stm32-rs/stm32-rs-mmaps/compare/pr-713-b732293 - I can't see any signs of stopbits being omitted for uart4. I'm building locally now to check. |
yes. uart5,7,8 should be derived from uart4. You can use stm32-rs/stm32f4xx-hal#481 as base. |
For more detail peripheral compare (with enums) you could use https://github.com/burrbull/svd-yaml-compare |
Well, this has turned out to be quite the rabbit hole
I have to go now, but will try to get this finished up later on today. |
stm32-rs#713 fixed the UART4 peripheral on f413 so that it didn't derive from the USART (which is a superset of the UART), but didn't add the UART register definitions, causing problems for downstream crates, by effectively removing some register definitions.
Expands stm32-rs#713 to include uart5, and also corrects a faulty interrupt definition which was pulled in from f405.
Currently, the F413 UART peripheral is a copy of its USART definition, whereas all of the other F4xx family use a separate independent definition for the UART peripheral (the independent definition doesn't include USART-specific fields which are not present in the UART peripheral). Fix by using the F405 UART definition on the F413.
All F4xx UARTs support IrDA mode, which utilises the PSC fields of the GTPR register. This field is missing in the UART definition (except F413 - see above) across the F4 family (presence and correct operation of the GTPR PSC field was verified by the author on F429 and F446 microcontrollers).
n.b. The other GTPR field (GT) appears to be specific to SmartCard mode - which is a USART-only feature, not supported on UART according to the reference manual, so the PR does not currently include that field for UARTs.