Skip to content

Commit f472512

Browse files
committed
nrf5x: Request HFXO via OS
Mynewt (similar to Soft Device) has its own reference counting for HFXO oscillator. So far TinyUSB requested HFXO when VBUS was detected and stopped when VBUS was removed. But with Mynewt running HFXO can be stopped when other interested parties don't require HFXO anymore. This results in very difficult to track USB transmission errors. This change enables Mynewt specific HFXO management in Soft Device fashion.
1 parent 3b09b82 commit f472512

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/portable/nordic/nrf5x/dcd_nrf5x.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include "device/usbd.h"
3939
#include "device/usbd_pvt.h" // to use defer function helper
4040

41+
#if CFG_TUSB_OS == OPT_OS_MYNEWT
42+
#include "mcu/mcu.h"
43+
#endif
44+
4145
/*------------------------------------------------------------------*/
4246
/* MACRO TYPEDEF CONSTANT ENUM
4347
*------------------------------------------------------------------*/
@@ -891,6 +895,11 @@ static bool hfclk_running(void)
891895

892896
static void hfclk_enable(void)
893897
{
898+
#if CFG_TUSB_OS == OPT_OS_MYNEWT
899+
usb_clock_request();
900+
return;
901+
#else
902+
894903
// already running, nothing to do
895904
if ( hfclk_running() ) return;
896905

@@ -904,10 +913,16 @@ static void hfclk_enable(void)
904913

905914
nrf_clock_event_clear(NRF_CLOCK, NRF_CLOCK_EVENT_HFCLKSTARTED);
906915
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTART);
916+
#endif
907917
}
908918

909919
static void hfclk_disable(void)
910920
{
921+
#if CFG_TUSB_OS == OPT_OS_MYNEWT
922+
usb_clock_release();
923+
return;
924+
#else
925+
911926
#ifdef SOFTDEVICE_PRESENT
912927
if ( is_sd_enabled() )
913928
{
@@ -917,6 +932,7 @@ static void hfclk_disable(void)
917932
#endif
918933

919934
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTOP);
935+
#endif
920936
}
921937

922938
// Power & Clock Peripheral on nRF5x to manage USB

0 commit comments

Comments
 (0)