-
Notifications
You must be signed in to change notification settings - Fork 918
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
Add RP2350 support #4459
Merged
Merged
Add RP2350 support #4459
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
09dcba6
add linker scripts for rp2350
soypat 7502c09
add bootloader
soypat 5934993
add placeholder runtime and machine stubs
soypat 0b8e564
ok, example/blinky1 now compiles...
soypat 87f32ac
begin melding rp2040 and rp2350 APIs
soypat dabefa4
compiles for rp2350, serial=none
soypat 1ef9859
add UART
soypat 1b9b9c9
add assembly and link; compile error remaining
soypat c59f472
fix assembly extension, causing C preprocessor to not execute
soypat 161cfaf
begin adding UART initialization
soypat 9245457
extract pin_init into its own macro
soypat 7875cb4
remove binaries
soypat e34b252
exclude .elf and .uf2 binaries in gitignore
soypat d8db26e
work on adding IMAGE_DEF patching
soypat 54745c0
add rp2350 boot patching
soypat 65a9c06
Fix RP2350 memory layout (#4626)
cibomahto ae722c3
gen-device-svd: enclose assembly description with multi-line comment;…
soypat abd37fc
revert use of tinyboot
soypat f6e1d35
fix last commit slipup
soypat d55b7f0
Implement rp2350 init, clock, and uart support
cibomahto f6f5938
Working USB, but separated
cibomahto f926eeb
Use uart console for rp2350 since USB console crashes with fmt
cibomahto 3cdcfc0
Fix linting issues
cibomahto c30dcb4
Correct usb/serial initialization order
cibomahto d3d3c2d
Implement jump-to-bootloader
cibomahto ba1919f
Fix linting
cibomahto 677ba11
test: add pico2 to smoketests
deadprogram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,9 @@ test.exe | |
test.gba | ||
test.hex | ||
test.nro | ||
test.uf2 | ||
test.wasm | ||
wasm.wasm | ||
|
||
*.uf2 | ||
*.elf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//go:build pico2 | ||
|
||
package machine | ||
|
||
// GPIO pins | ||
const ( | ||
GP0 Pin = GPIO0 | ||
GP1 Pin = GPIO1 | ||
GP2 Pin = GPIO2 | ||
GP3 Pin = GPIO3 | ||
GP4 Pin = GPIO4 | ||
GP5 Pin = GPIO5 | ||
GP6 Pin = GPIO6 | ||
GP7 Pin = GPIO7 | ||
GP8 Pin = GPIO8 | ||
GP9 Pin = GPIO9 | ||
GP10 Pin = GPIO10 | ||
GP11 Pin = GPIO11 | ||
GP12 Pin = GPIO12 | ||
GP13 Pin = GPIO13 | ||
GP14 Pin = GPIO14 | ||
GP15 Pin = GPIO15 | ||
GP16 Pin = GPIO16 | ||
GP17 Pin = GPIO17 | ||
GP18 Pin = GPIO18 | ||
GP19 Pin = GPIO19 | ||
GP20 Pin = GPIO20 | ||
GP21 Pin = GPIO21 | ||
GP22 Pin = GPIO22 | ||
GP26 Pin = GPIO26 | ||
GP27 Pin = GPIO27 | ||
GP28 Pin = GPIO28 | ||
|
||
// Onboard LED | ||
LED Pin = GPIO25 | ||
|
||
// Onboard crystal oscillator frequency, in MHz. | ||
xoscFreq = 12 // MHz | ||
) | ||
|
||
// I2C Default pins on Raspberry Pico. | ||
const ( | ||
I2C0_SDA_PIN = GP4 | ||
I2C0_SCL_PIN = GP5 | ||
|
||
I2C1_SDA_PIN = GP2 | ||
I2C1_SCL_PIN = GP3 | ||
) | ||
|
||
// SPI default pins | ||
const ( | ||
// Default Serial Clock Bus 0 for SPI communications | ||
SPI0_SCK_PIN = GPIO18 | ||
// Default Serial Out Bus 0 for SPI communications | ||
SPI0_SDO_PIN = GPIO19 // Tx | ||
// Default Serial In Bus 0 for SPI communications | ||
SPI0_SDI_PIN = GPIO16 // Rx | ||
|
||
// Default Serial Clock Bus 1 for SPI communications | ||
SPI1_SCK_PIN = GPIO10 | ||
// Default Serial Out Bus 1 for SPI communications | ||
SPI1_SDO_PIN = GPIO11 // Tx | ||
// Default Serial In Bus 1 for SPI communications | ||
SPI1_SDI_PIN = GPIO12 // Rx | ||
) | ||
|
||
// UART pins | ||
const ( | ||
UART0_TX_PIN = GPIO0 | ||
UART0_RX_PIN = GPIO1 | ||
UART1_TX_PIN = GPIO8 | ||
UART1_RX_PIN = GPIO9 | ||
UART_TX_PIN = UART0_TX_PIN | ||
UART_RX_PIN = UART0_RX_PIN | ||
) | ||
|
||
var DefaultUART = UART0 | ||
|
||
// USB identifiers | ||
const ( | ||
usb_STRING_PRODUCT = "Pico2" | ||
usb_STRING_MANUFACTURER = "Raspberry Pi" | ||
) | ||
|
||
var ( | ||
usb_VID uint16 = 0x2E8A | ||
usb_PID uint16 = 0x000A | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,38 +1,55 @@ | ||||||
//go:build rp2040 | ||||||
//go:build rp2040 || rp2350 | ||||||
|
||||||
package machine | ||||||
|
||||||
import ( | ||||||
"device/rp" | ||||||
"runtime/interrupt" | ||||||
"runtime/volatile" | ||||||
"unsafe" | ||||||
) | ||||||
|
||||||
const deviceName = rp.Device | ||||||
|
||||||
const ( | ||||||
// Number of spin locks available | ||||||
// Note: On RP2350, most spinlocks are unusable due to Errata 2 | ||||||
_NUMSPINLOCKS = 32 | ||||||
_PICO_SPINLOCK_ID_IRQ = 9 | ||||||
) | ||||||
|
||||||
// UART on the RP2040 | ||||||
var ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should update comment:
Suggested change
|
||||||
UART0 = &_UART0 | ||||||
_UART0 = UART{ | ||||||
Buffer: NewRingBuffer(), | ||||||
Bus: rp.UART0, | ||||||
} | ||||||
|
||||||
UART1 = &_UART1 | ||||||
_UART1 = UART{ | ||||||
Buffer: NewRingBuffer(), | ||||||
Bus: rp.UART1, | ||||||
} | ||||||
) | ||||||
|
||||||
func init() { | ||||||
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) | ||||||
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt) | ||||||
} | ||||||
|
||||||
//go:linkname machineInit runtime.machineInit | ||||||
func machineInit() { | ||||||
// Reset all peripherals to put system into a known state, | ||||||
// except for QSPI pads and the XIP IO bank, as this is fatal if running from flash | ||||||
// and the PLLs, as this is fatal if clock muxing has not been reset on this boot | ||||||
// and USB, syscfg, as this disturbs USB-to-SWD on core 1 | ||||||
bits := ^uint32(rp.RESETS_RESET_IO_QSPI | | ||||||
rp.RESETS_RESET_PADS_QSPI | | ||||||
rp.RESETS_RESET_PLL_USB | | ||||||
rp.RESETS_RESET_USBCTRL | | ||||||
rp.RESETS_RESET_SYSCFG | | ||||||
rp.RESETS_RESET_PLL_SYS) | ||||||
bits := ^uint32(initDontReset) | ||||||
resetBlock(bits) | ||||||
|
||||||
// Remove reset from peripherals which are clocked only by clkSys and | ||||||
// clkRef. Other peripherals stay in reset until we've configured clocks. | ||||||
bits = ^uint32(rp.RESETS_RESET_ADC | | ||||||
rp.RESETS_RESET_RTC | | ||||||
rp.RESETS_RESET_SPI0 | | ||||||
rp.RESETS_RESET_SPI1 | | ||||||
rp.RESETS_RESET_UART0 | | ||||||
rp.RESETS_RESET_UART1 | | ||||||
rp.RESETS_RESET_USBCTRL) | ||||||
bits = ^uint32(initUnreset) | ||||||
unresetBlockWait(bits) | ||||||
|
||||||
clocks.init() | ||||||
|
@@ -94,4 +111,25 @@ const ( | |||||
) | ||||||
|
||||||
// DMA channels usable on the RP2040. | ||||||
var dmaChannels = (*[12]dmaChannel)(unsafe.Pointer(rp.DMA)) | ||||||
var dmaChannels = (*[12 + 4*rp2350ExtraReg]dmaChannel)(unsafe.Pointer(rp.DMA)) | ||||||
|
||||||
//go:inline | ||||||
func boolToBit(a bool) uint32 { | ||||||
if a { | ||||||
return 1 | ||||||
} | ||||||
return 0 | ||||||
} | ||||||
|
||||||
//go:inline | ||||||
func u32max(a, b uint32) uint32 { | ||||||
if a > b { | ||||||
return a | ||||||
} | ||||||
return b | ||||||
} | ||||||
|
||||||
//go:inline | ||||||
func isReservedI2CAddr(addr uint8) bool { | ||||||
return (addr&0x78) == 0 || (addr&0x78) == 0x78 | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be commented out here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No patch required for rp2350 from my understanding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we should remove this, no?