Skip to content
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

Use different USB PID for dual-CDC setups #13115

Merged
merged 2 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Tools/ardupilotwaf/chibios.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def run(self):
"version": "0.1",
"image_size": len(img),
"git_identity": self.generator.bld.git_head_hash(short=True),
"board_revision": 0
"board_revision": 0,
"USBID": self.env.USBID
}
if self.env.build_dates:
# we omit build_time when we don't have build_dates so that apj
Expand Down
5 changes: 4 additions & 1 deletion Tools/scripts/generate_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ def add_USB_IDs_ChibiOS(self, firmware):
'VRCore-v10': ['0x27AC/0x1910'],
'VRUBrain-v51': ['0x27AC/0x1351']
}
if platform in USBID_MAP:
if 'USBID' in apj_json:
# newer APJ files have USBID in the json data
firmware['USBID'] = apj_json['USBID']
elif platform in USBID_MAP:
firmware['USBID'] = USBID_MAP[platform]
else:
# all others use a single USB VID/PID
Expand Down
2 changes: 0 additions & 2 deletions libraries/AP_HAL_ChibiOS/hwdef/mRoControlZeroF7/hwdef-bl.dat
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
MCU STM32F7xx STM32F777xx

# USB setup
USB_VENDOR 0x0483 # ST
USB_PRODUCT 0x5740
USB_STRING_MANUFACTURER "mRo"

# crystal frequency
Expand Down
2 changes: 0 additions & 2 deletions libraries/AP_HAL_ChibiOS/hwdef/mRoControlZeroF7/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ STM32_ST_USE_TIMER 5
define HAL_STORAGE_SIZE 16384

# USB setup
USB_VENDOR 0x0483 # ST
USB_PRODUCT 0x5740
USB_STRING_MANUFACTURER "mRo"

# RC Input set for Interrupt not DMA
Expand Down
2 changes: 0 additions & 2 deletions libraries/AP_HAL_ChibiOS/hwdef/mRoX21-777/hwdef-bl.dat
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ STM32_VDD 330U
FLASH_SIZE_KB 2048

# USB setup
USB_VENDOR 0x0483 # ST
USB_PRODUCT 0x5740
USB_STRING_MANUFACTURER "mRo"
USB_STRING_PRODUCT "X2.1-777"
USB_STRING_SERIAL "%SERIAL%"
Expand Down
2 changes: 0 additions & 2 deletions libraries/AP_HAL_ChibiOS/hwdef/mRoX21-777/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ STDOUT_BAUDRATE 57600
# if creating a board for a RTF vehicle you may wish to customise these

# USB setup
USB_VENDOR 0x0483 # ST
USB_PRODUCT 0x5740
USB_STRING_MANUFACTURER "mRo"
USB_STRING_PRODUCT "mRoX21-777"
USB_STRING_SERIAL "%SERIAL%"
Expand Down
28 changes: 23 additions & 5 deletions libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
baro_list = []

mcu_type = None

dual_USB_enabled = False

def is_int(str):
'''check if a string is an integer'''
Expand Down Expand Up @@ -726,15 +726,28 @@ def copy_common_linkerscript(outdir, hwdef):
shutil.copy(os.path.join(dirpath, "../common/common.ld"),
os.path.join(outdir, "common.ld"))

def get_USB_IDs():
'''return tuple of USB VID/PID'''

global dual_USB_enabled
if dual_USB_enabled:
# use pidcodes allocated ID
default_vid = 0x1209
default_pid = 0x5740
else:
default_vid = 0x0483
default_pid = 0x5740
return (get_config('USB_VENDOR', type=int, default=default_vid), get_config('USB_PRODUCT', type=int, default=default_pid))


def write_USB_config(f):
'''write USB config defines'''
if not have_type_prefix('OTG'):
return
f.write('// USB configuration\n')
f.write('#define HAL_USB_VENDOR_ID %s\n' % get_config('USB_VENDOR', default=0x0483)) # default to ST
f.write('#define HAL_USB_PRODUCT_ID %s\n' % get_config('USB_PRODUCT', default=0x5740))
(USB_VID, USB_PID) = get_USB_IDs()
f.write('#define HAL_USB_VENDOR_ID 0x%04x\n' % int(USB_VID))
f.write('#define HAL_USB_PRODUCT_ID 0x%04x\n' % int(USB_PID))
f.write('#define HAL_USB_STRING_MANUFACTURER "%s"\n' % get_config("USB_STRING_MANUFACTURER", default="ArduPilot"))
default_product = "%BOARD%"
if args.bootloader:
Expand Down Expand Up @@ -929,6 +942,7 @@ def get_extra_bylabel(label, name, default=None):

def write_UART_config(f):
'''write UART config defines'''
global dual_USB_enabled
if get_config('UART_ORDER', required=False) is None:
return
uart_list = config['UART_ORDER']
Expand Down Expand Up @@ -996,6 +1010,7 @@ def write_UART_config(f):
'#define HAL_%s_CONFIG {(BaseSequentialStream*) &SDU2, true, false, 0, 0, false, 0, 0}\n'
% dev)
OTG2_index = uart_list.index(dev)
dual_USB_enabled = True
elif dev.startswith('OTG'):
f.write(
'#define HAL_%s_CONFIG {(BaseSequentialStream*) &SDU1, true, false, 0, 0, false, 0, 0}\n'
Expand Down Expand Up @@ -1399,6 +1414,8 @@ def setup_apj_IDs():
'''setup the APJ board IDs'''
env_vars['APJ_BOARD_ID'] = get_config('APJ_BOARD_ID')
env_vars['APJ_BOARD_TYPE'] = get_config('APJ_BOARD_TYPE', default=mcu_type)
(USB_VID, USB_PID) = get_USB_IDs()
env_vars['USBID'] = '0x%04x/0x%04x' % (USB_VID, USB_PID)

def write_peripheral_enable(f):
'''write peripheral enable lines'''
Expand Down Expand Up @@ -1449,7 +1466,6 @@ def write_hwdef_header(outfilename):
''')

write_mcu_config(f)
write_USB_config(f)
write_SPI_config(f)
write_ADC_config(f)
write_GPIO_config(f)
Expand All @@ -1458,7 +1474,6 @@ def write_hwdef_header(outfilename):
write_BARO_config(f)

write_peripheral_enable(f)
setup_apj_IDs()

dma_resolver.write_dma_header(f, periph_list, mcu_type,
dma_exclude=get_dma_exclude(periph_list),
Expand All @@ -1472,6 +1487,9 @@ def write_hwdef_header(outfilename):
else:
write_UART_config_bootloader(f)

setup_apj_IDs()
write_USB_config(f)

add_bootloader()

if len(romfs) > 0:
Expand Down