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.
- Need a GitHub Account to sign in to the Github Copilot extension.
- 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.
Make sure GitHub Copilot is signed in.
- If it isn’t: Command Palette (Ctrl+Shift+P) → “GitHub Copilot: Sign in”.
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).
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:
- CMSIS-solution 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-CMSIS 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-CMSIS Projects
For non-CMSIS 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.
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
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.