forked fromzephyrproject-rtos/gsoc-2022-arduino-core
Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork22
RPI RP 2040 support#144
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
pennam wants to merge6 commits intoarduino:arduinoChoose a base branch frompennam:rpi_2040
base:arduino
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
9ee3929
extra: add bin2uf2 tool
pennam16ca6b6
extra: copy uf2 files to firmware folder
pennamd55e832
platform: allow using picotool to burn (boot)loader
pennam8e63528
variant: add rpi_pico_rp2040
pennam7063460
platform: rpi rp2040 fix llext undefined symbol __gnu_thumb1_case_uqi
pennamadf920a
rp2040: enable usb device and usb serial console
pennamFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletionsboards.txt
This file contains hidden or 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
1 change: 1 addition & 0 deletionsextra/bin2uf2/.gitignore
This file contains hidden or 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 @@ | ||
bin2uf2 |
3 changes: 3 additions & 0 deletionsextra/bin2uf2/go.mod
This file contains hidden or 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,3 @@ | ||
module github.com/pennam/bin2uf2 | ||
go 1.21 |
181 changes: 181 additions & 0 deletionsextra/bin2uf2/main.go
This file contains hidden or 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,181 @@ | ||
package main | ||
import ( | ||
"encoding/binary" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"unsafe" | ||
) | ||
// UF2 block constants with fixed-size types. | ||
const ( | ||
magic1 uint32 = 0x0A324655 | ||
magic2 uint32 = 0x9E5D5157 | ||
magic3 uint32 = 0x0AB16F30 | ||
flags uint32 = 0x00002000 // familyID present | ||
payloadSize uint32 = 256 | ||
blockSize uint32 = 512 | ||
dataSectionSize uint32 = 476 | ||
) | ||
// UF2Block defines the structure of a UF2 block, used as a data container. | ||
// The Payload array is sized to hold the entire data section, so the unused | ||
// portion of the array acts as our padding. | ||
type UF2Block struct { | ||
Magic1 uint32 | ||
Magic2 uint32 | ||
Flags uint32 | ||
TargetAddr uint32 | ||
PayloadSize uint32 | ||
BlockNo uint32 | ||
NumBlocks uint32 | ||
FamilyID uint32 | ||
Payload [dataSectionSize]byte | ||
Magic3 uint32 | ||
} | ||
// Calculate the offset of the NumBlocks field within the block struct. | ||
const numBlocksOffset = unsafe.Offsetof(UF2Block{}.NumBlocks) | ||
func main() { | ||
// Define optional string flags for address and family ID | ||
addrStr := flag.String("addr", "0x100E0000", "The starting memory address in hexadecimal format.") | ||
familyIDStr := flag.String("familyID", "0xe48bff56", "The family ID of the target device in hexadecimal format.") | ||
// Customize the default usage message to be more explicit. | ||
flag.Usage = func() { | ||
fmt.Fprintf(os.Stderr, "Usage: %s [options] <source file> <destination file>\n", os.Args[0]) | ||
fmt.Fprintln(os.Stderr, "Converts a binary file to the UF2 format.") | ||
fmt.Fprintln(os.Stderr, "\nOptions:") | ||
flag.PrintDefaults() | ||
} | ||
flag.Parse() | ||
// Check for the correct number of positional arguments. | ||
if len(flag.Args()) != 2 { | ||
flag.Usage() | ||
os.Exit(1) | ||
} | ||
// Parse the address string from the flag. | ||
parsedAddr, err := strconv.ParseUint(strings.TrimPrefix(*addrStr, "0x"), 16, 32) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Invalid address format: %v\n", err) | ||
os.Exit(1) | ||
} | ||
address := uint32(parsedAddr) | ||
// Parse the familyID string from the flag. | ||
parsedFamilyID, err := strconv.ParseUint(strings.TrimPrefix(*familyIDStr, "0x"), 16, 32) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Invalid familyID format: %v\n", err) | ||
os.Exit(1) | ||
} | ||
familyID := uint32(parsedFamilyID) | ||
srcPath := flag.Arg(0) | ||
dstPath := flag.Arg(1) | ||
// Open source file | ||
src, err := os.Open(srcPath) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Could not open source file %s: %v\n", srcPath, err) | ||
os.Exit(1) | ||
} | ||
defer src.Close() | ||
// Create destination file | ||
dst, err := os.Create(dstPath) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Could not create destination file %s: %v\n", dstPath, err) | ||
os.Exit(1) | ||
} | ||
defer dst.Close() | ||
var blockNum uint32 | ||
var totalBlocks uint32 | ||
// This slice is a temporary buffer for reading one payload-worth of data. | ||
readBuffer := make([]byte, payloadSize) | ||
// Main loop to read source and write UF2 blocks | ||
for { | ||
bytesRead, err := io.ReadFull(src, readBuffer) | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil && err != io.ErrUnexpectedEOF { | ||
fmt.Fprintf(os.Stderr, "Error: Failed reading from source file %s: %v\n", srcPath, err) | ||
os.Exit(1) | ||
} | ||
// Create the block struct and populate its fields. | ||
block := UF2Block{ | ||
Magic1: magic1, | ||
Magic2: magic2, | ||
Flags: flags, | ||
TargetAddr: address, | ||
PayloadSize: payloadSize, | ||
BlockNo: blockNum, | ||
NumBlocks: 0, // Placeholder, will be updated later. | ||
FamilyID: familyID, | ||
Magic3: magic3, | ||
} | ||
// Copy the data from our read buffer into the beginning of the | ||
// larger Payload array. The rest of the array remains zero, acting as padding. | ||
copy(block.Payload[:], readBuffer) | ||
// --- Write the block to disk piece-by-piece --- | ||
// 1. Write the header fields | ||
binary.Write(dst, binary.LittleEndian, block.Magic1) | ||
binary.Write(dst, binary.LittleEndian, block.Magic2) | ||
binary.Write(dst, binary.LittleEndian, block.Flags) | ||
binary.Write(dst, binary.LittleEndian, block.TargetAddr) | ||
binary.Write(dst, binary.LittleEndian, block.PayloadSize) | ||
binary.Write(dst, binary.LittleEndian, block.BlockNo) | ||
binary.Write(dst, binary.LittleEndian, block.NumBlocks) | ||
binary.Write(dst, binary.LittleEndian, block.FamilyID) | ||
// 2. Write the entire 476-byte data section (payload + padding) in one go. | ||
if _, err := dst.Write(block.Payload[:]); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Failed writing data section to %s: %v\n", dstPath, err) | ||
os.Exit(1) | ||
} | ||
// 3. Write the final magic number | ||
if err := binary.Write(dst, binary.LittleEndian, block.Magic3); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Failed writing final magic to %s: %v\n", dstPath, err) | ||
os.Exit(1) | ||
} | ||
address += payloadSize | ||
blockNum++ | ||
if err == io.EOF || bytesRead < int(payloadSize) { | ||
break | ||
} | ||
} | ||
totalBlocks = blockNum | ||
// After writing all blocks, seek back and update the totalBlocks field in each header | ||
for i := uint32(0); i < totalBlocks; i++ { | ||
// Calculate the offset using our safe constant instead of a magic number. | ||
offset := int64(i)*int64(blockSize) + int64(numBlocksOffset) | ||
_, err := dst.Seek(offset, io.SeekStart) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Failed seeking in destination file %s: %v\n", dstPath, err) | ||
os.Exit(1) | ||
} | ||
if err := binary.Write(dst, binary.LittleEndian, totalBlocks); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: Failed updating total blocks in %s: %v\n", dstPath, err) | ||
os.Exit(1) | ||
} | ||
} | ||
fmt.Printf("Successfully converted %s to %s (%d blocks written).\n", srcPath, dstPath, totalBlocks) | ||
} |
2 changes: 1 addition & 1 deletionextra/build.sh
This file contains hidden or 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
12 changes: 10 additions & 2 deletionsplatform.txt
This file contains hidden or 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
10 changes: 10 additions & 0 deletionsvariants/rpi_pico_rp2040/rpi_pico_rp2040.conf
This file contains hidden or 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,10 @@ | ||
CONFIG_USB_DEVICE_STACK=y | ||
CONFIG_USB_DEVICE_PRODUCT="Raspberry Pi Pico" | ||
CONFIG_USB_DEVICE_MANUFACTURER="Raspberry Pi" | ||
CONFIG_USB_DEVICE_VID=0x2E8A | ||
CONFIG_USB_DEVICE_PID=0x00C0 | ||
CONFIG_SERIAL=y | ||
CONFIG_CONSOLE=y | ||
CONFIG_UART_CONSOLE=y | ||
CONFIG_UART_LINE_CTRL=y |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.