newracom / nrc7292_sw_pkg

NRC7292 Software Package for Host mode (Linux OS)
http://www.newracom.com/product
GNU General Public License v2.0
58 stars 27 forks source link

FT232H configuration #77

Open Avamander opened 1 year ago

Avamander commented 1 year ago

I built the ft232 module and enabled ft232h_usb_spi in start.py, but dmesg doesn't say anything besides Succeed to register spi driver(nrc80211). .

I suspected a mismatch between the FT232H wiring expected by the ft232h-usb-spi module and the pins labeled for SPI on the Adafruit FT232H Breakout board, but I can't figure out where.

On the Adafruit board the pinout is as follows:

D0 - SCK/SCL
D1 - MOSI
D2 - MISO
D3 - SPICS 

From the FT232 documentation in MPSSE mode these should be equivalent to:

ADBUS0 - TCK/SK
ADBUS1 - TDI/DO
ADBUS2 - TDO/DI
ADBUS3 - TMS/CS

From AN-7292-008-FT232H_USB_SPI.pdf:

MPSSE_GPIOL0 - 500
MPSSE_GPIOL1 - 501
MPSSE_GPIOL2 - 502
MPSSE_GPIOL3 - 503 

So this seems correct, but after running the following commands, I can't see a new wireless interface or any dmesg output related to the module except Succeed to register spi driver(nrc80211)..

sudo insmod ./nrc7292_sw_pkg/package/src/ft232h-usb-spi/spi-ft232h.ko latency=1 spi_bus_num=3 gpio_base_num=500
sudo insmod ./nrc7292_sw_pkg/package/src/nrc/nrc.ko fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat listen_interval=1000 debug_level_all=1 spi_bus_num=3 spi_polling_interval=5 spi_cs_num=503 spi_gpio_irq=-1
newracom commented 11 months ago

Dear @Avamander,

Thank you for your inquiry.

Could you try with following insmod command?

sudo insmod ./nrc7292_sw_pkg/package/src/nrc/nrc.ko fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat listen_interval=1000 debug_level_all=1 hifspeed=15000000 spi_bus_num=3 spi_cs_num=0 spi_gpio_irq=503 spi_polling_interval=50

As evident from this command, hifspeed should be configured as 15MHz for FT232H. Additionally, spi_cs_num should be set to 0, and spi_gpio_irq should be either 500 or 503.

Best regards, Newracom

Avamander commented 11 months ago

@newracom

Could you try with following insmod command?

I tried it but that provided no difference in dmesg. Just in case I also rebuilt the spi-ft232h module in debug:

Indeed it is in host mode hprt0 = 00021501
usb 1-1: new high-speed USB device number 5 using dwc_otg
Indeed it is in host mode hprt0 = 00001101
usb 1-1: New USB device found, idVendor=0403, idProduct=6014, bcdDevice= 9.00
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1: Product: Single RS232-HS
usb 1-1: Manufacturer: FTDI
platform ftdi-mpsse-spi.0: ftdi_mpsse_spi_probe done
spi_ft232h 1-1:1.0: gpiochip: label=ftdi-mpsse-gpio.0 base=500 ngpio=12
platform ftdi-mpsse-spi.0: spi_master: bus_num=2
spi_ft232h 1-1:1.0: clock_divisor: divide_by_5=off div=581024000436600832 master=60000000 output=0
spi_ft232h 1-1:1.0: clock frequency: 30000000 -> 0
platform ftdi-mpsse-spi.0: latency timer: 16ms -> 1ms
spi_ft232h 1-1:1.0: ftdi_set_latency_timer: setting latency timer = 1
Succeed to register spi driver(nrc80211).

I also attached a logic analyzer to D0, D1, D2, D3. Even though D0 (CLK) and D1 (MOSI) are logic level low, I see no actual activity.

Additionally, spi_cs_num should be set to 0,

Just to be sure, spi_cs_num=0 corresponds to which pin on the FT232?

and spi_gpio_irq should be either 500 or 503.

I did not connect IRQ because polling was supported and it was unclear which pin on the FT232 breakout was going to be utilized. Though wouldn't 500 be ADBUS0/SCK/CLK and 503 ADBUS3/SPICS/CS?

Avamander commented 11 months ago

@newracom It seems like the nrc module will not initialize itself if there isn't an overlay for it. There's also no way to use the non-DT initialization on newer kernels. I also can't figure out how would one even write an overlay to use the FT232H module.

What's the recommended approach on new kernels on regular PCs? (That don't utilize device trees(?))

newracom commented 11 months ago

Dear @Avamander,

Please refer to following table.

Please update the spi_gpio_irq parameter value to match your GPIO pin for HSPI_EIRQ.

If there are any additional logs after "Succeed to register spi driver(nrc80211)," kindly inform us.

Best regards, Newracom

Avamander commented 11 months ago

@newracom

Please update the spi_gpio_irq parameter value to match your GPIO pin for HSPI_EIRQ.

Thank you for this image, following that wiring seems to have had no effect. In general the module parameters seem to have no effect at all. The driver gets registered but nothing besides that.

If there are any additional logs after "Succeed to register spi driver(nrc80211)," kindly inform us.

If I apply the overlay that this repository provides then the module actually tries to initialize the radio (but using the incorrect SPI bus 0, even if defined otherwise, it seems).

Avamander commented 11 months ago

Yeah, no success in getting the kernel module to actually do anything with the FT232H SPI bus, if there's an overlay for using a physical SPI bus the module actually loads on the same machine. It even seems that trying to override the bus using module arguments does not work with an overlay in effect. Could there be an incompatibility with trying to use FT232H with a RPi?

I'd really like to get it working in order to work on native wpa_supplicant and hostapd support.

Avamander commented 6 months ago

I tried to revisit this using the latest driver, but the best I can see is still usbcore: registered new interface driver spi_ft232h and Succeed to register spi driver(nrc80211). But this practically means that the driver is not actually loaded (no nrc-specific log lines). When I replug the FT232 module I also see spi_ft232h 1-1:1.0: gpiochip: label=ftdi-mpsse-gpio.0 base=500 ngpio=12, so at least that part seems to interface fine.

Does the driver actually work without an overlay?

Avamander commented 5 months ago

@newracom It seems that on newer Linux kernels the module is always built with CONFIG_SPI_USE_DT which makes it not behave correctly without a warning.

I've resorted to force-disabling the flag and reimplementing spi_busnum_to_master. Then the module loads and seems to basically work. Ideally these changes are also made for your driver.

It should also be noted that the working config with this wiring is fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat listen_interval=1000 debug_level_all=1 hifspeed=500000 spi_bus_num=3 spi_cs_num=0 spi_gpio_irq=5 (Note the 5 instead of 503, but I haven't investigated why 5 seems to work.)