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

@ -57,8 +57,6 @@
<file file_name="../sdk_config.h" /> <file file_name="../sdk_config.h" />
<folder Name="usb"> <folder Name="usb">
<file file_name="../usb/tusb_config.h" /> <file file_name="../usb/tusb_config.h" />
<file file_name="../usb/tusb_descriptors.c" />
<file file_name="../usb/tusb_descriptors.h" />
<folder Name="uf2"> <folder Name="uf2">
<file file_name="../usb/uf2/uf2cfg.h" /> <file file_name="../usb/uf2/uf2cfg.h" />
<file file_name="../usb/uf2/uf2.h" /> <file file_name="../usb/uf2/uf2.h" />
@ -66,6 +64,8 @@
</folder> </folder>
<file file_name="../usb/msc_uf2.c" /> <file file_name="../usb/msc_uf2.c" />
<file file_name="../usb/usb.c" /> <file file_name="../usb/usb.c" />
<file file_name="../usb/usb_desc.c" />
<file file_name="../usb/usb_desc.h" />
</folder> </folder>
<folder Name="cmsis"> <folder Name="cmsis">
<folder Name="include"> <folder Name="include">
@ -210,7 +210,6 @@
<file file_name="../../lib/tinyusb/src/device/usbd.c" /> <file file_name="../../lib/tinyusb/src/device/usbd.c" />
<file file_name="../../lib/tinyusb/src/device/usbd.h" /> <file file_name="../../lib/tinyusb/src/device/usbd.h" />
<file file_name="../../lib/tinyusb/src/device/usbd_pvt.h" /> <file file_name="../../lib/tinyusb/src/device/usbd_pvt.h" />
<file file_name="../../lib/tinyusb/src/device/usbd_auto_desc.c" />
</folder> </folder>
<folder Name="osal"> <folder Name="osal">
<file file_name="../../lib/tinyusb/src/osal/osal.c" /> <file file_name="../../lib/tinyusb/src/osal/osal.c" />

View File

@ -135,7 +135,14 @@ static uint32_t get_flash_size(void)
const bootloader_settings_t * boot_setting; const bootloader_settings_t * boot_setting;
bootloader_util_settings_get(&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; 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 "nrf_usbd.h"
#include "tusb.h" #include "tusb.h"
#include "usb_desc.h"
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // 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) /* 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. */ * 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); 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); 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 // Init tusb stack
tusb_init(); tusb_init();
} }

View File

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