This commit is contained in:
Edward Emelianov
2023-01-11 21:19:18 +03:00
parent a5e420ac51
commit e98aa11f72
29 changed files with 54 additions and 46 deletions

View File

@@ -64,11 +64,11 @@ CFLAGS += -O2 -MD -D__thumb2__=1
CFLAGS += -Wall -Werror -Wextra -Wshadow -Wimplicit-function-declaration
CFLAGS += -Wredundant-decls $(INCLUDE)
# -Wmissing-prototypes -Wstrict-prototypes
CFLAGS += -fno-common -ffunction-sections -fdata-sections
CFLAGS += -fno-common -ffunction-sections -fdata-sections -flto
###############################################################################
# Linker flags
LDFLAGS += --static -nostartfiles --specs=nano.specs
LDFLAGS += --static -nostartfiles --specs=nano.specs -flto
LDFLAGS += -L$(LIB_DIR)
LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -Wl,-Map=$(OBJDIR)/$(BINARY).map

View File

@@ -17,7 +17,8 @@
*/
#include <stm32g0.h>
#include "strfunc.h" // mymemcpy
#include <string.h>
#include "strfunc.h" // hexdump
#include "usart.h"
#include "i2c.h"
@@ -166,7 +167,7 @@ uint8_t write_i2c(uint8_t addr, uint8_t *data, uint8_t nbytes){
uint8_t write_i2c_dma(uint8_t addr, uint8_t *data, uint8_t nbytes){
if(!data || nbytes < 1) return 0;
mymemcpy((char*)I2Cbuf, (char*)data, nbytes);
memcpy((char*)I2Cbuf, (char*)data, nbytes);
if(isI2Cbusy()) return 0;
i2cDMAsetup(1, nbytes);
goterr = 0;

Binary file not shown.

View File

@@ -17,6 +17,7 @@
*/
#include <stm32g0.h>
#include <string.h>
#include "i2c.h"
#include "strfunc.h"
#include "usart.h"
@@ -24,6 +25,7 @@
#define LOCBUFFSZ (32)
// local buffer for I2C data to send
static uint8_t locBuffer[LOCBUFFSZ];
extern volatile uint32_t Tms;
const char *helpstring =
"i0..2 - setup I2C with lowest..highest speed (7.7, 10 and 100kHz)\n"
@@ -36,6 +38,7 @@ const char *helpstring =
"In n - just read n bytes\n"
"IN n - the same but with DMA\n"
"Is - scan I2C bus\n"
"T - print current Tms\n"
"U - send long buffer over USART\n"
;
@@ -167,6 +170,11 @@ char *parse_cmd(char *buf){
// "short" commands
if(buf[1]) return buf; // echo wrong data
switch(*buf){
case 'T':
usart3_sendstr("T=");
usart3_sendstr(u2str(Tms));
usart3_send("\n", 1);
break;
case 'U':
U3sendlong(longbuff);
break;

View File

@@ -247,7 +247,9 @@ char *getnum(const char *txt, uint32_t *N){
return nxt;
}
/*
void mymemcpy(char *dest, const char *src, int len){
if(len < 1) return;
while(len--) *dest++ = *src++;
}
*/

View File

@@ -19,7 +19,6 @@
#include <stm32g0.h>
#include <string.h>
#include "strfunc.h" // mymemcpy
#include "usart.h"
// RX/TX DMA->CCR without EN flag
@@ -84,7 +83,7 @@ int usart3_send(const char *str, int len){
int rest = UARTBUFSZ - txlen[tbufno];
if(rest == 0 && !u3txrdy) return 0; // buffer is full while transmission in process
if(len < rest) rest = len;
mymemcpy((char*)(tbuf[tbufno] + txlen[tbufno]), str, rest);
memcpy((char*)(tbuf[tbufno] + txlen[tbufno]), str, rest);
txlen[tbufno] += rest;
if(!u3txrdy) return rest;
if(txlen[tbufno] == UARTBUFSZ) usart3_sendbuf();
@@ -92,7 +91,7 @@ int usart3_send(const char *str, int len){
len -= rest;
// now fill another - empty - buffer
if(len > UARTBUFSZ) len = UARTBUFSZ;
mymemcpy((char*)tbuf[tbufno], str + rest, len);
memcpy((char*)tbuf[tbufno], str + rest, len);
txlen[tbufno] = len;
return rest + len;
}