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

Merged
merged 48 commits into from
Jan 14, 2025

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.

Reverted some changes that should've been in another PR. Mixed them up by mistake.
@iCMDdev
Copy link
Contributor Author

iCMDdev commented Dec 15, 2024

Thanks for running the checks! I’m not sure how I missed installing make, I know I had it in the script… Maybe I pushed the change to the wrong branch.

Either way, I’ll fix it asap.

Edit: yes, I think that’s exactly what happened. Hopefully it’s fine now.

Copy link
Collaborator

@rauhul rauhul left a comment

Choose a reason for hiding this comment

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

almost good to merge, sorry about the delay.

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Jan 3, 2025

almost good to merge, sorry about the delay.

No worries, and happy new year! I made the changes you've requested and retested the workflow, it should work fine now.

@rauhul
Copy link
Collaborator

rauhul commented Jan 3, 2025

@iCMDdev theres a couple yml lint issues remaining, otherwise this is ready

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Jan 3, 2025

Thanks for pointing out!

Apparently I didn't notice them in my fork, though the test also failed there. Sorry about that, fixing it now.

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Jan 3, 2025

Seems fine now, can you run checks again?

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Jan 10, 2025

Thanks! 🎉
If you want me to change or add anything else, let me know.

@kubamracek
Copy link
Collaborator

@rauhul shall we merge?

@rauhul
Copy link
Collaborator

rauhul commented Jan 14, 2025

Ah yes please, sorry I thought we already merged it!

I think I got lazy making a nice commit message. The GitHub one wasn't great with all the intermediate commit messages.

Do you mind summarizing the overall change when merging?

@iCMDdev
Copy link
Contributor Author

iCMDdev commented Jan 14, 2025

The GitHub one wasn't great with all the intermediate commit messages.

Yeah, sorry, I took a bit of advantage of the squash-on-merge policy. I think I should also provide more descriptive intermediate commit messages to replace the automatically-generated "Update [file]" ones - I'll try to do this more in the future.

Do you mind summarizing the overall change when merging?

Perhaps something like this would work (feel free to modify it, feedback always appreciated!):

Add Raspberry Pi 4B & 5 baremetal examples
Provide new examples demonstrating how to run Swift Embedded on the Raspberry Pi 4B and 5 single-board computers, in a baremetal fashion, without an underlying operating system. The provided examples showcase how to blink the onboard green LED using Swift MMIO.

@rauhul rauhul merged commit 5e21399 into apple:main Jan 14, 2025
18 checks passed
@iCMDdev
Copy link
Contributor Author

iCMDdev commented Jan 14, 2025

Thanks for merging! 🎉

@iCMDdev iCMDdev deleted the RPi-4B-BCM2711 branch January 14, 2025 19:36
@iCMDdev iCMDdev restored the RPi-4B-BCM2711 branch January 14, 2025 19:37
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