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

[BUG] ESP32C6 SPI Read Issue #13067

Open
1 task done
FelipeMdeO opened this issue Aug 20, 2024 · 16 comments
Open
1 task done

[BUG] ESP32C6 SPI Read Issue #13067

FelipeMdeO opened this issue Aug 20, 2024 · 16 comments
Labels
Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: Drivers Drivers issues OS: Linux Issues related to Linux (building system, etc) Type: Bug Something isn't working

Comments

@FelipeMdeO
Copy link
Contributor

FelipeMdeO commented Aug 20, 2024

Description / Steps to reproduce the issue

Hello All,

I am porting MFRC522 rfid card reader to esp32 c6. During port test I am facing issue related SPI message read.

1 - Add breakpoint in mfrc522_getfwversion() function, - I did minor change in code, not necessary:
file: mfrc522.c
line 1160

image

2 - Run the code until it hits the breakpoint
image

3 - In my case I start logic analyze and hit "next" in the gdb.
Looking syslog msgs and results in logic Analyze We can see that the rfid IC answer 0xB2, but spi drive can't get this value.

Look images below:
image
image

On which OS does this issue occur?

[Linux]

What is the version of your OS?

Ubuntu 24

NuttX Version

master

Issue Architecture

[risc-v]

Issue Area

[Drivers]

Verification

  • I have verified before submitting the report.
@FelipeMdeO FelipeMdeO added the Type: Bug Something isn't working label Aug 20, 2024
@acassis
Copy link
Contributor

acassis commented Aug 20, 2024

@fdcavalcanti PTAL

@FelipeMdeO
Copy link
Contributor Author

Hello @fdcavalcanti

I added a breakpoint in:
esp_spi.c:759

Reading:
trans.rcv_buffer and trans.send_buffer it always have same value, maybe this behavior explain how the example is working.

Steps:
1 - add breakpoint in mfrc522_getfwversion function.
2 - add brakpoint in esp_spi.c esp_spi_poll_send function

Running code and get trans.* value, you will see:
image

Note: 0xee is expected value:
( 0x80 | (MFRC522_VERSION_REG & 0x7e)

@fdcavalcanti
Copy link
Contributor

fdcavalcanti commented Aug 20, 2024

Hello @FelipeMdeO, let's figure this out.

We'll start making sure there's no hardware issues.

  • Is it an Espressif dev-kit or a custom board?
  • Which pins are you using with SPI?
  • Any pull-ups on the circuit?
  • Which SPI mode are you working with? just noticed it is already inside the lock function.

@github-actions github-actions bot added Area: Drivers Drivers issues OS: Linux Issues related to Linux (building system, etc) Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture labels Aug 20, 2024
@FelipeMdeO
Copy link
Contributor Author

FelipeMdeO commented Aug 20, 2024

Hello @fdcavalcanti

1 -
I am using esp32c6 dev kit m and rfid-rc522 rf card read:
image

2 -
SPI2 CS - 15
SPI2 CLK - 6
SPI2 MOSI - 7
SPI2 MISO - 2

3 - No, direct connection
image

I don't know if this the right way to share, but I did changes in fork from nuttx master:
https://github.com/FelipeMdeO/nuttx.git
branch: esp32-mfrc522-support

Below, my defconfig:

defconfig.zip

@fdcavalcanti
Copy link
Contributor

fdcavalcanti commented Aug 21, 2024

I see no issue on C6 driver side.
Please use NuttX main branch and try again. We need to be on common ground regarding the source code.
Let me know if anything different happens.

@FelipeMdeO
Copy link
Contributor Author

Hello @fdcavalcanti,

How do you test in your side?
I will try do the same thing on my side.

@FelipeMdeO
Copy link
Contributor Author

FelipeMdeO commented Aug 21, 2024

Hello @fdcavalcanti.

I tested using spi example and known slave device, in this situation it worked properly. So the issue is not in the drive.
I will investigate it better, sorry for false bug.

@fdcavalcanti
Copy link
Contributor

No problem! Good luck.

@FelipeMdeO
Copy link
Contributor Author

Hello @fdcavalcanti ,

I am reopen this issue, I will explain.

My issue happens when I tried use MFRC522 driver, this driver uses SPI_SEND function:
image

Using SPI_SEND function I cannot get read data properly.

The ESP SPI example uses SPI_EXCHANGE function. When we request once a byte, it send using exchange with nwords=1.

To do a proof, I changed the spi driver to esp_spi_send call esp_spi_exchange instead of esp_spi_poll_send

image

In this way I was able to read MFRF522 FW Version.

@fdcavalcanti can you check SPI_SEND in your side, please ?

@FelipeMdeO FelipeMdeO reopened this Aug 23, 2024
@FelipeMdeO
Copy link
Contributor Author

Hello,

I was clear in my last explanation, do you need more information?

@fdcavalcanti
Copy link
Contributor

Hi Felipe. I don't have this hardware to test.
But could you please try this inside esp_spi_poll_send:

------------------ arch/risc-v/src/common/espressif/esp_spi.c ------------------
index e84b22b336..4988f17aa3 100644
@@ -750,8 +750,9 @@ static uint32_t esp_spi_poll_send(struct esp_spi_priv_s *priv, uint32_t wd)
   trans.line_mode.cmd_lines = 0;
   priv->ctx->trans_config = trans;
 
-  spi_ll_set_mosi_bitlen(priv->ctx->hw, priv->nbits);
+  // spi_ll_set_mosi_bitlen(priv->ctx->hw, priv->nbits);
   spi_hal_prepare_data(priv->ctx, priv->dev_cfg, &trans);
+  spi_hal_setup_trans(priv->ctx, priv->dev_cfg, &trans);
   spi_hal_user_start(priv->ctx);

Make sure the rest of the file is the same as the main branch.

@FelipeMdeO
Copy link
Contributor Author

Hello @fdcavalcanti,

Sorry, not yet.
I put side by side comparation between SPI Exchange and SPI Send result.
Note that the SPI Send return strange data, like memory address, this happens with current master code too.
Maybe you can try use any spi slave device, if it uses SPI Send in the driver.

image

@acassis
Copy link
Contributor

acassis commented Aug 27, 2024

Hi Felipe. I don't have this hardware to test. But could you please try this inside esp_spi_poll_send:

------------------ arch/risc-v/src/common/espressif/esp_spi.c ------------------
index e84b22b336..4988f17aa3 100644
@@ -750,8 +750,9 @@ static uint32_t esp_spi_poll_send(struct esp_spi_priv_s *priv, uint32_t wd)
   trans.line_mode.cmd_lines = 0;
   priv->ctx->trans_config = trans;
 
-  spi_ll_set_mosi_bitlen(priv->ctx->hw, priv->nbits);
+  // spi_ll_set_mosi_bitlen(priv->ctx->hw, priv->nbits);
   spi_hal_prepare_data(priv->ctx, priv->dev_cfg, &trans);
+  spi_hal_setup_trans(priv->ctx, priv->dev_cfg, &trans);
   spi_hal_user_start(priv->ctx);

Make sure the rest of the file is the same as the main branch.

@FelipeMdeO I think you can use the spi tool to so this test. Just do the ordinary loop test, but using send instead of exchange command.

@FelipeMdeO
Copy link
Contributor Author

Thank you for you suggestion @acassis, very nice.

I did changes in spi_transfer.c to use SPI_SEND instead SPI_EXCHANGE in the spi tool.
Transfer is ok, so I don't know whats happen when I am try send/read data to MFRC device.

I will take a look better during next days.

image
image

@acassis
Copy link
Contributor

acassis commented Aug 28, 2024

Actually the message was to Filipe Cavalcanti that doesn't have the board:
@fdcavalcanti (since you don't have the board) I think you can use the spi tool to so this test. Just do the ordinary loop test, but using send instead of exchange command.

@fdcavalcanti
Copy link
Contributor

Recommend checking if #13780 changed anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: Drivers Drivers issues OS: Linux Issues related to Linux (building system, etc) Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants