Skip to content

Commit 3e081af

Browse files
authored
board: Added flash and twister support (zephyrproject-rtos#28)
Added support of west flash for dspic33a_curiosity board. Added support of twister for dspic33a_curiosity board. Signed-off-by: Adhil Xavier <[email protected]>
1 parent 70e6eed commit 3e081af

File tree

7 files changed

+164
-2
lines changed

7 files changed

+164
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Board-specific CMake configuration for DSPIC33A curiosity board
2+
# SPDX-License-Identifier: Apache-2.0
3+
set(XCDSC_ZEPHYR_HOME ${XCDSC_TOOLCHAIN_PATH}/bin)
4+
set(XCDSC_GNU_PREFIX xc-dsc-)
5+
6+
set(BOARD_FLASH_RUNNER ipecmd)
7+
set(BOARD_DEBUG_RUNNER mdb)
8+
9+
if(CONFIG_BOARD_DSPIC33A_CURIOSITY_P33AK128MC106)
10+
message(STATUS "device selected")
11+
board_runner_args(ipecmd "--device=33AK128MC106" "--flash-tool=PKOB4")
12+
endif()
13+
14+
board_finalize_runner_args(ipecmd)
15+
16+
set_property(GLOBAL PROPERTY BOARD_SUPPORTS_DEBUGGER TRUE)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
identifier: dspic33a_curiosity/p33ak128mc106
2+
name: EV74H48A EVB DSPIC33AK128MC106
3+
type: mcu
4+
arch: dspic
5+
toolchain:
6+
- xcdsc
7+
ram: 16
8+
flash: 128
9+
supported:
10+
- uart
11+
- timer
12+
testing:
13+
default: true
14+
vendor: microchip

cmake/compiler/xcdsc/generic.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ set(CMAKE_SYSTEM_NAME Generic)
22
set(CMAKE_SYSTEM_PROCESSOR ${ARCH})
33
# Find and validate the xc-dsc-gcc compiler binary
44
find_program(CMAKE_C_COMPILER xc-dsc-gcc PATHS ${XCDSC_TOOLCHAIN_PATH}/bin/ NO_DEFAULT_PATH REQUIRED )
5-
add_definitions(-D__XC_DSC__)
6-
add_definitions(-DQUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION)
5+
set(CMAKE_C_FLAGS -D__XC_DSC__)
6+
set(CMAKE_C_FLAGS -DQUICK_FIX_XCDSC_LINKER_EMPTY_OUTPUT_SECTION)
77
# Get compiler version
88
execute_process(
99
COMMAND ${CMAKE_C_COMPILER} --version

scripts/schemas/twister/platform-schema.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ schema;platform-schema:
6060
"arc",
6161
"arm",
6262
"arm64",
63+
"dspic",
6364
"mips",
6465
"nios2",
6566
"posix",

scripts/west_commands/runners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def _import_runner_module(runner_name):
3939
'hifive1',
4040
'intel_adsp',
4141
'intel_cyclonev',
42+
'ipecmd',
4243
'jlink',
4344
'linkserver',
4445
'mdb',
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Copyright (c) 2025, Microchip Technology Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
'''Runner for flashing PIC devices with ipecmd.'''
6+
7+
import os
8+
import platform
9+
import sys
10+
from pathlib import Path
11+
12+
from runners.core import RunnerCaps, ZephyrBinaryRunner
13+
14+
COMMON_LOCATIONS = ["/opt", "/usr/local", "/home", "C:\\Program Files"]
15+
16+
17+
class IpecmdBinaryRunner(ZephyrBinaryRunner):
18+
'''Runner front-end for Microchip's dspic33a_curiosity.'''
19+
20+
def __init__(self, cfg, device, flash_tool):
21+
super().__init__(cfg)
22+
self.elf = cfg.elf_file
23+
self.ipecmd_cmd = None
24+
self.mplabx_base = None
25+
self.java_bin = None
26+
self.ipecmd_jar = None
27+
if platform.system() == 'Linux' or platform.system() == 'Windows':
28+
self.mplabx_base = self.find_mplabx_base()
29+
if not self.mplabx_base:
30+
print("Error: Could not locate mplabx base directory")
31+
sys.exit(1)
32+
33+
version_path = self.find_latest_version_dir(self.mplabx_base)
34+
if not version_path:
35+
print("Error: No MPLAB X version directories found")
36+
sys.exit(1)
37+
38+
self.java_bin = self.find_java_bin(version_path)
39+
if not self.java_bin or not os.access(self.java_bin, os.X_OK):
40+
print("Error: Java executable not found or not executable")
41+
sys.exit(1)
42+
43+
self.ipecmd_jar = self.find_ipecmd_jar(version_path)
44+
if not self.ipecmd_jar:
45+
print(f"Error: ipecmd.jar not found in {version_path}/mplab_platform/mplab_ipe/")
46+
sys.exit(1)
47+
else:
48+
print(f'ipecmd: {self.ipecmd_jar}')
49+
self.app_bin = cfg.bin_file
50+
print(f'bin file: {cfg.bin_file}')
51+
self.hex_file = cfg.hex_file
52+
print(f'hex file: {cfg.hex_file}')
53+
self.device = device
54+
self.flash_tool = flash_tool
55+
56+
@classmethod
57+
def name(cls):
58+
return 'ipecmd'
59+
60+
@classmethod
61+
def capabilities(cls):
62+
return RunnerCaps(commands={'flash'}, erase=True, reset=True)
63+
64+
@classmethod
65+
def do_add_parser(cls, parser):
66+
# Required
67+
parser.add_argument('--device', required=True, help='soc')
68+
parser.add_argument('--flash-tool', required=True, help='hardware tool to program')
69+
70+
parser.set_defaults(reset=True)
71+
72+
@classmethod
73+
def do_create(cls, cfg, args):
74+
return IpecmdBinaryRunner(cfg, args.device, args.flash_tool)
75+
76+
def do_run(self, command, **kwargs):
77+
print("***************Flashing*************")
78+
self.ensure_output('hex')
79+
80+
self.logger.info(f'Flashing file: {self.hex_file}')
81+
if self.hex_file is not None:
82+
self.logger.info(f'flash tool: {self.flash_tool}, Device: {self.device}')
83+
self.logger.info(f'flash cmd: {self.ipecmd_jar}')
84+
cmd = [
85+
str(self.java_bin),
86+
'-jar',
87+
str(self.ipecmd_jar),
88+
'-TP' + self.flash_tool,
89+
'-P' + self.device,
90+
'-M',
91+
'-F' + self.hex_file,
92+
'-OL',
93+
]
94+
self.require(cmd[0])
95+
self.check_call(cmd)
96+
else:
97+
print("E: No HEX file found")
98+
99+
def find_mplabx_base(self):
100+
for base in COMMON_LOCATIONS:
101+
for root, dirs, _ in os.walk(base):
102+
for d in dirs:
103+
if d.startswith("mplabx") or d.startswith("MPLABX"):
104+
return Path(root) / d
105+
return None
106+
107+
def find_latest_version_dir(self, mplabx_base):
108+
versions = sorted([p for p in mplabx_base.glob("v*/") if p.is_dir()])
109+
return versions[-1] if versions else None
110+
111+
def find_java_bin(self, version_path):
112+
if platform.system() == 'Linux':
113+
java_dirs = list(version_path.glob("sys/java/*/bin/java"))
114+
elif platform.system() == 'Windows':
115+
java_dirs = list(version_path.glob("sys/java/*/bin/java.exe"))
116+
else:
117+
self.logger.error("Platform not supported")
118+
sys.exit(1)
119+
return java_dirs[0] if java_dirs else None
120+
121+
def find_ipecmd_jar(self, version_path):
122+
ipe_dir = version_path / "mplab_platform/mplab_ipe"
123+
for root, _, files in os.walk(ipe_dir):
124+
if "ipecmd.jar" in files:
125+
return Path(root) / "ipecmd.jar"
126+
return None

soc/microchip/dspic33/Kconfig.soc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
config SOC_FAMILY_MICROCHIP_DSPIC33
55
bool
66

7+
config BUILD_OUTPUT_HEX
8+
bool
9+
default y
10+
711
config SOC_FAMILY
812
default "microchip_dspic33" if SOC_FAMILY_MICROCHIP_DSPIC33
913

0 commit comments

Comments
 (0)