-
Notifications
You must be signed in to change notification settings - Fork 6
embed:machine pkg
#19
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
base: main
Are you sure you want to change the base?
Conversation
emb/device/emb*:remove .ld .s .c
PR Review: Embedded Device Support ImplementationReviewing PR #19 - Adding embedded device support for ARM/AVR microcontrollers Tasks:
Executive SummaryThis PR adds extensive embedded device support (~19,972 lines) for ARM, AVR, and other microcontroller families. The implementation includes device-specific register definitions, interrupt handlers, and validation infrastructure. ✅ Strengths1. Comprehensive Device Coverage
2. Robust Validation Infrastructure
3. Code Quality
|
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.
Summary of Changes
Hello @luoliwoshang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly expands the project's hardware abstraction capabilities by introducing a structured emb/device package. It provides foundational support for various ARM and AVR microcontrollers, enabling more robust bare-metal programming with LLGO. A new validation script has also been added to streamline testing of these new device integrations.
Highlights
- New Device Package Structure: Introduced a new comprehensive structure under
emb/deviceto house hardware abstraction layers for various microcontroller architectures and specific devices. - ARM and ARM64 Support: Added initial hardware register definitions and core functionalities for ARM Cortex-M (including System Control Block, SysTick, and Semihosting) and ARM64 architectures.
- Extensive AVR Microcontroller Definitions: Included detailed peripheral and interrupt definitions for a wide range of AVR microcontrollers, such as AT90CAN, AT90PWM, and AT90USB series.
- Automated Device Package Validation: Implemented a new shell script (
validate_device_packages.sh) to automatically test the compilation of these device-specific packages against different LLGO targets, ensuring compatibility and correctness.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a new embed:machine package, providing low-level hardware access for various microcontrollers, including ARM, ARM64, and a wide range of AVR devices. A validation script is also added to test the compilation of these device packages. The overall structure is sound, but I've identified a couple of issues in the validation script that should be addressed to improve its robustness and efficiency. The Go files, being mostly definitions and stubs, appear to be correctly structured for their purpose.
03ca82f to
5e4d14b
Compare
75d4b7a to
d2828f2
Compare
0fa18d8 to
bd3f7ee
Compare
Overview
This PR migrates TinyGo's machine package to the GoPlus/LLGo environment, providing complete embedded hardware abstraction layer support for LLGo.
Current Status: Initial migration phase. The primary goal is to enable
llgo buildto execute correctly and pass compilation validation. Many functions that require compiler support currently use placeholder implementations (panic), to be gradually implemented as LLGo compiler features are enhanced.Major Changes
1. Code Synchronization
1.1 Sync TinyGo Machine Code
tinygo/src/machinelib/emb/machine1.2 Sync TinyGo Runtime Interrupt Code
tinygo/src/runtime/interruptlib/emb/runtime/interrupt1.3 Sync Internal Packages
Need to migrate the following internal packages:
"internal/binary"- fromtinygo/src/internaltolib/emb/internal"internal/bytealg"- fromtinygo/src/internaltolib/emb/internal"internal/itoa"- from Go v1.24.0 standard library tolib/emb/internal2. LLGo Environment Adaptation
2.1 External Symbol Mapping
2.1.1 Machine Package External Symbol Mapping
Convert TinyGo's
//exportdirectives to//go:linknamemappings:Mapping Rule:
__tinygo_*→__llgo_*Functions in
emb/machine/machine_generic.gothat apply this mapping rule include:gpioConfiguregpioSetgpioGetpwmConfigurepwmChannelConfigurepwmChannelSetspiConfigurespiTransferspiTXadcReaduartConfigureuartReaduartWriteTODO: Subsequently need to implement concrete mappings for these external symbols in LLGo runtime to provide real hardware abstraction layer functionality.
2.1.2 Interrupt Package External Symbol Mapping
The
checkpointJump()function inemb/runtime/interrupt/checkpoint.go://export tinygo_checkpointJumpto declare external function//go:linkname checkpointJump __llgo_checkpointJumpmapping to LLGo external symbol2.2 Compiler Directive Placeholders
2.2.1 Interrupt Creation Mechanism
Interrupt creation functions in
emb/runtime/interrupt/interrupt.gofile require compiler support:New()Interrupt Creation Function:func New(id int, handler func(Interrupt)) InterruptNeeds LLGo compiler to implement interrupt handling mechanism
Used for creating and registering interrupt handlers
TODO: Need to implement interrupt creation and registration mechanism in LLGo compiler.
2.2.2 Interrupt Checkpoint Mechanism
Checkpoint-related functions in
emb/runtime/interrupt/checkpoint.gofile require compiler support:Save()Compiler Intrinsic Function:func (c *Checkpoint) Save() boolThis is a compiler intrinsic function that needs to be implemented in LLGo compiler
Functions similar to setjmp, saves execution state and supports dual return value mechanism
TODO: Need to implement compiler intrinsic function support in LLGo compiler.
2.3 Import Path Adaptation
Adapt all related package import paths to conform with GoPlus module structure:
Device Package Path Adaptation:
"device/stm32"→"github.com/goplus/lib/emb/device/stm32""device/*"→"github.com/goplus/lib/emb/device/*"Machine Package Path Adaptation:
"machine"→"github.com/goplus/lib/emb/machine"Runtime Package Path Adaptation:
"runtime/interrupt"→"github.com/goplus/lib/emb/runtime/interrupt""runtime/volatile"→"github.com/goplus/lib/emb/runtime/volatile"2.4 instead cgo
0a0c7c2
2.5 some runtime-function
emb/machine/machine_avr.go