diff options
Diffstat (limited to 'src/fsm')
-rw-r--r-- | src/fsm/Makefile | 8 | ||||
-rw-r--r-- | src/fsm/common.c | 45 | ||||
-rw-r--r-- | src/fsm/gps.c | 2 | ||||
-rw-r--r-- | src/fsm/main.c | 59 | ||||
-rw-r--r-- | src/fsm/pio.txt | 8 | ||||
-rw-r--r-- | src/fsm/usart.c | 39 | ||||
-rw-r--r-- | src/fsm/usart.h | 6 |
7 files changed, 113 insertions, 54 deletions
diff --git a/src/fsm/Makefile b/src/fsm/Makefile index 6891076..e7c6fb5 100644 --- a/src/fsm/Makefile +++ b/src/fsm/Makefile @@ -96,7 +96,7 @@ debug: release $(BINDIR)/$(BINHEX): $(BINDIR)/$(BINELF) $(CP) -O ihex $< $@ -$(BINDIR)/$(BINELF): $(OBJECTS) +$(BINDIR)/$(BINELF): $(OBJECTS) vc.h $(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(SIZE) $(BINDIR)/$(BINELF) @@ -106,6 +106,11 @@ $(BINDIR)/$(BINELF): $(OBJECTS) %.o: %.s $(CC) $(CFLAGS) $< -o $@ +vc.h: ../../.git/logs/HEAD + echo "// This file is generated by Makefile." > vc.h + echo "// Do not edit this file!" >> vc.h + git log -1 --format="format:#define GIT_VERSION \"%h\"" >> vc.h + clean: rm -f $(OBJECTS) $(BINDIR)/$(BINELF) $(BINDIR)/$(BINHEX) @@ -116,3 +121,4 @@ ifeq ($(wildcard /opt/openocd/bin/openocd),) else /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/board/stm32f4discovery.cfg -c "program bin/"$(BINELF)" verify reset" -c "init" -c "reset" -c "exit" endif + diff --git a/src/fsm/common.c b/src/fsm/common.c index 517eb80..33020e0 100644 --- a/src/fsm/common.c +++ b/src/fsm/common.c @@ -23,6 +23,7 @@ */ #include "common.h" +#include "usart.h" #include "FreeRTOS.h" #include "timers.h" #include <stm32f4xx.h> @@ -93,6 +94,8 @@ int random_bool(void) static int faultsource = 0; void trigger_fault(int source) { + usart_debug("Fatal: %d", source); + __disable_irq(); faultsource = source; @@ -100,4 +103,44 @@ void trigger_fault(int source) while (1) {} } - +void hard_fault_handler_c(uint32_t *hardfault_args) +{ + uint32_t stacked_r0; + uint32_t stacked_r1; + uint32_t stacked_r2; + uint32_t stacked_r3; + uint32_t stacked_r12; + uint32_t stacked_lr; + uint32_t stacked_pc; + uint32_t stacked_psr; + + stacked_r0 = hardfault_args[0]; + stacked_r1 = hardfault_args[1]; + stacked_r2 = hardfault_args[2]; + stacked_r3 = hardfault_args[3]; + + stacked_r12 = hardfault_args[4]; + stacked_lr = hardfault_args[5]; + stacked_pc = hardfault_args[6]; + stacked_psr = hardfault_args[7]; + + while (1); + + usart_debug_puts("\n\n[Hard fault handler - all numbers in hex]\n"); + usart_debug("R0 = %x\n", stacked_r0); + usart_debug("R1 = %x\n", stacked_r1); + usart_debug("R2 = %x\n", stacked_r2); + usart_debug("R3 = %x\n", stacked_r3); + usart_debug("R12 = %x\n", stacked_r12); + usart_debug("LR [R14] = %x subroutine call return address\n", stacked_lr); + usart_debug("PC [R15] = %x program counter\n", stacked_pc); + usart_debug("PSR = %x\n", stacked_psr); + usart_debug("BFAR = %x\n", (*((volatile unsigned long *)(0xE000ED38)))); + usart_debug("CFSR = %x\n", (*((volatile unsigned long *)(0xE000ED28)))); + usart_debug("HFSR = %x\n", (*((volatile unsigned long *)(0xE000ED2C)))); + usart_debug("DFSR = %x\n", (*((volatile unsigned long *)(0xE000ED30)))); + usart_debug("AFSR = %x\n", (*((volatile unsigned long *)(0xE000ED3C)))); + usart_debug("SCB_SHCSR = %x\n", SCB->SHCSR); + + while (1); +} diff --git a/src/fsm/gps.c b/src/fsm/gps.c index 2b6d058..7b86f1c 100644 --- a/src/fsm/gps.c +++ b/src/fsm/gps.c @@ -103,7 +103,7 @@ void gps_init() { gps_timeutc.valid = 0; - usart_init(); + usart_gps_init(); timeutc_semaphore = xSemaphoreCreateBinary(); diff --git a/src/fsm/main.c b/src/fsm/main.c index 1e897ab..8b56f22 100644 --- a/src/fsm/main.c +++ b/src/fsm/main.c @@ -40,6 +40,8 @@ #include "gps.h" #include "fsm.h" #include "common.h" +#include "usart.h" +#include "vc.h" #define GPIOD_BOARD_LED_GREEN GPIO_Pin_12 #define GPIOD_BOARD_LED_ORANGE GPIO_Pin_13 @@ -69,6 +71,8 @@ void vApplicationStackOverflowHook( TaskHandle_t xTask, int main(void) { init(); + usart_init(); + usart_debug_puts("glutt-o-matique version " GIT_VERSION "\n"); TaskHandle_t task_handle; xTaskCreate( @@ -94,11 +98,17 @@ int main(void) { // already running when calling the init functions. static void launcher_task(void *pvParameters) { + usart_debug_puts("1"); cw_psk31_init(16000); + usart_debug_puts("2"); pio_init(); + usart_debug_puts("3"); i2c_init(); + usart_debug_puts("4"); common_init(); + usart_debug_puts("5"); gps_init(); + usart_debug_puts("6"); TaskHandle_t task_handle; xTaskCreate( @@ -139,8 +149,10 @@ static void launcher_task(void *pvParameters) InitializeAudio(Audio16000HzSettings); SetAudioVolume(210); + usart_debug_puts("7"); PlayAudioWithCallback(audio_callback, NULL); + usart_debug_puts("8\n"); /* We are done now, suspend this task @@ -173,6 +185,7 @@ static void detect_button_press(void *pvParameters) if (pin_high_count == pin_high_thresh) { tm_trigger = 1; + usart_debug_puts("Bouton bleu\n"); } else if (pin_high_count == 0) { tm_trigger = 0; @@ -226,6 +239,12 @@ static void gps_monit_task(void *pvParameters) else { GPIO_ResetBits(GPIOD, GPIOD_BOARD_LED_BLUE); } + + if (gps_time.sec % 30 == 0) { + usart_debug("T_GPS %04d-%02d-%02d %02d:%02d\n", + gps_time.year, gps_time.month, gps_time.day, + gps_time.hour, gps_time.min); + } } vTaskDelay(100 / portTICK_RATE_MS); @@ -281,24 +300,17 @@ static void exercise_fsm(void *pvParameters) void init() { - GPIO_InitTypeDef GPIO_InitStructure; - USART_InitTypeDef USART_InitStructure; // ---------- SysTick timer -------- // if (SysTick_Config(SystemCoreClock / 1000)) { // Capture error while (1){}; } - // Enable full access to FPU (Should be done automatically in system_stm32f4xx.c): - //SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); // set CP10 and CP11 Full Access - - // GPIOD Periph clock enable RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); // Configure PD12, PD13, PD14 and PD15 in output pushpull mode + GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIOD_BOARD_LED_GREEN | GPIOD_BOARD_LED_ORANGE | @@ -314,38 +326,9 @@ void init() { // Init PushButton GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // TODO is there an external pullup ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); - - - // ------ UART ------ // - - // Clock - RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); - - // IO - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART1); - GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART1); - - // Conf - 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; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; - USART_Init(USART2, &USART_InitStructure); - - // Enable - USART_Cmd(USART2, ENABLE); } diff --git a/src/fsm/pio.txt b/src/fsm/pio.txt index a95fc67..72ff6ee 100644 --- a/src/fsm/pio.txt +++ b/src/fsm/pio.txt @@ -32,4 +32,12 @@ I2C to Audio Codec - i/o SDA PB9 - i/o SCL PB6 +STM32DISCOVERY onboard things +----------------------------- +- out Green LED PD12 +- out Orange LED PD13 +- out Red LED PD14 +- out Blue LED PD15 +- in Blue Push Button PA0 + diff --git a/src/fsm/usart.c b/src/fsm/usart.c index 98d49eb..57194db 100644 --- a/src/fsm/usart.c +++ b/src/fsm/usart.c @@ -53,19 +53,11 @@ static QueueHandle_t usart_nmea_queue; void usart_init() { - usart_nmea_queue = xQueueCreate(15, MAX_NMEA_SENTENCE_LEN); - if (usart_nmea_queue == 0) { - while(1); /* fatal error */ - } - - GPIO_InitTypeDef GPIO_InitStruct; - USART_InitTypeDef USART_InitStruct; - NVIC_InitTypeDef NVIC_InitStructure; - // ============== PC DEBUG USART =========== RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); + GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIOA_PIN_USART1_RX | GPIOA_PIN_USART1_TX; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; @@ -77,6 +69,7 @@ void usart_init() GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // Setup USART1 for 9600,8,N,1 + USART_InitTypeDef USART_InitStruct; USART_InitStruct.USART_BaudRate = 9600; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_StopBits = USART_StopBits_1; @@ -85,10 +78,11 @@ void usart_init() USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(USART1, &USART_InitStruct); - +#if 0 // enable the USART1 receive interrupt USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); + NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; @@ -99,12 +93,24 @@ void usart_init() // finally this enables the complete USART1 peripheral USART_Cmd(USART1, ENABLE); +#endif +} + +void usart_gps_init() +{ + usart_nmea_queue = xQueueCreate(15, MAX_NMEA_SENTENCE_LEN); + if (usart_nmea_queue == 0) { + while(1); /* fatal error */ + } + + return; // ============== GPS USART =========== // Setup GPIO D and connect to USART 3 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); + GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIOD_PIN_USART3_RX | GPIOD_PIN_USART3_TX; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; @@ -116,7 +122,7 @@ void usart_init() GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); // Setup USART3 for 9600,8,N,1 - + USART_InitTypeDef USART_InitStruct; USART_InitStruct.USART_BaudRate = 9600; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_StopBits = USART_StopBits_1; @@ -129,9 +135,10 @@ void usart_init() // enable the USART3 receive interrupt USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); + NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); @@ -223,3 +230,11 @@ void USART3_IRQHandler(void) } } +void USART1_IRQHandler(void) +{ + if (USART_GetITStatus(USART1, USART_IT_RXNE)) { + char t = USART1->DR; + (void)t; // ignore t + } +} + diff --git a/src/fsm/usart.h b/src/fsm/usart.h index 0a8c12e..7d4bfa9 100644 --- a/src/fsm/usart.h +++ b/src/fsm/usart.h @@ -33,9 +33,13 @@ #define MAX_NMEA_SENTENCE_LEN 256 -// Initialise both USART1 for PC and USART3 for GPS +// Initialise USART1 for PC debugging void usart_init(void); +// Initialise USART3 for GPS and NMEA queue +// Needs running scheduler +void usart_gps_init(void); + // Send the str to the GPS receiver void usart_gps_puts(const char* str); |