Ansem-SoD / Picofly

Information and firmware related to the rp2040-zero based chip for the nx
867 stars 122 forks source link

Is "==" error message for CLK connection really implemented? #28

Open Quas7 opened 10 months ago

Quas7 commented 10 months ago

During compilation I noticed a compiler warning stating that the variable _clkok is not used and indeed the _selftest() does not call _safe_testvoltage() function to test for PIN_CLK compared to the other pins.

This might have been done intentionally, as the CLK is not giving a stable voltage reading by nature and threfore the test might fail randomly even if PIN_CLK is connected perfectly.
If this is the case and assuming that the CLK frequency is higher than the ADC sample rate, testing for the mid-voltage (0.9f) might do the trick as the CLK should be a 50:50 duty cycle.

https://github.com/Ansem-SoD/Picofly/blob/cc1099d6e9f659425b132fc73b9153fe07d605f8/code/usk/main.c#L53C1-L68C1

// test all ADC pins
void self_test()
{
    absolute_time_t tio_time = make_timeout_time_ms(2500);
    adc_init();
    bool rst_ok = false, cmd_ok = false, d0_ok = false, clk_ok = false;
    while (!time_reached(tio_time)) {
        if (!rst_ok)
            rst_ok |= safe_test_voltage(PIN_RST, 1.8f, 0.2f);
        if (!cmd_ok)
            cmd_ok |= safe_test_voltage(PIN_CMD, 1.8f, 0.2f);
        if (!d0_ok)
            d0_ok |= safe_test_voltage(PIN_DAT, 1.8f, 0.2f);
        if (rst_ok && cmd_ok && d0_ok)
            break;
    }

A quick sweep of the use of PIN_CLK did not show up any other test method and also no call for halt_with_error(3,2) (should be "==") can be found.

Therefore, I suspect that the error "== CLK is not connected" does never show up and a missing CLK signal will result in another maybe unrelated error indication. I will test this during my next picofly install this weekend.

For the sake of completeness: Brute-force error-code listing as I could not wrap my head around halt_with_error() within one minute ;)

#include <iostream>
using namespace std;
int main()
{
    for (int err=0; err <= 15; err++)
    {
        for (int bits=0; bits <= 4; bits++) 
        {
            for (int i = 0; i < bits; i++) 
            {
                bool is_long = err & ( 1 << (bits -i -1));
                cout<<"err: ";
                cout<<err;
                cout<<"  ";
                cout<<"bits: ";
                cout<<bits;
                cout<<"  ";
                cout<<"is_long:  ";
                cout<<is_long;
                cout<<"\n";
            }
            cout<<"\n";
        }
    }
    return 0;
}
TheCyberQuake commented 1 month ago

I can confirm that during my install, I had an issue with the connection to CLK, and during troubleshooting I was getting an entirely unrelated and undocumented error code (*==). Had to poke around with a multimeter to realize that CLK was the issue.