Repository navigation
Fix pin_backup_t missing the input routing of a pin - #349
Merged
Merged
Conversation
backup() looks for the input signal routed from a pin by reading the input selector of the pin's output signal. It compared that selector with the signal number, but the selector holds the GPIO number routed to the signal, so the match only happened when the two numbers were equal by chance, and restore() left the input routing as the borrower had set it. - Compare the selector with the pin number, and only while SIG_IN_SEL is set. With SIG_IN_SEL clear the signal bypasses the GPIO matrix and the selector is a stale value that does not belong to this pin. - restore() now writes the saved input selector back. Do it after the IO MUX, GPIO_PIN and output selector registers are restored, so the input is not reconnected to a pad still configured by the borrower. - matches_current() compares the input selector too, so a pin whose input routing was changed while borrowed is reported as changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #348.
What changes
pin_backup_t::backup()looks for the input signal routed from a pin by reading the input selector (IN_SEL) of the pin's output signal. It compared that selector with the signal number, butIN_SELholds the GPIO number routed to the signal. So the match only happened when the two numbers were equal by chance,_in_func_numstayed-1, andrestore()never put the input routing back.SIG_IN_SELis set. WithSIG_IN_SELclear the signal bypasses the GPIO matrix andIN_SELis a stale value that does not belong to this pin. Matching it would letrestore()undo routing that another pin owns.IO_MUX,GPIO_PINand the output selector are restored, and before output is re-enabled. This way the input is not reconnected to a pad still configured by the borrower, for example with its input buffer disabled.matches_current()now also compares the input selector, so a pin whose input routing was changed while borrowed is reported as changed. Board detection uses it to decide whether a pin needs restoring.Checked
IN_SELholds a GPIO number on all of them. The constant inputs are above the GPIO range.GPIO_SIG0_IN_SEL/GPIO_SIG1_IN_SELexist on each. On the P4, theGPIO_FUNC1_IN_SEL_CFG_REGbased read and theGPIO.func_in_sel_cfg[]write hit the same register.M5.In_I2C). The test backs up SDA/SCL, routes their input signals to the constant-high input, callsrestore(), and readsIN_SELagain:IN_SELstays 0x38IN_SELstays 0x38IN_SELstays 0x38IN_SELstays 0x3FNot tested