@@ -33,30 +33,31 @@ using namespace std::chrono_literals;
3333
3434CyH4TransportDriver::CyH4TransportDriver (PinName tx, PinName rx, PinName cts, PinName rts, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name, uint8_t host_wake_irq, uint8_t dev_wake_irq) :
3535 cts (cts), rts(rts),
36+ tx (tx), rx(rx),
3637 bt_host_wake_name (bt_host_wake_name),
3738 bt_device_wake_name (bt_device_wake_name),
3839 bt_host_wake (bt_host_wake_name, PIN_INPUT, PullNone, 0 ),
3940 bt_device_wake (bt_device_wake_name, PIN_OUTPUT, PullNone, 1 ),
4041 host_wake_irq_event (host_wake_irq),
4142 dev_wake_irq_event (dev_wake_irq)
4243{
43- cyhal_uart_init (&uart, tx, rx, NULL , NULL );
4444 enabled_powersave = true ;
4545 bt_host_wake_active = false ;
4646}
4747
4848CyH4TransportDriver::CyH4TransportDriver (PinName tx, PinName rx, PinName cts, PinName rts, int baud) :
4949 cts (cts),
5050 rts (rts),
51+ tx (tx), rx(rx),
5152 bt_host_wake_name (NC),
5253 bt_device_wake_name (NC),
5354 bt_host_wake (bt_host_wake_name),
5455 bt_device_wake (bt_device_wake_name)
5556{
56- cyhal_uart_init (&uart, tx, rx, NULL , NULL );
5757 enabled_powersave = false ;
5858 bt_host_wake_active = false ;
59- sleep_manager_lock_deep_sleep ();
59+ sleep_manager_lock_deep_sleep (); // locking deep sleep because this option
60+ // does not include a host wake pin
6061 holding_deep_sleep_lock = true ;
6162}
6263
@@ -124,12 +125,21 @@ void CyH4TransportDriver::initialize()
124125
125126 sleep_manager_lock_deep_sleep ();
126127
128+ cyhal_gpio_write (CYBSP_BT_POWER, 0 );
129+ rtos::ThisThread::sleep_for (20ms);
130+
131+ cyhal_uart_init (&uart, tx, rx, NULL , NULL );
132+
127133 const cyhal_uart_cfg_t uart_cfg = { .data_bits = 8 , .stop_bits = 1 , .parity = CYHAL_UART_PARITY_NONE, .rx_buffer = NULL , .rx_buffer_size = 0 };
128134 cyhal_uart_configure (&uart, &uart_cfg);
129135 cyhal_uart_set_flow_control (&uart, cts, rts);
136+ cyhal_uart_clear (&uart);
130137 cyhal_uart_register_callback (&uart, &on_controller_irq, &uart);
131138 cyhal_uart_enable_event (&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true );
132139
140+ cyhal_gpio_write (CYBSP_BT_POWER, 1 );
141+ rtos::ThisThread::sleep_for (10ms);
142+
133143#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
134144 if (bt_host_wake_name != NC) {
135145 // Register IRQ for Host WAKE
@@ -149,26 +159,34 @@ void CyH4TransportDriver::initialize()
149159 rtos::ThisThread::sleep_for (500ms);
150160}
151161
152- void CyH4TransportDriver::terminate ()
153- {
162+ void CyH4TransportDriver::terminate ()
163+ {
154164 cyhal_uart_event_t enable_irq_event = (cyhal_uart_event_t )(CYHAL_UART_IRQ_RX_DONE
155165 | CYHAL_UART_IRQ_TX_DONE
156166 | CYHAL_UART_IRQ_RX_NOT_EMPTY
157- );
167+ );
158168
159169 cyhal_uart_enable_event (&uart,
160- enable_irq_event,
161- CYHAL_ISR_PRIORITY_DEFAULT,
162- false
163- );
170+ enable_irq_event,
171+ CYHAL_ISR_PRIORITY_DEFAULT,
172+ false
173+ );
174+ cyhal_uart_register_callback (&uart,
175+ NULL ,
176+ NULL
177+ );
178+
179+ if (CYBSP_BT_DEVICE_WAKE != NC) cyhal_gpio_free (CYBSP_BT_DEVICE_WAKE);
164180
165- cyhal_uart_register_callback (&uart, NULL , NULL );
166- cyhal_uart_free (&uart);
167181
168- cyhal_gpio_free (CYBSP_BT_DEVICE_WAKE);
169- cyhal_gpio_free (CYBSP_BT_HOST_WAKE);
170- cyhal_gpio_write (CYBSP_BT_POWER, false );
171- cyhal_gpio_free (CYBSP_BT_POWER);
182+ if (CYBSP_BT_HOST_WAKE != NC) cyhal_gpio_write (CYBSP_BT_DEVICE_WAKE, false );
183+
184+ if (CYBSP_BT_POWER != NC)
185+ {
186+ cyhal_gpio_write (CYBSP_BT_POWER, false );
187+ }
188+
189+ cyhal_uart_free (&uart);
172190}
173191
174192uint16_t CyH4TransportDriver::write (uint8_t type, uint16_t len, uint8_t *pData)
0 commit comments