add CDC mode only for use with Arduino touch 1200

fix issue with reading current.uf2 size when flashed with jlink
This commit is contained in:
hathach
2018-08-16 19:27:27 +07:00
parent 0b3f49f4a1
commit 8c66a55511
4 changed files with 24 additions and 6 deletions

View File

@ -135,7 +135,14 @@ static uint32_t get_flash_size(void)
const bootloader_settings_t * boot_setting;
bootloader_util_settings_get(&boot_setting);
// if bank0 size is not valid, happens when flashed with jlink
// use maximum application size
flash_sz = boot_setting->bank_0_size;
if ( (flash_sz == 0) || (flash_sz == 0xFFFFFFFFUL) )
{
flash_sz = FLASH_SIZE;
}
}
}

View File

@ -44,11 +44,16 @@
#include "nrf_usbd.h"
#include "tusb.h"
#include "usb_desc.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
// from usb_desc.c for dynamic descriptor
extern tusb_desc_device_t usb_desc_dev;
extern usb_desc_cfg_t usb_desc_cfg;
/* tinyusb function that handles power event (detected, ready, removed)
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
extern void tusb_hal_nrf_power_event(uint32_t event);
@ -95,6 +100,16 @@ void usb_init(bool cdc_only)
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
}
if ( cdc_only )
{
// Change PID to CDC only
usb_desc_dev.idProduct = USB_DESC_SERIAL_ONLY_PID;
// Remove MSC interface = reduce total interface + adjust config desc length
usb_desc_cfg.config.bNumInterfaces--;
usb_desc_cfg.config.wTotalLength -= sizeof(usb_desc_cfg.msc);
}
// Init tusb stack
tusb_init();
}

View File

@ -85,9 +85,6 @@ typedef struct ATTR_PACKED
} usb_desc_cfg_t;
extern tusb_desc_device_t usb_desc_dev;
extern usb_desc_cfg_t usb_desc_cfg;
#ifdef __cplusplus
}
#endif