fixed -flto problem (usb_dev.c needs -fno-lto)

This commit is contained in:
Edward Emelianov
2026-07-23 21:15:11 +03:00
parent 8252d370a2
commit 9fb0956dcf
7 changed files with 37 additions and 31 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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
}

View File

@@ -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

Binary file not shown.