Fly sht36 pro - rp2040 spi

Hi

There is an issue with the Mellow FLY SHT36 Pro as indicated by this post on Mellows site.

The issue is related to the RP2040 software SPI and gcc10 and gcc8.

I checked the latest spi.c in the rp2040 directory and the required gpio pin settings are missing for this board.

cs_pin: FlySHT:gpio20
spi_software_sclk_pin: FlySHT:gpio10
spi_software_mosi_pin: FlySHT:gpio11
spi_software_miso_pin: FlySHT:gpio12

It would be great if this set of gpio’s could be added as I’m sure at some point Klipper will more forward and create an incompatibility with Mellows firmware.

Thanks

I can not see any connection between the pin definition and gcc version issue.
Looks like you have already defined software SPI and it works.

Most probably, you are actually, asking to define HW SPI there, for those pins.

diff --git a/src/rp2040/spi.c b/src/rp2040/spi.c
index 4cf2eb799..d2c8df951 100644
--- a/src/rp2040/spi.c
+++ b/src/rp2040/spi.c
@@ -29,6 +29,8 @@ DECL_ENUMERATION("spi_bus", "spi1_gpio12_gpio15_gpio14", 6);
 DECL_CONSTANT_STR("BUS_PINS_spi1_gpio12_gpio15_gpio14", "gpio12,gpio15,gpio14");
 DECL_ENUMERATION("spi_bus", "spi1_gpio24_gpio27_gpio26", 7);
 DECL_CONSTANT_STR("BUS_PINS_spi1_gpio24_gpio27_gpio26", "gpio24,gpio27,gpio26");
+DECL_ENUMERATION("spi_bus", "spi1_gpio12_gpio11_gpio10", 8);
+DECL_CONSTANT_STR("BUS_PINS_spi1_gpio12_gpio11_gpio10", "gpio12,gpio11,gpio10");
 
 //Deprecated "spi0a" style mappings
 DECL_ENUMERATION("spi_bus", "spi0a", 0);
@@ -63,6 +65,7 @@ static const struct spi_info spi_bus[] = {
     {spi1_hw, 8,  11, 10, RESETS_RESET_SPI1_BITS},
     {spi1_hw, 12, 15, 14, RESETS_RESET_SPI1_BITS},
     {spi1_hw, 24, 27, 26, RESETS_RESET_SPI1_BITS},
+    {spi1_hw, 12, 11, 10, RESETS_RESET_SPI1_BITS},
 };
 
 struct spi_config

I think it is possible.

Hope that helps.

Sorry, maybe I did not say what I needed clearly, software SPI does not work with current Klipper so Mellows old version is needed.

It would be great if hardware could be made to work.

I see from that you had the knowledge to identify the pin order using the software spi details.
I tried to work this out but it was not documented in the source.

pi@voron2:~/klipper $ patch < ~/SHT36ProSPI.patch -p1
patching file src/rp2040/spi.c
pi@voron2:~/klipper $ 

Got the following error

pin gpio12 is reserved for spi1_gpio12_gpio11_gpio10

With the config of

[tmc5160 extruder]
cs_pin: FlySHT:gpio20
#spi_software_sclk_pin: FlySHT:gpio10       
#spi_software_mosi_pin: FlySHT:gpio11
#spi_software_miso_pin: FlySHT:gpio12
spi_bus: spi1_gpio12_gpio11_gpio10
interpolate: False
run_current: 0.8
sense_resistor: 0.075
stealthchop_threshold: 0

Got the following error

Are you sure there is no other SPI definition in the configuration?
Like for the MAX31865

Generally, you will see it, if pin is defined multiple times in an incompatible manner.


The thing is, it should work with SW SPI.
I hooked up an oscilloscope, to check what was wrong here.
Well

RP2040 is just too fast right now.
I suspect GCC 8 generate slow enough code in the past to make it work.

I repacked patches, you may want to check the first one, it should make SW SPI work without breaking anything.

Your correct, I have a ADXL configured, I’ll try again.

Yep, I forgot about the ADXL.

So when are your patches going to be added to Klipper?

@kevin any chance you can get this added to the source? I would rather not run dirty code, but still run a current version of Klipper.
I mean the hardware SPI patch initially and the software SPI once your happy with the more complex patch.

I am struggling with the exact same problem with my SHT36 Pro. I did a Klipper update yesterday and have spent hours trying to fix the the error. I get: “Unable to write tmc spi ‘extruder’ register GLOBALSCALER”. Mellow sent me a custom firmware made with gcc8 some months ago, but now it is not working. Is there any way I can test the: “Software SPI: make it respect rate limits” code to fix it? I am not that fluent on changing stuff on the Rpi, but if it is a “copy paste” command I very much like to try.

I got it to work!!! I used Visual studio code for the code from #nefelim4ag and the commands from #mjoconr. Made a c++ file and saved it as: SHT36ProSPI.patch. saved the file on root (pi) and used the: “patch < ~/SHT36ProSPI.patch -p1 patching file src/rp2040/spi.c”. Got an error about spacing in the code and fixed it again in Visual studio. Flashed the SHT36 Pro and changed the printer.cfg as described. Everything is woking again! I am so happy! I literally spent days trying to find a solution. My Rpi is full of files trying to make a cross compile with the GCC8. Thank you all so very much!

HW SPI Bus definition: RP2040: Another HW bus. by nefelim4ag · Pull Request #6867 · Klipper3d/klipper · GitHub

The printer is printing again! Just doing an autotower test and everything is working fine. Your code was super helpful! Last time I had this problem I spent days tying to find a solution. At the end Mellow made me a custom firmware file, but I had no way of updating the file and run the risk of bricking the machine when updating Klipper. I was thinking I had to buy a new CAN bord and just thrash the SHT36 Pro. Is there a way I can upvote your work on Github? Thank you very much again!

@kevin, @nefelim4ag, thanks for getting this patch into main line so quickly.

Thanks. FYI, I think you may be pinging the wrong person.

Cheers,
-Kevin

Your right, I remember now that your used the koconnor not just kevin :slight_smile: