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

Raspberry Pi 4B & 5 baremetal blink example #67

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

iCMDdev
Copy link
Contributor

@iCMDdev iCMDdev commented Oct 26, 2024

Currently just a draft for a baremetal Raspberry Pi 4B 64-bit blink example (-target aarch64-none-none-elf). I'll add the code soon - I'm making this draft public now to receive suggestions & feedback as I work on this example.

I already got Embedded Swift working on a 4B (blinking a led with Swift-MMIO), but I need to do some cleanup & better organize the code & build process. I'll upload it here after I do that (it will be in a Swift Package format).

I'm currently using llvm-objcopy as a last step to convert the resulted ELF file, with something like $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img. From what I've seen, there doesn't seem to be any viable alternative, so users will need to install llvm with brew, since llvm-objcopy is not installed by default.

@iCMDdev iCMDdev changed the title Raspberry Pi 4B baremetal support Raspberry Pi 4B baremetal blink example Oct 26, 2024
@iCMDdev
Copy link
Contributor Author

iCMDdev commented Oct 26, 2024

This doesn't need to be necesarily specific to the 4B, I might as well adapt it to the 5B. Some register values might be different, especially because the 5's ACT (green) LED (and the whole GPIO) is not directly connected to the main processor, but via the RP1 chip, perhaps making it a bit harder to blink directly.

Still, one could blink another LED connected directly to the GPIO by changing the pin(currently hardcoded in Swift MMIO registers)

Edit: I think I'm partially wrong, It appears that the green (ACT) led is connacted to the always-on GPIO pin 9 (the BCM2712's GPIO) on the RPi 5 according to this.

Edit 2: Yes, the last edit is accurate. I got this working.

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Oct 26, 2024

That was faster than expected, I think it's ready for review now!

@iCMDdev iCMDdev marked this pull request as ready for review October 26, 2024 20:31
@iCMDdev
Copy link
Contributor Author

iCMDdev commented Oct 26, 2024

boot.S and link.ld are borrowed from this bare-metal code example for Raspberry Pi 4 (CC0-licensed).

@iCMDdev iCMDdev changed the title Raspberry Pi 4B baremetal blink example Raspberry Pi 4B & 5 baremetal blink example Oct 27, 2024
@iCMDdev
Copy link
Contributor Author

iCMDdev commented Oct 27, 2024

I also got this working on a Pi 5! I managed to gather the relevant register details (adresses & necessary bit values).
Now, I'm wondering whether these should be 2 separate examples, or if I should merge them into one (and use compiler directives to specify which board is used).

@kubamracek kubamracek requested a review from phausler November 1, 2024 19:16
@rauhul
Copy link
Collaborator

rauhul commented Nov 11, 2024

I think the example makes sense to add. However Im trying to get CI setup for this repo before adding additional examples, so avoid hosting broken code!

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Nov 11, 2024

However Im trying to get CI setup for this repo before adding additional examples

Make sense, alright!

so avoid hosting broken code!

I'm not sure what you mean by that, do you mean that this example is broken somewhere? I was able to build & run it just fine, but maybe that's on my machine only. Let me know if you had any problems if you tested this.

Either way, as you suggested, we should popstone this example and come back to it once we get CI integration. That's a good idea.

@rauhul
Copy link
Collaborator

rauhul commented Nov 11, 2024

I mean the examples silently breaking due to changes in the swift compiler or other example dependencies, e.g. the SDKs where we depend on a branch.

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Nov 11, 2024

I mean the examples silently breaking due to changes in the swift compiler or other example dependencies, e.g. the SDKs where we depend on a branch.

Oh, right, yeah. Great idea.

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.

2 participants