esp-hosted icon indicating copy to clipboard operation
esp-hosted copied to clipboard

esp-hosted-fg SPI can't use pin 33 as HS or DR

Open JAndrassy opened this issue 2 years ago • 6 comments

functions set_handshake_gpio, reset_handshake_gpio, set_dataready_gpio and reset_dataready_gpio use WRITE_PERI_REG which treats mask as a 32 bit value.

I want to make esp-hosted-fg work on Arduino Nano RP2040 Connect where the io available for DR and HS are io 0 and io 33.

JAndrassy avatar Jan 13 '24 10:01 JAndrassy

WRITE_PERI_REG are all slave side part. Don't you use the slave and slave software as is?

You can always change the host, as per your need.

I am still trying to understand the problem, if you could detail a bit.

mantriyogesh avatar Jan 13 '24 10:01 mantriyogesh

spi_slave_api_.c

the io 33 mask for WRITE_PERI_REG is 1 << 33 which doesn't fit into 32 bits, but WRITE_PERI_REG casts it to 32 bit.

I think correct is

static inline void set_handshake_gpio(void)
{
  gpio_set_level(GPIO_HS, 1);
}

static inline void reset_handshake_gpio(void)
{
  gpio_set_level(GPIO_HS, 0);
}

static inline void set_dataready_gpio(void)
{
  gpio_set_level(GPIO_DR, 1);
}

static inline void reset_dataready_gpio(void)
{
  gpio_set_level(GPIO_DR, 0);
}

https://content.arduino.cc/assets/ABX00053-schematics.pdf

JAndrassy avatar Jan 13 '24 11:01 JAndrassy

Yes. You are correct. Either use above changes, or use 1ULL << 33

mantriyogesh avatar Jan 14 '24 01:01 mantriyogesh

just 1ll is not enough

#define WRITE_PERI_REG(addr, val) do {                                                                                 \
            ASSERT_IF_DPORT_REG((addr), WRITE_PERI_REG);                                                               \
            (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val);                                       \
        } while(0)

there is (uint32_t)(val);

JAndrassy avatar Jan 14 '24 04:01 JAndrassy

@JAndrassy ,

Yes, you are absolutely correct. We will correct the master with this change.

mantriyogesh avatar Jan 14 '24 15:01 mantriyogesh

I see now, there is already a PR https://github.com/espressif/esp-hosted/pull/248/ from last year

JAndrassy avatar Mar 06 '24 12:03 JAndrassy