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

Dedicated GPIO not work with inline assembly function on ESP32S3 (IDFGH-14544) #15306

Open
3 tasks done
windowsair opened this issue Jan 30, 2025 · 3 comments
Open
3 tasks done
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@windowsair
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v4.4.2

Espressif SoC revision.

ESP32S3

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32S3

Power Supply used.

USB

What is the expected behavior?

I'm trying to use Dedicated GPIO and I've found that inline assembly functions produce different results than non-inline assembly functions:

void setHigh()
{
    __asm__ __volatile__ ("ee.set_bit_gpio_out 0xff" );
}

// inline version
static inline void setHigh()
{
    __asm__ __volatile__ ("ee.set_bit_gpio_out 0xff" );
}

Use objdump to see the results of the non-inline and inline versions separately:

void setHigh()
{
4037ecc8:	004136        	entry	a1, 32
    __asm__ __volatile__ ("ee.set_bit_gpio_out 0xff" );
4037eccb:	754ff4        	lsi	f15, a15, 0x1d4
}
4037ecce:	f01d      	retw.n

// inline version
   __asm__ __volatile__ ("ee.set_bit_gpio_out 0xff" );
42009220:	754ff4        	lsi	f15, a15, 0x1d4

According to TRM, the instruction 754ff4 generated by both function is consistent and correct.
Image

But now only the non-inline version works.

I inserted a large number of nop instructions into the inline version, considering that there may be some delay in function calls. But that didn't work:

// inline version with nop. NOT WORK
static inline void setHigh()
{
    __asm__ __volatile__ ("ee.set_bit_gpio_out 0xff" );
    __asm__ __volatile__ ("nop" );
    __asm__ __volatile__ ("nop" );
// more than 10 nop here
}

Also, calling the cpu_ll_write_dedic_gpio_mask function in esp-idf has the same behavior, and once the inline attribute of cpu_ll_write_dedic_gpio_mask is removed, everything works fine.

What is the actual behavior?

See above.

Steps to reproduce.

See above.

Debug Logs.


More Information.

No response

@windowsair windowsair added the Type: Bug bugs in IDF label Jan 30, 2025
@github-actions github-actions bot changed the title Dedicated GPIO not work with inline assembly function on ESP32S3 Dedicated GPIO not work with inline assembly function on ESP32S3 (IDFGH-14544) Jan 30, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 30, 2025
@suda-morris
Copy link
Collaborator

But now only the non-inline version works.

Do you mean, you can't see the GPIO being "toggle/set/clear" by the CPU instruction? Could you please share a minimal project for us to reproduce? Because we also want to see if you have setup the GPIO correctly.

@windowsair
Copy link
Author

But now only the non-inline version works.

Do you mean, you can't see the GPIO being "toggle/set/clear" by the CPU instruction? Could you please share a minimal project for us to reproduce? Because we also want to see if you have setup the GPIO correctly.

It looks like the time it takes to run inline and non-inline instructions is different, which messes up the timing a bit. I need to insert more nop instructions than expected to make the non-inline version work.

The TRM and esp-idf documentation doesn't say what is the typical time to execute this instruction, i.e. what is the fastest rate of the Dedicated GPIO. I'll verify this with a logic analyzer after the holidays.

@suda-morris
Copy link
Collaborator

@windowsair when you using the dedicate GPIO instructions to simulate any waveforms, please wrap them in a critical section. for example:

portENTER_CRITICAL(&g_lock);
emulate_uart_receive(read_buffer, read_size, port->rx_bit, port->cycles);
portEXIT_CRITICAL(&g_lock);

@espressif-bot espressif-bot assigned songruo and unassigned songruo Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

4 participants