Skip to content

Commit d9990b3

Browse files
don't send stdio data without USB connected
1 parent 78c097b commit d9990b3

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

system/libstm32l4_dragonfly/stm32l4_clib.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,28 @@ int _write(int file, char *buf, int nbytes)
135135
stm32l4_usbd_cdc_enable(&stm32l4_usbd_cdc, 0, NULL, NULL, 0);
136136
}
137137

138-
if (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
138+
if (stm32l4_usbd_cdc_connected(&stm32l4_usbd_cdc))
139139
{
140+
if (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
141+
{
142+
if (armv7m_core_priority() <= (int)NVIC_GetPriority(OTG_FS_IRQn))
143+
{
144+
while (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
145+
{
146+
stm32l4_usbd_cdc_poll(&stm32l4_usbd_cdc);
147+
}
148+
}
149+
else
150+
{
151+
while (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
152+
{
153+
armv7m_core_yield();
154+
}
155+
}
156+
}
157+
158+
stm32l4_usbd_cdc_transmit(&stm32l4_usbd_cdc, (const uint8_t*)buf, nbytes);
159+
140160
if (armv7m_core_priority() <= (int)NVIC_GetPriority(OTG_FS_IRQn))
141161
{
142162
while (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
@@ -153,23 +173,6 @@ int _write(int file, char *buf, int nbytes)
153173
}
154174
}
155175

156-
stm32l4_usbd_cdc_transmit(&stm32l4_usbd_cdc, (const uint8_t*)buf, nbytes);
157-
158-
if (armv7m_core_priority() <= (int)NVIC_GetPriority(OTG_FS_IRQn))
159-
{
160-
while (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
161-
{
162-
stm32l4_usbd_cdc_poll(&stm32l4_usbd_cdc);
163-
}
164-
}
165-
else
166-
{
167-
while (!stm32l4_usbd_cdc_done(&stm32l4_usbd_cdc))
168-
{
169-
armv7m_core_yield();
170-
}
171-
}
172-
173176
return nbytes;
174177

175178
default:
152 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)