From 40808561a6fb224d0f4851b25332ffd0be1826bd Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 9 Apr 2014 19:59:38 +0200 Subject: fixed usb pump thread prio added better way for connect/disconnect USB --- software/mpu/Makefile | 1 + software/mpu/blockstore.c | 2 +- software/mpu/board-F405/board-utils.c | 82 +++++++++++++++++++++++++++++++++++ software/mpu/board-F405/board-utils.h | 45 +++++++++++++++++++ software/mpu/board-F405/board.c | 2 + software/mpu/board-F405/board.mk | 5 --- software/mpu/board.mk | 2 +- software/mpu/main.c | 3 +- software/mpu/mcuconf-F405.h | 2 +- software/mpu/usb-cdc-shell.c | 14 +++--- software/mpu/utils.c | 47 ++++++++++++++++++++ software/mpu/utils.h | 38 ++++++++++++++++ 12 files changed, 225 insertions(+), 18 deletions(-) create mode 100644 software/mpu/board-F405/board-utils.c create mode 100644 software/mpu/board-F405/board-utils.h delete mode 100644 software/mpu/board-F405/board.mk create mode 100644 software/mpu/utils.c create mode 100644 software/mpu/utils.h (limited to 'software/mpu') diff --git a/software/mpu/Makefile b/software/mpu/Makefile index 528b4ea..3c049b4 100644 --- a/software/mpu/Makefile +++ b/software/mpu/Makefile @@ -110,6 +110,7 @@ CSRC = $(PORTSRC) \ usb-cdc-shell.c \ ihu.c \ blockstore.c \ + utils.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global diff --git a/software/mpu/blockstore.c b/software/mpu/blockstore.c index fc22321..4a6d506 100644 --- a/software/mpu/blockstore.c +++ b/software/mpu/blockstore.c @@ -47,7 +47,7 @@ static msg_t blockstoreRun(void *arg) if(BLK_STOP == s || BLK_UNINIT) { return 0; } - // DO something + // DO something chThdSleepMilliseconds(100); } return 0; diff --git a/software/mpu/board-F405/board-utils.c b/software/mpu/board-F405/board-utils.c new file mode 100644 index 0000000..4928bb6 --- /dev/null +++ b/software/mpu/board-F405/board-utils.c @@ -0,0 +1,82 @@ +/* + * + * mur.sat + * + * Somewhen in the year 2012, mur.at will have a nano satellite launched + * into a low earth orbit (310 km above the surface of our planet). The + * satellite itself is a TubeSat personal satellite kit, developed and + * launched by interorbital systems. mur.sat is a joint venture of mur.at, + * ESC im Labor and realraum. + * + * Please visit the project hompage at sat.mur.at for further information. + * + * + * Copyright (C) 2013 Christian Pointner + * + * This file is part of mur.sat. + * + * mur.sat is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * mur.sat 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. + * + * You should have received a copy of the GNU General Public License + * along with mur.sat. If not, see . + * + */ + +#include "ch.h" +#include "hal.h" + +#include "board-utils.h" + +#if HAL_USE_USB + +int usbConnect(USBDriver* usbp) +{ +// usbConnectBus(usbp); // on F405 this only enables VBUS sensing - not needed + +#if STM32_USB_USE_OTG1 + if(usbp == &USBD1) { + palClearPad(GPIOA, GPIOA_USB_DISC); + return 0; + } +#endif + +#if STM32_USB_USE_OTG2 + if(usbp == &USBD2) { + palClearPad(GPIO, GPIO_USB2_DISC); + return 0; + } +#endif + + return 1; +} + +int usbDisconnect(USBDriver* usbp) +{ +// usbDisconnectBus(usbp); // on F405 this only disables VBUS sensing - not needed + +#if STM32_USB_USE_OTG1 + if(usbp == &USBD1) { + palSetPad(GPIOA, GPIOA_USB_DISC); + return 0; + } +#endif + +#if STM32_USB_USE_OTG2 + if(usbp == &USBD2) { +// palSetPad(GPIO, GPIO_USB2_DISC); + return 0; + } +#endif + + return 1; +} + +#endif /* HAL_USE_USB */ diff --git a/software/mpu/board-F405/board-utils.h b/software/mpu/board-F405/board-utils.h new file mode 100644 index 0000000..1ceb614 --- /dev/null +++ b/software/mpu/board-F405/board-utils.h @@ -0,0 +1,45 @@ +/* + * + * mur.sat + * + * Somewhen in the year 2012, mur.at will have a nano satellite launched + * into a low earth orbit (310 km above the surface of our planet). The + * satellite itself is a TubeSat personal satellite kit, developed and + * launched by interorbital systems. mur.sat is a joint venture of mur.at, + * ESC im Labor and realraum. + * + * Please visit the project hompage at sat.mur.at for further information. + * + * + * Copyright (C) 2013 Christian Pointner + * + * This file is part of mur.sat. + * + * mur.sat is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * mur.sat 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. + * + * You should have received a copy of the GNU General Public License + * along with mur.sat. If not, see . + * + */ + +#ifndef MURSAT_board_utils_h_INCLUDED +#define MURSAT_board_utils_h_INCLUDED + +#include "halconf.h" + +#if HAL_USE_USB + +int usbConnect(USBDriver* usbp); +int usbDisconnect(USBDriver* usbp); + +#endif /* HAL_USE_USB */ + +#endif diff --git a/software/mpu/board-F405/board.c b/software/mpu/board-F405/board.c index 0813bb6..a5d0b55 100644 --- a/software/mpu/board-F405/board.c +++ b/software/mpu/board-F405/board.c @@ -62,6 +62,8 @@ void __early_init(void) { void boardInit(void) { } + + #if HAL_USE_SDC /** * @brief Insertion monitor function. diff --git a/software/mpu/board-F405/board.mk b/software/mpu/board-F405/board.mk deleted file mode 100644 index 078d5d5..0000000 --- a/software/mpu/board-F405/board.mk +++ /dev/null @@ -1,5 +0,0 @@ -# List of all the board related files. -BOARDSRC = board/board.c - -# Required include directories -BOARDINC = board diff --git a/software/mpu/board.mk b/software/mpu/board.mk index 2ba51f9..4a58b34 100644 --- a/software/mpu/board.mk +++ b/software/mpu/board.mk @@ -1,5 +1,5 @@ # List of all the board related files. -BOARDSRC = board-$(MURSAT_TRGT)/board.c +BOARDSRC = board-$(MURSAT_TRGT)/board.c board-$(MURSAT_TRGT)/board-utils.c # Required include directories BOARDINC = board-$(MURSAT_TRGT)/ diff --git a/software/mpu/main.c b/software/mpu/main.c index 3bae9f0..506d857 100644 --- a/software/mpu/main.c +++ b/software/mpu/main.c @@ -55,9 +55,10 @@ static void sysInit(void) static void subsystemsInit(void) { /* call init functions of all subsystems which should spawn threads for their task */ - heartbeatInit(); blockstoreInit(); ihuInit(); + + heartbeatInit(); } static void subsystemsStop(void) diff --git a/software/mpu/mcuconf-F405.h b/software/mpu/mcuconf-F405.h index 7ead1e4..f3bb27f 100644 --- a/software/mpu/mcuconf-F405.h +++ b/software/mpu/mcuconf-F405.h @@ -283,6 +283,6 @@ #define STM32_USB_OTG2_IRQ_PRIORITY 14 #define STM32_USB_OTG1_RX_FIFO_SIZE 512 #define STM32_USB_OTG2_RX_FIFO_SIZE 1024 -#define STM32_USB_OTG_THREAD_PRIO LOWPRIO +#define STM32_USB_OTG_THREAD_PRIO NORMALPRIO #define STM32_USB_OTG_THREAD_STACK_SIZE 128 #define STM32_USB_OTGFIFO_FILL_BASEPRI 0 diff --git a/software/mpu/usb-cdc-shell.c b/software/mpu/usb-cdc-shell.c index e2fb452..cd7ea15 100644 --- a/software/mpu/usb-cdc-shell.c +++ b/software/mpu/usb-cdc-shell.c @@ -60,6 +60,9 @@ #include "usb-cdc-shell.h" #include "usb-cdc-descriptor.h" +#include "board-utils.h" + +#include "utils.h" static SerialUSBDriver SDU1; @@ -319,15 +322,8 @@ int8_t usbCDCShellRun(void) { sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); - - palSetPad(GPIOA, GPIOA_USB_DISC); - usbDisconnectBus(serusbcfg.usbp); - - chThdSleepMilliseconds(100); - usbStart(serusbcfg.usbp, &usbcfg); - usbConnectBus(serusbcfg.usbp); - palClearPad(GPIOA, GPIOA_USB_DISC); + usbConnect(serusbcfg.usbp); shellInit(); @@ -344,9 +340,9 @@ int8_t usbCDCShellRun(void) chThdSleepMilliseconds(1000); } + usbDisconnect(serusbcfg.usbp); usbStop(serusbcfg.usbp); sduStop(&SDU1); - palSetPad(GPIOA, GPIOA_USB_DISC); return shell_return_code; } diff --git a/software/mpu/utils.c b/software/mpu/utils.c new file mode 100644 index 0000000..bfd89db --- /dev/null +++ b/software/mpu/utils.c @@ -0,0 +1,47 @@ +/* + * + * mur.sat + * + * Somewhen in the year 2012, mur.at will have a nano satellite launched + * into a low earth orbit (310 km above the surface of our planet). The + * satellite itself is a TubeSat personal satellite kit, developed and + * launched by interorbital systems. mur.sat is a joint venture of mur.at, + * ESC im Labor and realraum. + * + * Please visit the project hompage at sat.mur.at for further information. + * + * + * Copyright (C) 2013 Christian Pointner + * + * This file is part of mur.sat. + * + * mur.sat is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * mur.sat 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. + * + * You should have received a copy of the GNU General Public License + * along with mur.sat. If not, see . + * + */ + +#include "ch.h" +#include "hal.h" + +#include "utils.h" + +void debugBlink(unsigned int times) +{ + while(times--) { + palClearPad(GPIOA, GPIOA_LED); + chThdSleepMilliseconds(50); + palSetPad(GPIOA, GPIOA_LED); + if(times) + chThdSleepMilliseconds(50); + } +} diff --git a/software/mpu/utils.h b/software/mpu/utils.h new file mode 100644 index 0000000..bdb800e --- /dev/null +++ b/software/mpu/utils.h @@ -0,0 +1,38 @@ +/* + * + * mur.sat + * + * Somewhen in the year 2012, mur.at will have a nano satellite launched + * into a low earth orbit (310 km above the surface of our planet). The + * satellite itself is a TubeSat personal satellite kit, developed and + * launched by interorbital systems. mur.sat is a joint venture of mur.at, + * ESC im Labor and realraum. + * + * Please visit the project hompage at sat.mur.at for further information. + * + * + * Copyright (C) 2013 Christian Pointner + * + * This file is part of mur.sat. + * + * mur.sat is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * mur.sat 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. + * + * You should have received a copy of the GNU General Public License + * along with mur.sat. If not, see . + * + */ + +#ifndef MURSAT_utils_h_INCLUDED +#define MURSAT_utils_h_INCLUDED + +void debugBlink(unsigned int times); + +#endif -- cgit v1.2.3