mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 03:44:30 +03:00
add timeouts
This commit is contained in:
@@ -6,4 +6,4 @@ LDSCRIPT ?= stm32f103xB.ld
|
|||||||
DEFINES := -DSTM32F10X_MD
|
DEFINES := -DSTM32F10X_MD
|
||||||
|
|
||||||
include ../makefile.f1
|
include ../makefile.f1
|
||||||
include ../../makefile.stm32
|
include ../makefile.stm32
|
||||||
|
|||||||
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 17.0.0, 2025-08-24T23:38:47. -->
|
<!-- Written by QtCreator 18.0.2, 2026-02-09T20:28:07. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
@@ -86,6 +86,7 @@
|
|||||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
<value type="int" key="RcSync">0</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
<data>
|
||||||
@@ -163,6 +164,7 @@
|
|||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
@@ -197,6 +199,7 @@
|
|||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
@@ -207,10 +210,6 @@
|
|||||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
<value type="qlonglong">1</value>
|
<value type="qlonglong">1</value>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
|
||||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
|
||||||
<value type="int">22</value>
|
|
||||||
</data>
|
|
||||||
<data>
|
<data>
|
||||||
<variable>Version</variable>
|
<variable>Version</variable>
|
||||||
<value type="int">22</value>
|
<value type="int">22</value>
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ static errcode_e help(_U_ cmd_e idx, _U_ char* par){
|
|||||||
void parse_cmd(char *cmd){
|
void parse_cmd(char *cmd){
|
||||||
errcode_e ecode = ERR_BADCMD;
|
errcode_e ecode = ERR_BADCMD;
|
||||||
// command and its parameter
|
// command and its parameter
|
||||||
CMDWRn(cmd);
|
//CMDWRn(cmd);
|
||||||
char *cmdstart = omit_spaces(cmd), *parstart = NULL;
|
char *cmdstart = omit_spaces(cmd), *parstart = NULL;
|
||||||
if(!cmdstart) goto retn;
|
if(!cmdstart) goto retn;
|
||||||
char *ptr = cmdstart;
|
char *ptr = cmdstart;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h> // memcpy
|
||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
|
|
||||||
static int datalen(ringbuffer *b){
|
static int datalen(ringbuffer *b){
|
||||||
@@ -57,11 +58,11 @@ int RB_hasbyte(ringbuffer *b, uint8_t byte){
|
|||||||
b->busy = 0;
|
b->busy = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
// poor memcpy
|
// poor memcpy
|
||||||
static void mcpy(uint8_t *targ, const uint8_t *src, int l){
|
static void mcpy(uint8_t *targ, const uint8_t *src, int l){
|
||||||
while(l--) *targ++ = *src++;
|
while(l--) *targ++ = *src++;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// increment head or tail
|
// increment head or tail
|
||||||
TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){
|
TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){
|
||||||
@@ -76,9 +77,11 @@ static int read(ringbuffer *b, uint8_t *s, int len){
|
|||||||
int _1st = b->length - b->head;
|
int _1st = b->length - b->head;
|
||||||
if(_1st > l) _1st = l;
|
if(_1st > l) _1st = l;
|
||||||
if(_1st > len) _1st = len;
|
if(_1st > len) _1st = len;
|
||||||
mcpy(s, b->data + b->head, _1st);
|
//mcpy(s, b->data + b->head, _1st);
|
||||||
|
memcpy(s, b->data + b->head, _1st);
|
||||||
if(_1st < len && l > _1st){
|
if(_1st < len && l > _1st){
|
||||||
mcpy(s+_1st, b->data, l - _1st);
|
//mcpy(s+_1st, b->data, l - _1st);
|
||||||
|
memcpy(s+_1st, b->data, l - _1st);
|
||||||
incr(b, &b->head, l);
|
incr(b, &b->head, l);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@@ -132,9 +135,11 @@ static int write(ringbuffer *b, const uint8_t *str, int l){
|
|||||||
if(l > r || !l) return 0;
|
if(l > r || !l) return 0;
|
||||||
int _1st = b->length - b->tail;
|
int _1st = b->length - b->tail;
|
||||||
if(_1st > l) _1st = l;
|
if(_1st > l) _1st = l;
|
||||||
mcpy(b->data + b->tail, str, _1st);
|
//mcpy(b->data + b->tail, str, _1st);
|
||||||
|
memcpy(b->data + b->tail, str, _1st);
|
||||||
if(_1st < l){ // add another piece from start
|
if(_1st < l){ // add another piece from start
|
||||||
mcpy(b->data, str+_1st, l-_1st);
|
//mcpy(b->data, str+_1st, l-_1st);
|
||||||
|
memcpy(b->data, str+_1st, l-_1st);
|
||||||
}
|
}
|
||||||
incr(b, &b->tail, l);
|
incr(b, &b->tail, l);
|
||||||
return l;
|
return l;
|
||||||
|
|||||||
@@ -254,7 +254,12 @@ int USB_sendall(uint8_t ifno){
|
|||||||
int USB_send(uint8_t ifno, const uint8_t *buf, int len){
|
int USB_send(uint8_t ifno, const uint8_t *buf, int len){
|
||||||
if(!buf || !CDCready[ifno] || !len) return FALSE;
|
if(!buf || !CDCready[ifno] || !len) return FALSE;
|
||||||
DBG("USB_send");
|
DBG("USB_send");
|
||||||
|
uint32_t T0 = Tms;
|
||||||
while(len){
|
while(len){
|
||||||
|
if(Tms - T0 > DISCONN_TMOUT){
|
||||||
|
break_handler(ifno);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
if(!CDCready[ifno]) return FALSE;
|
if(!CDCready[ifno]) return FALSE;
|
||||||
IWDG->KR = IWDG_REFRESH;
|
IWDG->KR = IWDG_REFRESH;
|
||||||
int a = RB_write((ringbuffer*)&rbout[ifno], buf, len);
|
int a = RB_write((ringbuffer*)&rbout[ifno], buf, len);
|
||||||
@@ -272,7 +277,12 @@ int USB_send(uint8_t ifno, const uint8_t *buf, int len){
|
|||||||
int USB_putbyte(uint8_t ifno, uint8_t byte){
|
int USB_putbyte(uint8_t ifno, uint8_t byte){
|
||||||
if(!CDCready[ifno]) return FALSE;
|
if(!CDCready[ifno]) return FALSE;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
|
uint32_t T0 = Tms;
|
||||||
while((l = RB_write((ringbuffer*)&rbout[ifno], &byte, 1)) != 1){
|
while((l = RB_write((ringbuffer*)&rbout[ifno], &byte, 1)) != 1){
|
||||||
|
if(Tms - T0 > DISCONN_TMOUT){
|
||||||
|
break_handler(ifno);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
if(!CDCready[ifno]) return FALSE;
|
if(!CDCready[ifno]) return FALSE;
|
||||||
IWDG->KR = IWDG_REFRESH;
|
IWDG->KR = IWDG_REFRESH;
|
||||||
if(l == 0){ // overfull
|
if(l == 0){ // overfull
|
||||||
@@ -299,7 +309,7 @@ int USB_sendstr(uint8_t ifno, const char *string){
|
|||||||
* @return amount of received bytes (negative, if overfull happened)
|
* @return amount of received bytes (negative, if overfull happened)
|
||||||
*/
|
*/
|
||||||
int USB_receive(uint8_t ifno, uint8_t *buf, int len){
|
int USB_receive(uint8_t ifno, uint8_t *buf, int len){
|
||||||
chkin(ifno);
|
chkin(ifno); // rxtx_handler could leave last message unwritten if buffer was busy
|
||||||
if(bufovrfl[ifno]){
|
if(bufovrfl[ifno]){
|
||||||
DBG("Buffer overflow");
|
DBG("Buffer overflow");
|
||||||
DBGs(uhex2str(ifno));
|
DBGs(uhex2str(ifno));
|
||||||
@@ -320,7 +330,7 @@ int USB_receive(uint8_t ifno, uint8_t *buf, int len){
|
|||||||
* @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared)
|
* @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared)
|
||||||
*/
|
*/
|
||||||
int USB_receivestr(uint8_t ifno, char *buf, int len){
|
int USB_receivestr(uint8_t ifno, char *buf, int len){
|
||||||
chkin(ifno);
|
chkin(ifno); // rxtx_handler could leave last message unwritten if buffer was busy
|
||||||
if(bufovrfl[ifno]){
|
if(bufovrfl[ifno]){
|
||||||
while(1 != RB_clearbuf((ringbuffer*)&rbin[ifno]));
|
while(1 != RB_clearbuf((ringbuffer*)&rbin[ifno]));
|
||||||
bufovrfl[ifno] = 0;
|
bufovrfl[ifno] = 0;
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
#define BUILD_NUMBER "126"
|
#define BUILD_NUMBER "130"
|
||||||
#define BUILD_DATE "2025-08-24"
|
#define BUILD_DATE "2026-02-09"
|
||||||
|
|||||||
Reference in New Issue
Block a user