diff --git a/src/Makefile b/src/Makefile index 732b83c77..6cd3d06e9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -496,7 +496,7 @@ ifeq ($(PCB), X9D) EEPROMSRC = eeprom_avr.cpp # TODO later eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += sky9x/audio.cpp - CPPSRC += x9d/pwr_driver.cpp x9d/eeprom_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/adc_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp + CPPSRC += x9d/pwr_driver.cpp x9d/eeprom_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/adc_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp x9d/uart.cpp CPPSRC += bmp.cpp monitors_views.cpp SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c @@ -504,6 +504,7 @@ ifeq ($(PCB), X9D) SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rtc.c SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c + SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s ifeq ($(SDCARD), YES) diff --git a/src/x9d/board_x9d.cpp b/src/x9d/board_x9d.cpp index 8c5148e90..4495ac436 100644 --- a/src/x9d/board_x9d.cpp +++ b/src/x9d/board_x9d.cpp @@ -121,7 +121,7 @@ void init5msTimer() // Timer14 RCC->APB1ENR |= RCC_APB1ENR_TIM14EN ; // Enable clock TIM14->ARR = 4999 ; // 5mS - TIM14->PSC = (PERI1_FREQUENCY * TIMER_MULT) / 1000000 - 1 ; // 1uS from 30MHz + TIM14->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1 ; // 1uS from 30MHz TIM14->CCER = 0 ; TIM14->CCMR1 = 0 ; TIM14->EGR = 0 ; @@ -174,6 +174,7 @@ void boardInit() __enable_irq() ; eepromInit(); + uartInit(); } #endif diff --git a/src/x9d/board_x9d.h b/src/x9d/board_x9d.h index 69e7b0db5..72dd82b68 100644 --- a/src/x9d/board_x9d.h +++ b/src/x9d/board_x9d.h @@ -41,6 +41,7 @@ #include "./STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_spi.h" #include "./STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rtc.h" #include "./STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_pwr.h" +#include "./STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_usart.h" #include "./STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h" #include "hal.h" @@ -48,10 +49,12 @@ #include "i2c_ee.h" #include "audio_driver.h" #include "delays.h" +#include "uart.h" #define PERI1_FREQUENCY 30000000 #define PERI2_FREQUENCY 60000000 -#define TIMER_MULT 2 +#define TIMER_MULT_APB1 2 +#define TIMER_MULT_APB2 1 // TODO elsewhere #if !defined(SIMU) diff --git a/src/x9d/delays.cpp b/src/x9d/delays.cpp index b113e00c7..406bf9529 100644 --- a/src/x9d/delays.cpp +++ b/src/x9d/delays.cpp @@ -37,7 +37,7 @@ void delaysInit(void) { // Timer13 RCC->APB1ENR |= RCC_APB1ENR_TIM13EN; // Enable clock - TIM13->PSC = (PERI1_FREQUENCY * TIMER_MULT) / 10000000 - 1; // 0.1uS + TIM13->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 10000000 - 1; // 0.1uS TIM13->CCER = 0; TIM13->CCMR1 = 0; TIM13->CR1 = 0x02; diff --git a/src/x9d/hal.h b/src/x9d/hal.h index ec814e6bb..ebe70a877 100644 --- a/src/x9d/hal.h +++ b/src/x9d/hal.h @@ -82,9 +82,16 @@ // Heart Beat #define PIN_HEART_BEAT GPIO_Pin_7 //PC.07 -// Update UART----RS232 ---UART3 -#define PIN_UPDATE_UART_TX GPIO_Pin_10 //PB.10 -#define PIN_UPDATE_UART_RX GPIO_Pin_11 //PB.11 +// 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 // USB_OTG #define PIN_FS_VBUS GPIO_Pin_9 //PA.09 diff --git a/src/x9d/uart.cpp b/src/x9d/uart.cpp new file mode 100644 index 000000000..f131b6291 --- /dev/null +++ b/src/x9d/uart.cpp @@ -0,0 +1,73 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * open9x is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include "../open9x.h" + +void uartSendChar(uint8_t c) +{ + USART_SendData(UART_DEBUG, c); + + /* Wait for end of previous transfer */ + while (USART_GetFlagStatus(UART_DEBUG, USART_FLAG_TC) == RESET); +} + + +void uartInit(void) +{ + USART_InitTypeDef USART_InitStructure; + GPIO_InitTypeDef GPIO_InitStructure; + + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_UART, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART_DEBUG, ENABLE); + + GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_RX, GPIO_AF_UART); + GPIO_PinAFConfig(GPIO_UART, GPIO_PinSource_UART_TX, GPIO_AF_UART); + + GPIO_InitStructure.GPIO_Pin = GPIO_PIN_UART_TX | GPIO_PIN_UART_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); + + USART_InitStructure.USART_BaudRate = DEBUG_UART_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_Init(UART_DEBUG, &USART_InitStructure); + USART_Cmd(UART_DEBUG, ENABLE); +} + diff --git a/src/x9d/uart.h b/src/x9d/uart.h new file mode 100644 index 000000000..d6adc9de5 --- /dev/null +++ b/src/x9d/uart.h @@ -0,0 +1,42 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * open9x is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef __UART_H +#define __UART_H + +#define DEBUG_UART_BAUDRATE 115200 + +void uartInit(void); +void uartSendChar(uint8_t c); + +#endif \ No newline at end of file