I can't understand this shit with UART!

This commit is contained in:
Edward Emelianov 2023-09-15 23:43:35 +03:00
parent 94f87db5c5
commit a8296717e1
8 changed files with 28 additions and 23 deletions

View File

@ -44,7 +44,7 @@ void sys_tick_handler(void){
++Tms; ++Tms;
} }
#if 0 #ifdef EBUG
static void iwdg_setup(){ static void iwdg_setup(){
/* Enable the peripheral clock RTC */ /* Enable the peripheral clock RTC */
/* (1) Enable the LSI (40kHz) */ /* (1) Enable the LSI (40kHz) */

View File

@ -56,9 +56,20 @@ uint8_t noLED =
void sendbuf(){ void sendbuf(){
IWDG->KR = IWDG_REFRESH; IWDG->KR = IWDG_REFRESH;
if(blen == 0) return; if(blen == 0) return;
#ifdef EBUG
USB_send(" sendbuf()\n");
#endif
*bptr = 0; *bptr = 0;
if(USBcmd) USB_send(buff); if(USBcmd) USB_send(buff);
else for(int i = 0; (i < 9999) && (LINE_BUSY == usart_send(buff, blen)); ++i){IWDG->KR = IWDG_REFRESH;} else for(int i = 0; (i < WAITFOR) && (LINE_BUSY == usart_send(buff, blen)); ++i){
#ifdef EBUG
USB_send(" line busy\n");
#endif
IWDG->KR = IWDG_REFRESH;
}
#ifdef EBUG
USB_send(" sendbuf() done\n");
#endif
bptr = buff; bptr = buff;
blen = 0; blen = 0;
} }
@ -69,7 +80,7 @@ void addtobuf(const char *txt){
if(l > UARTBUFSZ){ if(l > UARTBUFSZ){
sendbuf(); // send prevoius data in buffer sendbuf(); // send prevoius data in buffer
if(USBcmd) USB_send(txt); if(USBcmd) USB_send(txt);
else for(int i = 0; (i < 9999) && (LINE_BUSY == usart_send_blocking(txt, l)); ++i){IWDG->KR = IWDG_REFRESH;} else for(int i = 0; (i < WAITFOR) && (LINE_BUSY == usart_send_blocking(txt, l)); ++i){IWDG->KR = IWDG_REFRESH;}
}else{ }else{
if(blen+l > UARTBUFSZ){ if(blen+l > UARTBUFSZ){
sendbuf(); sendbuf();

View File

@ -65,11 +65,11 @@ const char *sensors_get_statename(SensorsState x){
// TODO: check if we can convert double to float! // TODO: check if we can convert double to float!
#ifndef EBUG //#ifndef EBUG
#define TYPE double //#define TYPE double
#else //#else
#define TYPE float #define TYPE float
#endif //#endif
const TYPE mul[5] = {-1.5e-2, 1., -2., 4., -2.}; const TYPE mul[5] = {-1.5e-2, 1., -2., 4., -2.};
/** /**

View File

@ -29,8 +29,6 @@
#include "usb.h" #include "usb.h"
#endif #endif
#define WAITFOR (72000000)
extern volatile uint32_t Tms; extern volatile uint32_t Tms;
static int datalen[2] = {0,0}; // received data line length (including '\n') static int datalen[2] = {0,0}; // received data line length (including '\n')
@ -109,15 +107,6 @@ TXstatus usart_send_blocking(const char *str, int len){
#endif #endif
return ALL_OK; return ALL_OK;
} }
/*
void usart_send_blck(const char *str){
while(!txrdy){IWDG->KR = IWDG_REFRESH;}
bufovr = 0;
while(*str){
USARTX -> TDR = *str++;
while(!(USARTX->ISR & USART_ISR_TXE)){IWDG->KR = IWDG_REFRESH;};
}
}*/
void usart_setup(){ void usart_setup(){
// Nucleo's USART2 connected to VCP proxy of st-link // Nucleo's USART2 connected to VCP proxy of st-link
@ -133,7 +122,7 @@ void usart_setup(){
DMA1_Channel4->CMAR = (uint32_t) tbuf; // mem DMA1_Channel4->CMAR = (uint32_t) tbuf; // mem
DMA1_Channel4->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq DMA1_Channel4->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
// Tx CNDTR set @ each transmission due to data size // Tx CNDTR set @ each transmission due to data size
NVIC_SetPriority(DMA1_Channel4_5_IRQn, 3); NVIC_SetPriority(DMA1_Channel4_5_IRQn, 0);
NVIC_EnableIRQ(DMA1_Channel4_5_IRQn); NVIC_EnableIRQ(DMA1_Channel4_5_IRQn);
NVIC_SetPriority(USART2_IRQn, 0); NVIC_SetPriority(USART2_IRQn, 0);
// setup usart2 // setup usart2
@ -159,7 +148,7 @@ void usart_setup(){
DMA1_Channel2->CMAR = (uint32_t) tbuf; // mem DMA1_Channel2->CMAR = (uint32_t) tbuf; // mem
DMA1_Channel2->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq DMA1_Channel2->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq
// Tx CNDTR set @ each transmission due to data size // Tx CNDTR set @ each transmission due to data size
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 3); NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn); NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
NVIC_SetPriority(USART1_IRQn, 0); NVIC_SetPriority(USART1_IRQn, 0);
// setup usart1 // setup usart1

View File

@ -31,6 +31,9 @@
#define TIMEOUT_MS (1500) #define TIMEOUT_MS (1500)
#endif #endif
// timeout for cycles
#define WAITFOR (72000000)
typedef enum{ typedef enum{
ALL_OK, ALL_OK,
LINE_BUSY, LINE_BUSY,

View File

@ -30,6 +30,8 @@
#ifdef EBUG #ifdef EBUG
#include "usart.h" #include "usart.h"
#define MSG(x) do{usart_send(x, sizeof(x));}while(0) #define MSG(x) do{usart_send(x, sizeof(x));}while(0)
#else
#define MSG(x)
#endif #endif

View File

@ -1,3 +1,3 @@
#define BUILD_NUMBER "80" #define BUILD_NUMBER "90"
#define BUILD_DATE "2023-09-12" #define BUILD_DATE "2023-09-15"
#define BUILDNO 80 #define BUILDNO 91