From 08002ebd65634832580bc50b838f1bddafabf8c8 Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Fri, 20 Dec 2013 16:38:03 +0100 Subject: [PATCH] changed uart baudrate to 115200 bps, added two more debug registers --- firmware/src/CB_functions.c | 29 ++++++++++++++++++----- firmware/src/CB_functions.h | 6 +++-- firmware/src/Makefile | 1 + firmware/src/main.c | 47 +++++++++++-------------------------- firmware/src/usart1.c | 17 ++++++++++---- firmware/src/usart1.h | 3 --- 6 files changed, 54 insertions(+), 49 deletions(-) diff --git a/firmware/src/CB_functions.c b/firmware/src/CB_functions.c index 14e2428..7e94b38 100644 --- a/firmware/src/CB_functions.c +++ b/firmware/src/CB_functions.c @@ -14,14 +14,21 @@ uint16_t uC_regs[UC_NO_REGS]; -void report_register(uint8_t addr) { - USART_SendData(USART1, addr); // send address - while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); - USART_SendData(USART1, (uint8_t) (uC_regs[addr]>>8)); // upper nibble - while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); - USART_SendData(USART1, (uint8_t) (uC_regs[addr]& 0x00FF)); // lower nibble + +void uart_byte_to_fpga(uint8_t byte){ + USART_SendData(USART1, byte); // send address while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); +} + +void report_register(uint8_t addr) { + + // just for debug, counts number of read back operations + uC_regs[0x13]++; + + uart_byte_to_fpga(addr); + uart_byte_to_fpga((uint8_t) (uC_regs[addr]>>8)); + uart_byte_to_fpga((uint8_t) (uC_regs[addr]& 0x00FF)); } @@ -76,6 +83,16 @@ void decode_register(uint8_t addr) { CB_GPIO_Out(LED1,thisRegister & 1<<0); } break; + + + case 0x12: + // send single byte back to fpga! + uart_byte_to_fpga( (uint8_t) (thisRegister&0x00FF)); + break; + + case 0x13: + // do nothing + break; } diff --git a/firmware/src/CB_functions.h b/firmware/src/CB_functions.h index 919aca2..7a24ff5 100644 --- a/firmware/src/CB_functions.h +++ b/firmware/src/CB_functions.h @@ -9,10 +9,12 @@ #include "stm32f10x.h" -#define UC_NO_REGS 18 +#define UC_NO_REGS 20 void init_CB_GPIO_Outputs(void); void decode_register(uint8_t addr); void report_register(uint8_t addr); -void report_all_registers(void); \ No newline at end of file +void report_all_registers(void); + +void uart_byte_to_fpga(uint8_t byte); \ No newline at end of file diff --git a/firmware/src/Makefile b/firmware/src/Makefile index 2495997..938b4bc 100644 --- a/firmware/src/Makefile +++ b/firmware/src/Makefile @@ -9,6 +9,7 @@ OBJS+=periph_conf.o OBJS+=CB_functions.o OBJS+=usart1.o OBJS+=spi2.o +OBJS+=misc_utils.o # OBJS+=keypins.o diff --git a/firmware/src/main.c b/firmware/src/main.c index 72cd60c..59c56db 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -17,6 +17,7 @@ #include "usart1.h" #include "spi2.h" #include "periph_conf.h" +#include "misc_utils.h" @@ -25,17 +26,17 @@ extern uint16_t SPIBuffer[]; extern uint16_t uC_regs[]; -GPIO_InitTypeDef GPIO_InitStructure; -NVIC_InitTypeDef NVIC_InitStructure; -SPI_InitTypeDef SPI_InitStructure; -USART_InitTypeDef USART_InitStructure; -DMA_InitTypeDef DMA_InitStructure; +// GPIO_InitTypeDef GPIO_InitStructure; +// NVIC_InitTypeDef NVIC_InitStructure; +// SPI_InitTypeDef SPI_InitStructure; +// USART_InitTypeDef USART_InitStructure; +// DMA_InitTypeDef DMA_InitStructure; // prototypes for functions that are included in main.c -void SysTick_Handler(void); +// void SysTick_Handler(void); @@ -51,44 +52,24 @@ int main(int argc, char *argv[]) { SystemInit(); disable_JTAG(); //disable JTAG to free GPIO ports init_CB_GPIO_Outputs(); - // configure timer interval // SysTick_Config(16777215); // standard - SysTick_Config(7200000); // 10 Hz interrupt +// SysTick_Config(7200000); // 10 Hz interrupt // SysTick_Config(720000); // 100 hz // SysTick_Config(72000); // 1000 hz - // UART init the StdPeriphLib way - - -// USART_InitStructure.USART_BaudRate = 9600; -// // USART_InitStructure.USART_BaudRate = 19200; -// USART_InitStructure.USART_WordLength = USART_WordLength_8b; -// USART_InitStructure.USART_StopBits = USART_StopBits_1; -// USART_InitStructure.USART_Parity = USART_Parity_No; -// USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; -// USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; -// -// STM_EVAL_COMInit(COM1, &USART_InitStructure); -// // STM_EVAL_COMInit(COM2, &USART_InitStructure); -// -// USART_SendData(EVAL_COM1, (uint8_t) 0); -// USART_SendData(EVAL_COM1, (uint8_t) 1); -// USART_SendData(EVAL_COM1, (uint8_t) 2); -// // USART_SendData(EVAL_COM2, (uint8_t) 'B'); init_SPI2(); -// SPIBuffer[0] = 0x1234; -// SPIBuffer[1] = 0x5678; - + init_USART1(); -// report_all_registers(); - + delay_ms(1000); + CB_GPIO_Out_Hi(LED4); + report_all_registers(); return 0; @@ -102,7 +83,7 @@ int main(int argc, char *argv[]) { - +/* void SysTick_Handler(void) { @@ -117,7 +98,7 @@ void SysTick_Handler(void) spi_addr=(spi_addr+1)%18; } - +*/ diff --git a/firmware/src/usart1.c b/firmware/src/usart1.c index e26dcca..c0962b8 100644 --- a/firmware/src/usart1.c +++ b/firmware/src/usart1.c @@ -8,6 +8,14 @@ #include "usart1.h" #include "stm32f10x_conf.h" + +// static (private) function prototypes +static void RCC_Configuration(void); +static void GPIO_Configuration(void); +static void NVIC_Configuration(void); + + + void init_USART1(void) { /* structure contains data for USART configuration */ @@ -19,7 +27,7 @@ void init_USART1(void) { NVIC_Configuration(); /* USARTx configuration ---------------------------------------------------*/ - USART_InitStructure.USART_BaudRate = 9600; + USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; @@ -33,12 +41,11 @@ void init_USART1(void) { /* Enabling interrupt from USART1 */ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); - while (1); } /* clock sources configuration */ -void RCC_Configuration(void) +static void RCC_Configuration(void) { /* error status */ ErrorStatus HSEStartUpStatus; @@ -70,7 +77,7 @@ void RCC_Configuration(void) /* I/O ports configuration */ -void GPIO_Configuration(void) +static void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; @@ -88,7 +95,7 @@ void GPIO_Configuration(void) /* NVIC module configuration */ -void NVIC_Configuration(void) +static void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; diff --git a/firmware/src/usart1.h b/firmware/src/usart1.h index 6166cba..b298e0b 100644 --- a/firmware/src/usart1.h +++ b/firmware/src/usart1.h @@ -13,6 +13,3 @@ void init_USART1(void); -void RCC_Configuration(void); -void GPIO_Configuration(void); -void NVIC_Configuration(void); \ No newline at end of file -- 2.43.0