Skip to content

Commit

Permalink
Change set to produce a working blinky example
Browse files Browse the repository at this point in the history
This is a minimum viable set of changes to tinygo, to get a blinky
example running. These should be broken into separate steps. The
changes are roughly:

* Remove the second stage bootloader because it has been replaced by the
  boot rom on the rp2040
* Add a minimum viable image desciptor to the binary, to allow the
  boot rom to recongize the binary as an application
* Disable the peripheral resets because the hardware works differently
  than the RP2040 (need to re-evaluate this)
* Skip PLL init because the boot rom should have enabled it. This should
  definitely be fixed and then re-enabled.
* When enabling a GPIO pin, disable the isolation latch

Only the GPIO hardware seems functional, the init routines should be
improved before continuing with other peripherals.
  • Loading branch information
cibomahto committed Nov 17, 2024
1 parent 52bd80d commit fbb5234
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/machine/machine_rp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func machineInit() {
bits = ^uint32(initUnreset)
unresetBlockWait(bits)

clocks.init()
// clocks.init()

// Peripheral clocks should now all be running
unresetBlockWait(RESETS_RESET_Msk)
Expand Down
10 changes: 5 additions & 5 deletions src/machine/machine_rp2350_resets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ var resets = (*resetsType)(unsafe.Pointer(rp.RESETS))
// resetBlock resets hardware blocks specified
// by the bit pattern in bits.
func resetBlock(bits uint32) {
resets.frceOff.Set(bits)
// resets.frceOff.Set(bits)
}

// unresetBlock brings hardware blocks specified by the
// bit pattern in bits out of reset.
func unresetBlock(bits uint32) {
resets.frceOn.Set(bits)
// resets.frceOn.Set(bits)
}

// unresetBlockWait brings specified hardware blocks
// specified by the bit pattern in bits
// out of reset and wait for completion.
func unresetBlockWait(bits uint32) {
unresetBlock(bits)
for !resets.resetDone.HasBits(bits) {
}
// unresetBlock(bits)
// for !resets.resetDone.HasBits(bits) {
// }
}
2 changes: 2 additions & 0 deletions src/machine/machine_rp2_2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"unsafe"
)

var DefaultUART = UART0

const (
LED = GPIO25
_NUMBANK0_GPIOS = 48
Expand Down
4 changes: 3 additions & 1 deletion src/machine/machine_rp2_gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (p Pin) setSchmitt(trigger bool) {
func (p Pin) setFunc(fn pinFunc) {
// Set input enable, Clear output disable
p.padCtrl().ReplaceBits(rp.PADS_BANK0_GPIO0_IE,
rp.PADS_BANK0_GPIO0_IE_Msk|rp.PADS_BANK0_GPIO0_OD_Msk, 0)
rp.PADS_BANK0_GPIO0_IE_Msk|rp.PADS_BANK0_GPIO0_OD_Msk|rp.PADS_BANK0_GPIO0_ISO_Msk, 0)

// Zero all fields apart from fsel; we want this IO to do what the peripheral tells it.
// This doesn't affect e.g. pullup/pulldown, as these are in pad controls.
Expand All @@ -136,7 +136,9 @@ func (p Pin) setFunc(fn pinFunc) {
// init initializes the gpio pin
func (p Pin) init() {
mask := uint32(1) << p

rp.SIO.GPIO_OE_CLR.Set(mask)

p.clr()
}

Expand Down
1 change: 1 addition & 0 deletions targets/arm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SECTIONS
.text :
{
KEEP(*(.isr_vector))
KEEP(*(.embedded_block))
*(.text)
*(.text.*)
*(.rodata)
Expand Down
11 changes: 11 additions & 0 deletions targets/embedded_block.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Inspired by embedded_start_block.inc.S and embedded_end_block.inc.S
// Minimum viable block image from datasheet section 5.9.5.1, "Minimum Arm IMAGE_DEF"
.section .embedded_block, "a"
.p2align 2
embedded_block:
.word 0xffffded3
.word 0x10210142
.word 0x000001ff
.word 0x00000000
.word 0xab123579
embedded_block_end:
3 changes: 1 addition & 2 deletions targets/pico2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"rp2350"
],
"build-tags": ["pico2"],
"linkerscript": "targets/pico2.ld",
"linkerscript": "targets/rp2350.ld",
"extra-files": [
"targets/pico_boot_stage2.S"
]
}
5 changes: 3 additions & 2 deletions targets/rp2350.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"msd-firmware-name": "firmware.uf2",
"binary-format": "uf2",
"uf2-family-id": "0xe48bff59","comment":"See page 393 of RP2350 datasheet: RP2350 Arm Secure image (i.e. one intended to be booted directly by the bootrom)",
"rp2040-boot-patch": true,
"extra-files": [
"targets/rp2350_boot2_generic03h.S"
"src/device/rp/rp2350.s",
"targets/rp2350_boot2_generic03h.S",
"targets/embedded_block.S"
],
"linkerscript": "targets/rp2350.ld",
"openocd-interface": "picoprobe",
Expand Down
20 changes: 3 additions & 17 deletions targets/rp2350.ld
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,16 @@ MEMORY
i.e: Separate stacks for core0 and core1. */
SRAM4 : ORIGIN = 0x20080000, LENGTH = 4k
SRAM5 : ORIGIN = 0x20081000, LENGTH = 4k
/* Reserve exactly 256 bytes at start of flash for second stage bootloader */
BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256
FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 2048k - 256
FLASH_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 2048k


RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 512k
}

_stack_size = 2K;

SECTIONS
{
/* Second stage bootloader is prepended to the image. It must be 256 bytes
and checksummed. The gap to the checksum is zero-padded.
*/
.boot2 : {
__boot2_start__ = .;
KEEP (*(.boot2));

/* Explicitly allocate space for CRC32 checksum at end of second stage
bootloader
*/
. = __boot2_start__ + 256 - 4;
LONG(0)
} > BOOT2_TEXT = 0x0

/* The second stage will always enter the image at the start of .text.
The debugger will use the ELF entry point, which is the _entry_point
symbol if present, otherwise defaults to start of .text.
Expand Down

0 comments on commit fbb5234

Please sign in to comment.