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

Hm2 bspi fixes #2288

Merged
merged 5 commits into from Jan 18, 2023
Merged

Hm2 bspi fixes #2288

merged 5 commits into from Jan 18, 2023

Conversation

SebKuzminsky
Copy link
Collaborator

This PR makes the Mesa 7i65 board inputs work right for us.

The BSPI module has a receive fifo and a transmit fifo per instance
(shared among all the channels of that instance).

Writing anything to the fifo count register clears both fifos, discarding
any old read data and any pending write data.
Writing to BSPI channels with echo enabled also simultaneously reads from
those channels.  The read bytes go into the BSPI instance's read fifo,
where they stay until the driver reads them out.

By writing to the (echo-y) ADCs to configure them, we also put some
bytes into the read fifo.  When we later try to read the analog and
digital inputs, we'll actually get the old bytes from the ADC setup,
and everything will be off by a handful of bytes, resulting in incorrect
information being used.

This commit fixes the problem by clearing the FIFO after setting up
the ADCs.

There may be another bug lurking in here - if somehow the FIFO becomes
out of sync, we'll never recover.  A future hacker will get the pleasure
of rediscovering this problem and fixing it.
@jepler jepler merged commit 24b1e58 into 2.8 Jan 18, 2023
@andypugh
Copy link
Collaborator

What prompted this? I wasn't aware of an issue.

@SebKuzminsky
Copy link
Collaborator Author

Sorry, this change was a bit rushed, and as it turns out it may have been in error...

@jepler and @cradek and I are building a new machine, using a 7i80 and a 7i65. It's probably also worth mentioning that we're using a custom 7i80 firmware from @pcw-mesa.

We were observing bogus results when reading the SPI peripherals on the 7i65:

  • The "misc input" digital input pins on the CPLD would flip randomly, even when the physical input pins were explicitly driven high or low.
  • The voltages we presented to the SPI ADC inputs (e.g. by connecting an analog input pin to ground or +5) would appear on the incorrect HAL pin. For example, we'd drive AIN0 to +5, and the voltage would show up on the mesa-7i65.0.analogue.07.in pin instead of mesa-7i65.0.analogue.00.in.
  • One or another of the analog input HAL pins would read a perfectly steady 6.25V, which is the voltage you'd get if you interpreted the CPLD input SPI frame as an ADC value. Driving the misc input pins high or low would change this "voltage" in the expected ways.
  • The mapping between physical analog input pins and HAL pins (and the analog input pin in HAL that appeared to carry the "CPLD Misc Input" frame) would change over time.

We (well, Jeff, who's the brains of our group) observed the following things:

From this we we formed the theory that there was unexpected stuff in the BSPI receive FIFO, before the values the driver expects based on the TRAM packet. Those junk frames in the receive FIFO would get read out before the actual frames that the driver expects. The old junk frames in the FIFO would still get interpreted according to the TRAM structure, and parsed into analog and digital hal pins, leading to the corruption we were seeing.

We inserted the "write anything to the BSPI FIFO Counter register in order to clear the FIFO" change, and it appeared to fix the problem. So we merged to 2.8 and merged up to 2.9, where we needed it.

But then we rebooted and the problem came back, so we must be mistaken about something here...

We'd love extra eyeballs on this. Are the 7i65 BSPI inputs (ADC and CPLD digital inputs) working right for you @andypugh? Were they working before our change, for example on 2.8.4?

@andypugh
Copy link
Collaborator

I do have a 7i65, but I am busy each evening until the weekend, then off to the Alps to slide down them. So I don't know when I will be able to get to it.

This thread might warrant further study: https://sourceforge.net/p/emc/mailman/message/29739585/

@SebKuzminsky SebKuzminsky deleted the hm2-bspi-fixes branch January 22, 2023 22:10
@ShadeTechnik
Copy link

What's the status on these changes to bspi? I'm having some trouble getting any life out of bspi using a 7i92 with a stripped down 7i65 component. Not sure these issues are the same as mine but it doesn't look like they are specific to the 7i65.

@pcw-mesa
Copy link
Collaborator

pcw-mesa commented Aug 4, 2023

One improvement I can see is is for the read function to check if the expected amount of data is in the RX FIFO
and if not (due to dropped packets etc) clear the FIFO, use the previous cycles read data and clear the FIFO
on the next write function.

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

Successfully merging this pull request may close these issues.

None yet

5 participants