Nuvoton NuCodeGen
Description
Nuvoton NuCodeGen is an AI-powered autonomous coding extension that generates code based on the library files of chip series and utilizes tools to edit files, build projects, retrieve functions or macros from the library files, and fix code errors.
Outline
Features
- A chat extension for VSCode building on GitHub Copilot Chat.
- Use a prompt to generate snippet code based on Nuvoton STDdriver API.
- Use a prompt to query all kinds of information related to the NuMicro BSP standard driver.
- Add a custom agent to Copilot Chat
- Allows customization of how user requests are handled.
- Add custom commands and tools
- Support various peripherals
- Helps with building and correcting bugs.
Requirements
- Visual Studio Code: Version 1.127 or higher is recommended.
- Install VS Code Extension: GitHub Copilot.
- A GitHub Copilot account, or Bring Your Own Key (BYOK).
- Ensure that your corporate or personal firewall does not block VS Code's network access during the installation of extensions.
Commands
- Custom agent
- Select
NuCodeGen as the agent in the Copilot Chat interface.
NuCodeGen only appears in the agent list when specific conditions are met (see step 5 in Getting Started).
- Slash commands
/{peripheral_name}: handle issues related to the specified peripheral. For example,
/pdma: generate code for PDMA functionality
/clk: generate code for peripherals' clocks
/spi: what are limits for SPI_Open function?
/clk: how many clock sources does SPI0 have?
/{peripheral_name}-settings:
- List the relevant settings for the specified peripheral
- Example prompt format for settings
/build-project: build your project and try to fix any build errors
/debug-project: load your code and run the debugger
- VSCode commands
NuCodeGen:Add User-Defined Sub-Skill
- Add a user-defined sub-skill defining rules and constraints for a specific peripheral in specific application scenarios to improve related code generation.
- Added sub-skills will be stored in the
~/.copilot/skills/nucodegen/ directory.
NuCodeGen:Delete User-Defined Sub-Skill
- Remove the user-defined sub-skill for a specific peripheral.
NuCodeGen:Open Sub-Skill
- Open the sub-skill file for a specific peripheral to edit, including user-defined and default sub-skills.
Getting Started
Launch the VS Code application.
Install the VS Code extension Nuvoton NuMicro Cortex-M Pack.
Set up Language Model Access (choose one):
- Option A (GitHub Copilot): Make sure GitHub Copilot is signed in.
- Command Palette (Ctrl+Shift+P) → “GitHub Copilot: Sign in”.
- Option B (Bring Your Own Key - BYOK): Use your own language model API key (e.g. Claude, GPT, Gemini) or local models without signing in to a GitHub account.
Click the Chat button to open the Chat Panel.
Access `Chat Input Box` in `Chat Panel`
- Recommended Language Model: Any coding-proficient model with strong reasoning abilities (such as the latest Claude, Gemini, or GPT series).
If using a GitHub Copilot account, please check the GitHub Copilot plan for details on the free and subscription models.
NOTE: The use of less capable language models can significantly compromise the quality of the code generation.
select NuCodeGen as the agent in the Copilot Chat interface, which can appear and be used in workspaces that meet one of the following conditions:
- csolution project (e.g. a BSP project): the workspace contains
*.cproject.yml and *.csolution.yml files.
- Follow the "Getting Started" section in the "Overview" of the Nuvoton NuMicro Cortex-M Pack.
- Make sure you have downloaded the required NuMicro BSP in this step, and opened its
VSCode directory in Visual Studio Code.
- Non-csolution project: the workspace's
.vscode/settings.json contains the required NuCodeGen settings.
Generate your code:
Method 1: Repeatly get configurable settings and example prompts, then generate code based on user-adjusted settings.
NOTE: This method guarantees high accuracy because you control all the parameters, but it requires more steps and manual tuning.
Use /{peripheral_name}-settings to get configurable settings and an example prompt.
Based on the example prompt, use /{peripheral_name} to generate your code.
- Each setting can be adjusted based on your needs.
- Without clear configuration settings, the likelihood of generating incorrect configurations is higher.
Method 2: Directly generate code by describing your needs in natural language.
NOTE: This method feels more natural because you just state the goal, but it can miss key details and lead to inaccurate code generation.
Click Always Allow to enable automatic execution of command line operations.
Manual Environment Setup for Non-csolution Projects
For non-csolution projects, you need to manually set up the environment by specifying the DFP path, device, Library path, and optionally the build and flash commands in the extension settings.
Method 1: Using Command Palette
- Open Command Palette (Ctrl+Shift+P) → Enter
NuCodeGen: Configure Environment (DFP / Device / Library Path).
- Set the following fields:
- Required (all three must be set; if any required field is empty,
NuCodeGen cannot be enabled):
DFP Path: Path to the Device Family Pack (e.g. C:\Users\<USERNAME>\AppData\Local\Arm\Packs\Nuvoton\NuMicroM55_DFP\3.1.3).
Device: Target device name (e.g. M55M1H2LJAE).
Library Path: Path to the Library folder of the Board Support Package. For example,
C:\Nuvoton\M55M1BSP\Library
C:\Users\<USERNAME>\AppData\Local\Arm\Packs\Nuvoton\NuMicroM55_DFP\3.1.3\Library
C:\Users\<USERNAME>\AppData\Local\Arm\Packs\Nuvoton\NuMicroM33_DFP\1.0.5\Library\Device\Nuvoton\m3331
C:\Users\<USERNAME>\AppData\Local\Arm\Packs\Nuvoton\NuMicroM0_DFP\1.0.3\Device\M030G
NOTE: This folder must directly contain a StdDriver subfolder (e.g. <Library Path>\StdDriver).
- Optional:
Build Command: Command used to build the project.
Flash Command: Command used to flash the project.
- Right-click in the editor → Focus on
NuCodeGen → Select Configure Environment (DFP / Device / Library Path).
- Set the following fields:
- Required (all three must be set; if any required field is empty,
NuCodeGen cannot be enabled):
DFP Path: Path to the Device Family Pack (e.g. C:/Users/<USERNAME>/AppData/Local/Arm/Packs/Nuvoton/NuMicroM55_DFP/3.1.3).
Device: Target device name (e.g. M55M1H2LJAE).
Library Path: Path to the Library folder of the Board Support Package (e.g. C:/Nuvoton/M55M1BSP/Library).
NOTE: This folder must directly contain a StdDriver subfolder (e.g. C:/Nuvoton/M55M1BSP/Library/StdDriver).
- Optional:
Build Command: Command used to build the project.
Flash Command: Command used to flash the project.
These settings are saved in .vscode/settings.json.
After all required fields are configured, NuCodeGen will appear in the Agent menu. If any required field is empty, NuCodeGen cannot be enabled.
Use your own language model key
In addition to using models provided through a GitHub Copilot subscription, VS Code supports Bring Your Own Key (BYOK).
NOTE: BYOK models work without signing into a GitHub account and without a GitHub Copilot plan. You can add and use models entirely with your own API keys (e.g. Anthropic Claude, OpenAI, Google Gemini) or local models (e.g. Ollama).
How to set up BYOK
- Open Command Palette (Ctrl+Shift+P) → Enter
Chat: Manage Language Models (or select the gear icon in the Chat model picker).
- Select Add Models and choose your provider.
- Enter the required details (e.g. API key, endpoint).
- Select your configured model directly from the Chat model picker.
For more details, please refer to Use your own language model key in VS Code.
Custom Sub-Skills
You can add your own sub-skill for a specific peripheral to improve code generation related to that peripheral to meet your specific application needs.
Execute the NuCodeGen:Add User-Defined Sub-Skill.
- Method 1: Open Command Palette (Ctrl+Shift+P) → Enter
NuCodeGen:Add User-Defined Sub-Skill
- Method 2: Right-click in editor → Focus on
NuCodeGen → Select Add User-Defined Sub-Skill
Select the peripheral for which you want to add a sub-skill.
Select currently supported IPs will display a list of all supported peripherals of current chip.
Input the sub-skill's file name and press Enter.
Input the sub-skill's description and press Enter.
The sub-skill file will be created in the ~/.copilot/skills/nucodegen/<peripheral_name>/<sub_skill_name> directory.
The SKILL.md file in ~/.copilot/skills/nucodegen/<peripheral_name>/ is the main file for this peripheral. It contains the file paths and descriptions of all sub-skills.
- AI will first read this SKILL.md file to understand the sub-skills available for the peripheral, and then it will read the corresponding sub-skill file to generate code based on the user's prompt.
AI will use the sub-skill to generate code for the specified peripheral in specific application scenarios.
You can also edit the sub-skill file to modify its content.
- Method 1: Open Command Palette (Ctrl+Shift+P) → Enter
NuCodeGen:Open Sub-Skill
- Method 2: Right-click in editor → Focus on
NuCodeGen → Select Open Sub-Skill
You can delete the sub-skill file to remove it.
- Method 1: Open Command Palette (Ctrl+Shift+P) → Enter
NuCodeGen:Delete User-Defined Sub-Skill
- Method 2: Right-click in editor → Focus on
NuCodeGen → Select Delete User-Defined Sub-Skill
Reusing Skills with External AI Agents
The skills in assets/skills follow the Agent Skills specification and are written in Markdown with YAML front matter. AI agents that support this specification can use these skills to generate C code for Nuvoton microcontrollers.
Copy the individual skill folders from <extension_install_path>/assets/skills (e.g. C:\Users\<USERNAME>\.vscode\extensions\nuvoton.nuvoton-nucodegen-<version>\assets\skills on Windows) into your AI agent's global or project skills directory, as listed below.
| Agent |
Global Skills Directory |
Project Skills Directory |
| Claude Code |
~/.claude/skills/ |
<project_root>/.claude/skills/ |
| OpenAI Codex |
~/.agents/skills/ |
<project_root>/.agents/skills/ |
| Gemini CLI |
~/.gemini/skills/ |
<project_root>/.gemini/skills/ |
| Other Agent |
Refer to the agent's documentation for the global skills directory |
Refer to the agent's documentation for the project skills directory |
Example Prompts
- NuCodeGen Example Prompts provide a collection of example prompts for various peripherals. These prompts can be used as references to help you generate code for your specific use cases.
Troubleshooting
Shell Integration Unavailable
- In the gencode step, the tool-calling mode may retrieve relevant code snippets from the
OpenNuvoton GitHub repository.
- If you encounter issues with the
#githubRepo tool.
- Please ensure that your internet connection is stable and try again.
- If the problem persists, please use Copilot on the GitHub site to ask a question related to the repository.
Disclaimer
AI-Assisted Development Note
NuCodeGen is designed to accelerate your workflow and reduce boilerplate coding using AI. Like all tools powered by Large Language Models (LLMs), the generated code serves as a helpful draft and starting point. Please apply your engineering expertise to review, test, and verify the logic and security before compiling or deploying it to a production environment.