Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit 35aeffc

Browse files
alfransergiotomasello
authored andcommitted
Fixed ESP8266 Upload issue (the sleep time before the stm32 sketch upload should be set to 3 seconds and a patched version of Espressif tool is needed)
1 parent afc47f7 commit 35aeffc

File tree

4 files changed

+245
-200
lines changed

4 files changed

+245
-200
lines changed

ChangeLog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
- Fixed USB CDC issue if the chunk is greater than 64 bytes
33
- Fixed I2C Pin definition
44
- Fixed CAN-BUS pin definition
5-
- Added CAN-BUS port 2 definition
5+
- Added CAN-BUS port 2 definition
6+
- Fixed ESP8266 Upload issue (the sleep time before the stm32 sketch upload should be set to 3 seconds)
67

78
- Library:
89
- Audio:

cores/arduino/usb_serial.cpp

100755100644
Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ size_t USBSerial::write(uint8_t ch) {
106106
if(((UserTxBufPtrIn + 1) % APP_TX_DATA_SIZE) == UserTxBufPtrOut)
107107
{
108108
// Buffer full!!! Force a flush to not loose data and go on
109-
flush();
109+
CDC_flush();
110110
}
111111
UserTxBufferFS[UserTxBufPtrIn] = ch;
112112
UserTxBufPtrIn = ((UserTxBufPtrIn + 1) % APP_TX_DATA_SIZE);
@@ -117,36 +117,56 @@ size_t USBSerial::write(uint8_t ch) {
117117
}
118118

119119
int USBSerial::available(void) {
120-
return ((APP_RX_DATA_SIZE + (UserRxBufPtrIn - UserRxBufPtrOut)) % APP_RX_DATA_SIZE);
120+
int ret;
121+
122+
CDC_disable_TIM_Interrupt();
123+
ret = ((APP_RX_DATA_SIZE + (UserRxBufPtrIn - UserRxBufPtrOut)) % APP_RX_DATA_SIZE);
124+
CDC_enable_TIM_Interrupt();
125+
126+
return ret;
121127
}
122128

123129
int USBSerial::read(void) {
124-
if(UserRxBufPtrOut == UserRxBufPtrIn)
125-
{
126-
return -1;
130+
/* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */
131+
/* value that we read is correct, we need to disable TIM Interrupt. */
132+
CDC_disable_TIM_Interrupt();
133+
if(UserRxBufPtrOut == UserRxBufPtrIn)
134+
{
135+
CDC_enable_TIM_Interrupt();
136+
return -1;
127137
} else
128-
{
129-
unsigned char c = UserRxBufferFS[UserRxBufPtrOut];
138+
{
139+
unsigned char c = UserRxBufferFS[UserRxBufPtrOut];
130140
UserRxBufPtrOut = ((UserRxBufPtrOut + 1) % APP_RX_DATA_SIZE);
141+
CDC_enable_TIM_Interrupt();
131142
return c;
132-
}
143+
}
133144
}
134145

135146
int USBSerial::peek(void)
136147
{
137-
if(UserRxBufPtrOut == UserRxBufPtrIn)
138-
{
139-
return -1;
148+
/* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */
149+
/* value that we read is correct, we need to disable TIM Interrupt. */
150+
CDC_disable_TIM_Interrupt();
151+
if(UserRxBufPtrOut == UserRxBufPtrIn)
152+
{
153+
CDC_enable_TIM_Interrupt();
154+
return -1;
140155
} else
141-
{
142-
unsigned char c = UserRxBufferFS[UserRxBufPtrOut];
156+
{
157+
unsigned char c = UserRxBufferFS[UserRxBufPtrOut];
158+
CDC_enable_TIM_Interrupt();
143159
return c;
144-
}
160+
}
145161
}
146162

147163
void USBSerial::flush(void)
148164
{
165+
/* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */
166+
/* value that we read is correct, we need to disable TIM Interrupt. */
167+
CDC_disable_TIM_Interrupt();
149168
CDC_flush();
169+
CDC_enable_TIM_Interrupt();
150170

151171
#if 0
152172
/* Flush EP1 for data IN */

0 commit comments

Comments
 (0)