Skip to content

ESP32C3 interrupts, GPIO and UART support #2167

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

Closed
wants to merge 19 commits into from

Conversation

zdima
Copy link
Contributor

@zdima zdima commented Oct 10, 2021

Added and integrated interrupts, GPIO and UART.
The test examples are:
src/examples/esp/esp32c3/pininterrupt.go
src/examples/esp/esp32c3/echo.go
The signal vector remain in .text.
Moving it to the .init or even to the bottom of the .text segment breaks the signals functionality.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very large PR. I haven't gone through all of it yet.
Can you perhaps make it smaller, so that it is easier to review and maintain?

  • This PR implements both pin interrupts and UART. I would prefer it it only implemented one of them (you can always make a PR with the other one later).
  • This PR implements nested interrupts, but do we really need those? I would suggest simple non-nested interrupts (like in the fe310 chip) for now, to keep things easy to understand.
  • More generally, it looks like you've copied a lot of code from ESP-IDF. Please make sure you understand what every piece of it is doing, and if you don't understand it, remove it. For example, you are passing two parameters to handleInterrupt from esp32c3_intr.S but don't actually use those parameters.
  • Why do you move code from machine_esp32c3.go to new files? It's done for some other chips, but I honestly don't think it improves readability (it will make the list of files in the machine package very long). And in this case, it makes the diff bigger and thus the code becomes harder to review.

Comment on lines +107 to +108
.rept 5
j _interrupt_handler /* 6 identical entries, all pointing to the interrupt handler */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there 5 or 6 identical entries? The comment and .rept statement disagree.

addi t0, sp, CONTEXT_SIZE /* restore sp with the value when trap happened */
sw t0, 34*REGSIZE(sp)

/* Call handleException(sp) or handleException(sp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleException or handleException? This doesn't look right.

Comment on lines +98 to +100
for {
riscv.Asm("wfi")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should call abort.

Comment on lines +182 to +191
/* Increase interrupt threshold level */
li t2, 0x7fffffff
and t1, s1, t2 /* t1 = mcause & mask */
slli t1, t1, 2 /* t1 = mcause * 4 */
li t2, CPU_INT_PRI_0_REG
add t1, t2, t1 /* t1 = INTC_INT_PRIO_REG + 4 * mcause */
lw t2, 0(t1) /* t2 = INTC_INT_PRIO_REG[mcause] */
addi t2, t2, 1 /* t2 = t2 +1 */
sw t2, 0(t0) /* CPU_INT_THRESH = t2 */
fence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are implementing nested interrupts here. Is this intentional? Did you test nested interrupts?

Comment on lines +10 to +14
uartConfig := &machine.UARTConfig{
BaudRate: 115200,
TX: machine.Pin(2),
RX: machine.Pin(5),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need a new example?

@@ -14,131 +13,92 @@ func CPUFrequency() uint32 {
return 160e6 // 160MHz
}

type Module int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's a module? It seems like this is something internal to the ESP32-C3, and therefore should not be part of the public API.

@zdima
Copy link
Contributor Author

zdima commented Oct 12, 2021

@aykevl
I have submitted another PR #2170 for interrupt only

@zdima zdima closed this Oct 12, 2021
@sago35
Copy link
Member

sago35 commented Jan 6, 2022

@zdima
It would be nice to be able to use UART interrupts, etc.

@sago35 sago35 mentioned this pull request Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants