diff --git a/src/debug.cpp b/src/debug.cpp index 0e7bdd3df..de8609635 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -40,7 +40,8 @@ #if !defined(SIMU) -Fifo32 debugFifo; +Fifo512 debugRxFifo; +Fifo512 debugTxFifo; // Outputs a string to the UART void debugPuts(const char *format, ...) @@ -54,7 +55,7 @@ void debugPuts(const char *format, ...) const char *t = tmp; while (*t) { - debugPutc(*t++); + debugTxFifo.push(*t++); } } @@ -78,10 +79,17 @@ void debugTask(void* pdata) uint8_t rxchar ; for (;;) { - while (!debugFifo.pop(rxchar)) + while (!debugRxFifo.pop(rxchar)) CoTickDelay(5); // 10ms } } +void debugTx(void) +{ + uint8_t txchar; + + if(debugTxFifo.pop(txchar)) + debugPutc(txchar); +} #endif diff --git a/src/debug.h b/src/debug.h index 7152793fd..23b0646e7 100644 --- a/src/debug.h +++ b/src/debug.h @@ -63,6 +63,7 @@ void dump(unsigned char *data, unsigned int size); #define DUMP(data, size) dump(data, size) void debugTask(void* pdata); +void debugTx(void); #else diff --git a/src/fifo.h b/src/fifo.h index a2160844a..af90a7306 100644 --- a/src/fifo.h +++ b/src/fifo.h @@ -37,17 +37,17 @@ #ifndef fifo_h #define fifo_h -class Fifo32 +class Fifo512 { public: - Fifo32(): + Fifo512(): widx(0), ridx(0) { } void push(uint8_t byte) { - uint32_t next = (widx+1) & 0x1f; + uint32_t next = (widx+1) & 0x1ff; if (next != ridx) { fifo[widx] = byte; widx = next; @@ -60,13 +60,13 @@ class Fifo32 } else { byte = fifo[ridx]; - ridx = (ridx+1) & 0x1f; + ridx = (ridx+1) & 0x1ff; return true; } } protected: - uint8_t fifo[32]; + uint8_t fifo[512]; volatile uint32_t widx; volatile uint32_t ridx; }; diff --git a/src/sky9x/debug_driver.cpp b/src/sky9x/debug_driver.cpp index dc51fcec9..4a7a04305 100644 --- a/src/sky9x/debug_driver.cpp +++ b/src/sky9x/debug_driver.cpp @@ -39,7 +39,7 @@ #if !defined(SIMU) -extern Fifo32 debugFifo; +extern Fifo512 debugRxFifo; /* * Outputs a character on the UART line. @@ -103,7 +103,7 @@ void DEBUG_UART_Stop() extern "C" void UART0_IRQHandler() { - debugFifo.push(CONSOLE_USART->UART_RHR); + debugRxFifo.push(CONSOLE_USART->UART_RHR); } #endif diff --git a/src/x9d/board_x9d.cpp b/src/x9d/board_x9d.cpp index 920723197..13411b418 100644 --- a/src/x9d/board_x9d.cpp +++ b/src/x9d/board_x9d.cpp @@ -171,6 +171,9 @@ void interrupt5ms() pre_scale = 0 ; per10ms(); } +#if defined(DEBUG) + debugTx(); +#endif } extern "C" void TIM8_TRG_COM_TIM14_IRQHandler() diff --git a/src/x9d/hal.h b/src/x9d/hal.h index 59b120c29..b6ac8e885 100644 --- a/src/x9d/hal.h +++ b/src/x9d/hal.h @@ -105,16 +105,16 @@ // Heart Beat #define PIN_HEART_BEAT GPIO_Pin_7 //PC.07 -// Debug UART -#define RCC_AHB1Periph_GPIO_UART RCC_AHB1Periph_GPIOB -#define RCC_APB1Periph_UART_DEBUG RCC_APB1Periph_USART3 -#define GPIO_UART GPIOB -#define GPIO_PIN_UART_TX GPIO_Pin_10 //PB.10 -#define GPIO_PIN_UART_RX GPIO_Pin_11 //PB.11 -#define GPIO_PinSource_UART_TX GPIO_PinSource10 -#define GPIO_PinSource_UART_RX GPIO_PinSource11 -#define GPIO_AF_UART GPIO_AF_USART3 -#define UART_DEBUG USART3 +// UART3 +#define RCC_AHB1Periph_GPIO_UART3 RCC_AHB1Periph_GPIOB +#define RCC_APB1Periph_UART3 RCC_APB1Periph_USART3 +#define GPIO_UART3 GPIOB +#define GPIO_PIN_UART3_TX GPIO_Pin_10 //PB.10 +#define GPIO_PIN_UART3_RX GPIO_Pin_11 //PB.11 +#define GPIO_PinSource_UART3_TX GPIO_PinSource10 +#define GPIO_PinSource_UART3_RX GPIO_PinSource11 +#define GPIO_AF_UART3 GPIO_AF_USART3 +#define UART3 USART3 // USB_OTG #define PIN_FS_VBUS GPIO_Pin_9 //PA.09 diff --git a/src/x9d/rtc_driver.cpp b/src/x9d/rtc_driver.cpp index c192de9e9..8056dbfb2 100644 --- a/src/x9d/rtc_driver.cpp +++ b/src/x9d/rtc_driver.cpp @@ -41,15 +41,18 @@ void rtcSetTime(struct gtm * t) RTC_TimeTypeDef RTC_TimeStruct; RTC_DateTypeDef RTC_DateStruct; + RTC_TimeStructInit(&RTC_TimeStruct); + RTC_DateStructInit(&RTC_DateStruct); + RTC_TimeStruct.RTC_Hours = t->tm_hour; RTC_TimeStruct.RTC_Minutes = t->tm_min; RTC_TimeStruct.RTC_Seconds = t->tm_sec; RTC_DateStruct.RTC_Year = t->tm_year - 100; - RTC_DateStruct.RTC_Month = t->tm_mon; + RTC_DateStruct.RTC_Month = t->tm_mon + 1; RTC_DateStruct.RTC_Date = t->tm_mday; - - RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct); - RTC_SetDate(RTC_Format_BCD, &RTC_DateStruct); + + RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct); + RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct); } void rtc_gettime(struct gtm * t) @@ -57,14 +60,14 @@ void rtc_gettime(struct gtm * t) RTC_TimeTypeDef RTC_TimeStruct; RTC_DateTypeDef RTC_DateStruct; - RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct); - RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct); - + RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct); + RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct); + t->tm_hour = RTC_TimeStruct.RTC_Hours; t->tm_min = RTC_TimeStruct.RTC_Minutes; t->tm_sec = RTC_TimeStruct.RTC_Seconds; t->tm_year = RTC_DateStruct.RTC_Year + 100; - t->tm_mon = RTC_DateStruct.RTC_Month; + t->tm_mon = RTC_DateStruct.RTC_Month - 1; t->tm_mday = RTC_DateStruct.RTC_Date; } diff --git a/src/x9d/uart_driver.cpp b/src/x9d/uart_driver.cpp index 3d801c18e..044bd014a 100644 --- a/src/x9d/uart_driver.cpp +++ b/src/x9d/uart_driver.cpp @@ -41,34 +41,32 @@ void uartInit(uint32_t baudrate) USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART, ENABLE); - RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART_DEBUG, ENABLE); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART3, ENABLE); - GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_RX, GPIO_AF_UART); - GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_TX, GPIO_AF_UART); + GPIO_PinAFConfig(GPIO_UART3, GPIO_PinSource_UART3_RX, GPIO_AF_UART3); + GPIO_PinAFConfig(GPIO_UART3, GPIO_PinSource_UART3_TX, GPIO_AF_UART3); - GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART_TX | GPIO_PIN_UART_RX; + GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART3_TX | GPIO_PIN_UART3_RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(GPIO_UART, &GPIO_InitStructure); + GPIO_Init(GPIO_UART3, &GPIO_InitStructure); + + RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART3, ENABLE); USART_InitStructure.USART_BaudRate = baudrate; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; - USART_InitStructure.USART_Mode = USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_InitStructure.USART_Mode = USART_Mode_Tx; - USART_Init(UART_DEBUG, &USART_InitStructure); - USART_Cmd(UART_DEBUG, ENABLE); + USART_Init(UART3, &USART_InitStructure); + USART_Cmd(UART3, ENABLE); } void uartPutc(const char c) { - USART_SendData(UART_DEBUG, c); - - /* Wait for end of previous transfer */ - while (USART_GetFlagStatus(UART_DEBUG, USART_FLAG_TC) == RESET); + USART_SendData(UART3, c); }