Skip to content

embed: device package #16

Open
luoliwoshang wants to merge 39 commits into
goplus:mainfrom
luoliwoshang:mv/task3
Open

embed: device package #16
luoliwoshang wants to merge 39 commits into
goplus:mainfrom
luoliwoshang:mv/task3

Conversation

@luoliwoshang
Copy link
Copy Markdown
Member

@luoliwoshang luoliwoshang commented Sep 12, 2025

Overview

This PR completes the migration of TinyGo v0.39.0 src/device package to goplus/lib/emb, providing embedded development support for the LLGO compiler ecosystem.

Major Changes

1. Device Package Migration

  • Migration Source: TinyGo v0.39.0 src/device package
  • Migration Scope: Migrated 17 architecture directories from TinyGo to emb/device/
  • File Count: ~1000+ device definition files covering major embedded architectures
  • Supported Architectures: ARM, ARM64, AVR, ESP, NRF, NXP, RP, SAM, STM32, Renesas, SiFive, Kendryte, RISC-V, GBA, TKey

Import Path Standardization

// Before migration
import "runtime/volatile"
import "device/stm32"

// After migration  
import "github.com/goplus/lib/emb/runtime/volatile"
import "github.com/goplus/lib/emb/device/stm32"
  • Impact Scope: 573 files updated with new import paths
  • Compatibility: Full integration with existing emb/runtime/volatile package

Compiler Intrinsic Adaptations

Inline Assembly Functions

Updated 5 files to be LLGO-compatible using //llgo:link directives:

// TinyGo (compiler built-in)
func Asm(asm string)

// LLGO adaptation
//llgo:link Asm llgo.asm
func Asm(asm string) {}
  • emb/device/asm.go - Generic inline assembly
  • emb/device/arm/arm.go - ARM architecture
  • emb/device/arm64/arm64.go - ARM64 architecture
  • emb/device/riscv/riscv.go - RISC-V architecture
  • emb/device/avr/avr.go - AVR architecture

Runtime Interrupt Handler Placeholders

Added placeholder implementations for runtime/interrupt.callHandlers in 567 device files to resolve compilation errors:

// Problematic (missing runtime, causes compilation errors)
//go:linkname callHandlers runtime/interrupt.callHandlers
func callHandlers(num int)

// Placeholder implementation (resolves compilation errors, but functionality not implemented)
// NOTE(zzy): runtime/interrupt.callHandlers is not yet implemented in LLGO
// Original linkname: //go:linkname callHandlers runtime/interrupt.callHandlers
func callHandlers(num int) {
    // TODO: implement interrupt handler dispatch mechanism
    // TinyGo implementation reference: runtime/interrupt package
}

ARM System Calls (SVCall)

Added placeholder implementations for ARM Cortex-M system calls:

func SVCall0(num uintptr) uintptr {
    // TODO(zzy): implement system call (SVCall) functionality for ARM Cortex-M
    // TinyGo compiler implementation: tinygo/compiler/inlineasm.go emitSV64Call function
    panic("TODO: SVCall0")
    return 0
}
// Similar for SVCall1, SVCall2, SVCall3, SVCall4

Related Issue: #18

RISC-V CSR Operations

Added placeholder implementations for Control Status Register operations:

func CSRReadUint(csr int) uint {
    // TODO(zzy): implement RISC-V CSR read operation
    // TinyGo compiler implementation: tinygo/compiler/inlineasm.go
    panic("TODO: CSRReadUint")
    return 0
}

Related Issue: #17

5. ARM Interrupt Placeholders

Documented existing LLGO interrupt control functions:

// DisableInterrupts/EnableInterrupts functions available in LLGO
// Implementation location: llgo/targets/device/arm/interrupts.c
// NOTE(zzy): Available for future linkage via //go:linkname
//go:linkname DisableInterrupts DisableInterrupts
func DisableInterrupts() uintptr

//go:linkname EnableInterrupts EnableInterrupts  
func EnableInterrupts(mask uintptr)

Package Validation Status

Most migrated device packages compile successfully. Three packages are excluded from validation:

  • device/riscv: picolibc compilation failure
  • device/kendryte: RISC-V64 not supported by LLGO
  • device/sifive: RISC-V32 not supported by LLGO
  • device/renesas: no corresponding LLGO target found

llgo maybe need llgo:export directive to support exporting functions with different symbol names xgo-dev/llgo#1377

//export LPSPI2_IRQHandler
func interruptLPSPI2() {
    callHandlers(IRQ_LPSPI2)
}

current will got warning

==> //export LPSPI2_IRQHandler LPSPI2_IRQHandler
llgo: linkname LPSPI2_IRQHandler not found and ignored

@niupilot
Copy link
Copy Markdown

niupilot Bot commented Sep 12, 2025

Code Review Complete

I've completed a comprehensive review of PR #16. Here are my findings and recommendations:

🔍 Overview

This PR makes significant architectural changes by:

  • Removing 263 files (~44K lines) - all board-specific configurations from emb/machine/
  • Adding CI validation infrastructure for device package compilation
  • Consolidating to ESP32-only machine implementations

⚠️ Critical Issues

1. Broken CI Validation Script

The new validation script .github/scripts/validate_device_packages.sh references emb/device/* packages that don't exist in this repository:

# Line 82: Script tries to import non-existent packages
import _ "github.com/goplus/lib/emb/device/$device_package"

Impact: The CI will fail immediately as these import paths are invalid.

2. Missing Device Packages

The script validates against targets like:

  • device/arm, device/avr, device/esp, device/nrf, etc.
  • None of these directories exist in the current repository structure

📋 Code Quality Assessment

Positive Aspects

  1. Clean Shell Script: Well-structured with proper error handling, colors, and comprehensive logging
  2. Robust Workflow: Uses pinned LLGO commit for reproducible builds
  3. Good Documentation: Clear comments and usage instructions

Issues Found

Shell Script Issues (.github/scripts/validate_device_packages.sh)

  • Line 104: Trap cleanup only affects current function scope, not script-wide
  • Lines 194 & 209: Redundant cleanup - trap cleanup EXIT already handles this
  • Line 34: Hardcoded git commit should be configurable or documented

Workflow Issues (.github/workflows/validate-device-packages.yml)

  • Lines 6-11: Path filters target non-existent emb/device/** directory
  • Line 23: Go version should be more recent (1.21 → 1.22+)
  • Missing: No timeout specifications for long-running LLGO setup

🏗️ Architecture Concerns

Major Breaking Changes

  1. Complete removal of board configurations for 100+ embedded devices
  2. No migration path or deprecation notice for existing users
  3. Unclear rationale for keeping only ESP32 implementations

Missing Documentation

  • No explanation of why all board configs were removed
  • No guidance for users migrating from removed boards
  • README.md unchanged despite massive structural changes

🛠️ Recommendations

Immediate Fixes Required

  1. Fix CI Script: Either create the missing emb/device/* packages or update import paths
  2. Update Path Filters: Change workflow triggers to match actual directory structure
  3. Document Changes: Explain architectural decisions in commit message/PR description

Suggested Improvements

  1. Make LLGO commit configurable: Use environment variable or workflow input
  2. Add proper timeouts: Prevent hanging CI jobs
  3. Improve error handling: Better cleanup and error reporting
  4. Consider backward compatibility: Phased removal or migration guide

Before Merging

  • Verify CI actually passes with current codebase
  • Document the architectural change rationale
  • Consider impact on existing users
  • Update README.md to reflect new structure

🎯 Summary

While the code quality of the new CI infrastructure is good, this PR cannot be merged in its current state due to the broken validation script that references non-existent packages. The architectural decision to remove all board configurations is significant and needs proper documentation and justification.


👉 Want me to re-run this review? Just type /review in the comments! For more usage examples, visit CodeAgent GitHub Repository.

@luoliwoshang luoliwoshang changed the title Mv/task3 task3 lib Sep 12, 2025
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a 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 refactors the project's device and machine configurations. It introduces an automated validation process for device package compilation across various LLGO targets, enhancing testing efficiency. Concurrently, a large number of older or redundant board-specific configuration files have been removed, streamlining the codebase and improving maintainability.

Highlights

  • New Device Package Validation Script: A new shell script, validate_device_packages.sh, has been added to the .github/scripts directory. This script automates the compilation validation of various device packages against different LLGO targets, ensuring compatibility and correctness.
  • Extensive Board File Removal: Numerous board-specific machine configuration files (e.g., board_arduino.go, board_esp32.go, board_pico.go) have been removed from the emb/machine directory. This cleanup likely indicates a refactoring or consolidation of board definitions, or removal of deprecated/unused configurations.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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

  1. 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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a 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 validation script for device packages and removes a significant number of board support package files, likely as part of a larger refactoring. My review focuses on the newly added script, .github/scripts/validate_device_packages.sh. I've identified a few areas for improvement to enhance its robustness and debuggability. Specifically, I'm suggesting fixes for a bug in the cleanup logic, a way to display compiler errors on build failure, and the removal of unused code.

Comment thread .github/scripts/validate_device_packages.sh Outdated
Comment thread .github/scripts/validate_device_packages.sh Outdated
Comment thread .github/scripts/validate_device_packages.sh Outdated
@luoliwoshang luoliwoshang changed the title task3 lib task3 lib(device) Sep 15, 2025
@luoliwoshang luoliwoshang changed the title task3 lib(device) device package Migration to LLGo Sep 15, 2025
@luoliwoshang luoliwoshang changed the title device package Migration to LLGo embed: device package Sep 15, 2025
@luoliwoshang luoliwoshang force-pushed the mv/task3 branch 5 times, most recently from b31bc4f to 0afa242 Compare September 25, 2025 11:22
@luoliwoshang
Copy link
Copy Markdown
Member Author

@xushiwei

fennoai Bot pushed a commit to goplus/emb that referenced this pull request Oct 28, 2025
Migrate TinyGo v0.39.0 device package from goplus/lib/emb to goplus/emb repository root.

This migration includes:
- 17 architecture directories (ARM, ARM64, AVR, ESP, NRF, NXP, RP, SAM, STM32, etc.)
- ~1000+ device definition files
- Updated import paths from github.com/goplus/lib/emb to github.com/goplus/emb
- LLGO-compatible adaptations (//llgo:link directives for Asm functions)
- Placeholder implementations for runtime/interrupt.callHandlers
- Support for embedded architectures: ARM Cortex-M, RISC-V, AVR, ESP32, Nordic, etc.

Based on goplus/lib#16

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
luoliwoshang added a commit to luoliwoshang/goplus-emb that referenced this pull request Nov 21, 2025
Migrate device generation tools and validation infrastructure from
goplus/lib PR goplus#16 (goplus/lib#16) for
TinyGo v0.39.0 adaptation.

Changes:
- Add setup-llgo GitHub Action for LLGO installation
- Add device-gen.sh script for device package generation verification
- Add validate_embed_packages.sh for device/machine validation
- Add validate-embed-packages workflow for CI validation
- Add gen-device-avr and gen-device-svd code generation tools
- Update all import paths from github.com/goplus/lib/emb to github.com/goplus/emb

These tools enable automated device package generation and validation
for embedded targets using LLGO compiler.

Source: goplus/lib PR goplus#16 (mv/task3 branch)
Commit: ebe1263c33e1a05b18df7b1b3de2132a4a4e115d

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant