diff --git a/G4:G431/USB_CDC/main.c b/G4:G431/USB_CDC/main.c index f5d5017..58a0070 100644 --- a/G4:G431/USB_CDC/main.c +++ b/G4:G431/USB_CDC/main.c @@ -35,7 +35,7 @@ int main(void){ gpio_setup(); usart_setup(115200); USB_setup(); - bool pressed = false; + uint8_t pressed = 0; uint32_t Tblink = 0, Tkey = 0; // blink and key pressed time while(1){ USART_flags_t f = usart_process(); @@ -56,7 +56,7 @@ int main(void){ } if(KEY_PRESSED()){ if(!pressed){ // new event - pressed = true; + pressed = 1; usart_sendstr(spressed); USB_putbyte('1'); USB_putbyte('1'); newline(); USB_sendstr(spressed); @@ -64,7 +64,7 @@ int main(void){ Tkey = Tms; }else{ // key released if(pressed && (Tms - Tkey) > TDEBOUNCE){ // wait for debounce - pressed = false; + pressed = 0; usart_sendstr(sreleased); USB_putbyte('0'); USB_putbyte('0'); newline(); USB_sendstr(sreleased); diff --git a/G4:G431/USB_CDC/ringbuffer.c b/G4:G431/USB_CDC/ringbuffer.c index 5e28ee0..9683f6c 100644 --- a/G4:G431/USB_CDC/ringbuffer.c +++ b/G4:G431/USB_CDC/ringbuffer.c @@ -31,9 +31,9 @@ int RB_datalen(ringbuffer *b){ CHK(b); if(0 == datalen(b)) return 0; // don't block for empty RO operations if(b->busy) return -1; - b->busy = true; + b->busy = 1; int l = datalen(b); - b->busy = false; + b->busy = 0; return l; } @@ -59,9 +59,9 @@ static int hasbyte(ringbuffer *b, uint8_t byte){ int RB_hasbyte(ringbuffer *b, uint8_t byte){ CHK(b); if(b->busy) return -1; - b->busy = true; + b->busy = 1; int ret = hasbyte(b, byte); - b->busy = false; + b->busy = 0; return ret; } @@ -100,9 +100,9 @@ int RB_read(ringbuffer *b, uint8_t *s, int len){ if(!s || len < 1) return -1; if(0 == datalen(b)) return 0; if(b->busy) return -1; - b->busy = true; + b->busy = 1; int r = read(b, s, len); - b->busy = false; + b->busy = 0; return r; } @@ -136,14 +136,14 @@ int RB_readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len){ if(!s || len < 1) return -1; if(0 == datalen(b)) return 0; if(b->busy) return -1; - b->busy = true; + b->busy = 1; int n = 0; if(s && len > 0){ n = readto(b, byte, s, len); }else{ incr(b, &b->head, lento(b, byte)); // just throw data out } - b->busy = false; + b->busy = 0; return n; } @@ -151,9 +151,9 @@ int RB_datalento(ringbuffer *b, uint8_t byte){ CHK(b); if(0 == datalen(b)) return 0; if(b->busy) return -1; - b->busy = true; + b->busy = 1; int n = lento(b, byte); - b->busy = false; + b->busy = 0; return n; } @@ -184,9 +184,9 @@ int RB_write(ringbuffer *b, const uint8_t *str, int l){ if(!str || l < 1) return -1; if(b->length - datalen(b) < 2) return 0; if(b->busy) return -1; - b->busy = true; + b->busy = 1; int w = write(b, str, l); - b->busy = false; + b->busy = 0; return w; } @@ -194,10 +194,10 @@ int RB_write(ringbuffer *b, const uint8_t *str, int l){ int RB_clearbuf(ringbuffer *b){ CHK(b); if(b->busy) return -1; - b->busy = true; + b->busy = 1; b->head = 0; b->tail = 0; memset(b->data, 0, b->length); - b->busy = false; + b->busy = 0; return 1; } diff --git a/G4:G431/USB_CDC/ringbuffer.h b/G4:G431/USB_CDC/ringbuffer.h index 8b7d808..5a0bf60 100644 --- a/G4:G431/USB_CDC/ringbuffer.h +++ b/G4:G431/USB_CDC/ringbuffer.h @@ -24,7 +24,7 @@ typedef struct{ const int length; // its length volatile int head; // head index volatile int tail; // tail index - volatile bool busy; // == TRUE if buffer is busy now + volatile uint8_t busy; // == TRUE if buffer is busy now } ringbuffer; int RB_read(ringbuffer *b, uint8_t *s, int len); diff --git a/G4:G431/USB_CDC/usart.c b/G4:G431/USB_CDC/usart.c index b1e7eff..a2754de 100644 --- a/G4:G431/USB_CDC/usart.c +++ b/G4:G431/USB_CDC/usart.c @@ -65,8 +65,8 @@ void dma1_channel2_isr() __attribute__ ((alias ("dmatx_isr"))); #define DMARXCCR (DMA_CCR_MINC | DMA_CCR_CIRC | DMA_CCR_TEIE) #define DMATXCCR (DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE | DMA_CCR_TEIE) -static volatile bool gotstring = true; // got '\n' in input stream -> force data reading to inbuf -static volatile bool txrdy = true; // Tx DMA not busy +static volatile uint8_t gotstring = 1; // got '\n' in input stream -> force data reading to inbuf +static volatile uint8_t txrdy = 1; // Tx DMA not busy static volatile USART_flags_t curflags; // current flags (cleared in `usart_process`) // rx/tx DMA buffers static uint8_t dmarxbuf[USARTRXDMABUFSZ]; @@ -123,19 +123,19 @@ void usart_setup(uint32_t speed){ * @brief usart_sendbuf - send next data portion * @return true if sent something */ -static bool usart_sendbuf(){ - if(!txrdy) return false; +static uint8_t usart_sendbuf(){ + if(!txrdy) return 0; int rd = RB_read(&TxRB, dmatxbuf, USARTTXDMABUFSZ); - if(rd < 1) return false; // nothing to write or busy + if(rd < 1) return 0; // nothing to write or busy // set up DMA DMACHTX->CCR = DMATXCCR; DMACHTX->CMAR = (uint32_t) dmatxbuf; DMACHTX->CNDTR = rd; USARTx->ICR = USART_ICR_TCCF; // clear TC flag - txrdy = false; + txrdy = 0; // activate DMA DMACHTX->CCR = DMATXCCR | DMA_CCR_EN; - return true; + return 1; } int usart_send(const char *str, int len){ @@ -235,7 +235,7 @@ char *usart_getline(){ // interrupt by '\n' static void usart_isr(){ if(USARTx->ISR & USART_ISR_CMF){ // got '\n' @ USARTx - gotstring = true; + gotstring = 1; } USARTx->ICR = 0xffffffff; // clear all flags } @@ -251,7 +251,7 @@ static void dmarx_isr(){ static void dmatx_isr(){ volatile uint32_t isr = DMAx->ISR; - if(isr & DMATXTCF) txrdy = true; + if(isr & DMATXTCF) txrdy = 1; if(isr & DMATXEF) curflags.txerr = 1; DMAx->IFCR = DMATXTCF | DMATXEF; // clear all flags } diff --git a/G4:G431/USB_CDC/usb_dev.c b/G4:G431/USB_CDC/usb_dev.c index 2af95f9..ee7ed0e 100644 --- a/G4:G431/USB_CDC/usb_dev.c +++ b/G4:G431/USB_CDC/usb_dev.c @@ -21,6 +21,8 @@ #include "usb_descr.h" #include "usb_dev.h" +//#pragma GCC optimize ("O1") + // Class-Specific Control Requests #define SEND_ENCAPSULATED_COMMAND 0x00 // unused #define GET_ENCAPSULATED_RESPONSE 0x01 // unused diff --git a/G4:G431/USB_CDC/usbcdc.bin b/G4:G431/USB_CDC/usbcdc.bin index a8e191a..43f602b 100755 Binary files a/G4:G431/USB_CDC/usbcdc.bin and b/G4:G431/USB_CDC/usbcdc.bin differ diff --git a/makefile.stm32 b/makefile.stm32 index ef9a466..2880721 100644 --- a/makefile.stm32 +++ b/makefile.stm32 @@ -49,7 +49,7 @@ LIB_DIR := $(INC_DIR)/ld ############################################################################### # C flags -CFLAGS += -D__thumb2__=1 -MD +CFLAGS += -D__thumb2__=1 -MD CFLAGS += -Wall -Wextra -Wshadow -Wdouble-promotion CFLAGS += -fshort-enums -ffunction-sections -fdata-sections #CFLAGS += -fno-common -fno-stack-protector @@ -57,12 +57,12 @@ CFLAGS += $(ARCH_FLAGS) ############################################################################### # Linker flags -LDFLAGS += -nostartfiles --static -specs=nosys.specs -specs=nano.specs +LDFLAGS += -nostartfiles --static -specs=nano.specs LDFLAGS += $(ARCH_FLAGS) LDFLAGS += -L$(LIB_DIR) #-L$(TOOLCHLIB) LDFLAGS += -T$(LDSCRIPT) -LDFLAGS += -Wl,-Map=$(MAP),--cref -Wl,--gc-sections -Wl,--print-memory-usage +LDFLAGS += -Wl,-Map=$(MAP),--cref -Wl,--gc-sections -Wl,--print-memory-usage -Wl,--trace-symbol=_sbrk ############################################################################### # Used libraries @@ -102,6 +102,8 @@ debug: CFLAGS += -O0 -DEBUG -Werror -g3 -gdwarf-2 debug: TARGET := DEBUG debug: $(TARGFILE) bin list size +all: $(BIN) + $(TARGFILE): $(OBJDIR) @echo -e "\t\tTARGET: $(TARGET)" @echo "$(TARGET)" > $(TARGFILE) @@ -130,13 +132,15 @@ $(VERSION_FILE): *.[ch] $(OBJDIR)/proto.o: proto.c $(VERSION_FILE) +$(OBJDIR)/usb_dev.o: CFLAGS := $(filter-out -flto,$(CFLAGS)) -fno-lto + $(OBJDIR)/%.o: %.c @echo " CC $<" $(CC) $(CFLAGS) $(DEFS) $(INCLUDE) -o $@ -c $< $(OBJDIR)/%.o: %.cpp @echo " C++ $<" - $(CPP) -c $(CFLAGS) -fno-exceptions $(DEFS) $(INCLUDE) -o $@ -c $< + $(CPP) -c $(CFLAGS) -std=c++11 -fno-exceptions -fno-rtti -Wl,--trace-symbol=_sbrk $(DEFS) $(INCLUDE) -o $@ -c $< $(BIN): $(ELF) @echo " OBJCOPY $(BIN)"