Skip to content

Commit

Permalink
Fix GNSS support (#58)
Browse files Browse the repository at this point in the history
* ublox example is working

* worked a bit on printf stuff

* modified API to include accuracies

* Add time struct for organization

* Add support for gps

* updated GPS interface

* Rework GNSS interface

* Replace GPS with GNSS

* Add gitignore for astyle .orig files

* run astyle

* resolved GCC 8 errors, and moved GPS example to UART1

* Add init check for ublox driver

* Update GPS example to deal with slow initialization

* Remove magic values

* Add ability to search for GNSS asynchronously

* Get GNSS example compiling

* asynchronous gnss initialization, including if the device is connected after startup

* GNSS reconnects after disconnect

* Code cleanup

* Revert files that shouldn't have changed

* Fix missing include in backup_sram

* Change GPS references to GNSS

* Remove debug statements

* remove unneeded wait

* clean up gnss example

* Improve struct initialization

* remove custom time conversion code

Co-authored-by: James Jackson <[email protected]>
  • Loading branch information
BillThePlatypus and superjax authored Apr 17, 2020
1 parent f56ba9f commit 14902a6
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 319 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
*.autosave
*.swp
*.map
*.orig
6 changes: 3 additions & 3 deletions examples/gps/Makefile → examples/gnss/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

TARGET = gps
TARGET = gnss

BOARD ?= REVO

Expand Down Expand Up @@ -165,7 +165,7 @@ TARGET_BIN=$(BIN_DIR)/$(TARGET).bin
ifeq ($(DEBUG), GDB)
$(info ************ BUILDING DEBUG SYMBOLS ************)
DEBUG_FLAGS = -ggdb3
OPTIMIZE = -O0
OPTIMIZE = -Og
else
$(info ************ BUILDING RELEASE ************)
DEBUG_FLAGS = -g0
Expand All @@ -182,7 +182,7 @@ endif
# -Wredundant-decls -Wshadow -Wstrict-overflow=5 -Wswitch-default -Wundef -Wunused -Wvariadic-macros \
# -Wctor-dtor-privacy -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel
FILE_SIZE_FLAGS += -ffunction-sections -fdata-sections -fno-exceptions
CXX_FILE_SIZE_FLAGS = $(C_FILE_SIZE_FLAGS) -fno-rtti
CXX_FILE_SIZE_FLAGS = $(FILE_SIZE_FLAGS) -fno-rtti

MCFLAGS=-mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
DEFS=-DSTM32F40_41xxx -D__CORTEX_M4 -D__FPU_PRESENT -DWORDS_STACK_SIZE=200 -DUSE_STDPERIPH_DRIVER -DTARGET_$(BOARD) -DHSE_VALUE=8000000
Expand Down
45 changes: 29 additions & 16 deletions examples/gps/main.cpp → examples/gnss/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "led.h"
#include "printf.h"
#include "revo_f4.h"
#include "serial.h"
#include "system.h"
#include "uart.h"
#include "ublox.h"
#include "vcp.h"

Serial* serPtr = NULL;
#define printf ::nanoprintf::tfp_printf

void rx_callback(uint8_t byte)
Serial *serPtr = NULL;

static void _putc(void *p, char c)
{
serPtr->put_byte(byte);
(void)p; // avoid compiler warning about unused variable
serPtr->put_byte(c);
}

int main()
Expand All @@ -52,22 +56,31 @@ int main()
serPtr = &vcp;

UART uart;
uart.init(&uart_config[UART3], 115200);
uart.init(&uart_config[UART1], 115200);

nanoprintf::init_printf(NULL, _putc);

UBLOX gnss;
gnss.init(&uart);

while (!gnss.present())
{
printf("GNSS not initialized");
delay(200);
gnss.check_connection_status();
}

vcp.register_rx_callback(rx_callback);
LED led1;
led1.init(LED1_GPIO, LED1_PIN);

UBLOX gps;
gps.init(&uart);
delay(5000); // Wait for the UBX to boot up

double lla[3];
float vel[3];
uint8_t fix_type;
uint32_t t_ms;
while (1)
{
if (gps.new_data())
{
gps.read(lla, vel, &fix_type, &t_ms);
}
UBLOX::NAV_PVT_t raw = gnss.read_raw();
printf("fix: %s\tt: %d\tlla: %d, %d, %d\tvel: %d, %d, %d\n", fix_names[raw.fixType].c_str(), raw.iTOW, raw.lat,
raw.lon, raw.height, raw.velN, raw.velE, raw.velD);
led1.toggle();
delay(1000);
}
}
15 changes: 9 additions & 6 deletions include/revo_f4.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@
#define UART2 1
#define UART3 2
const uart_hardware_struct_t uart_config[NUM_UART] = {
{USART1, GPIOA, GPIO_Pin_10, GPIO_Pin_9, GPIO_PinSource10, GPIO_PinSource9, GPIO_AF_USART1, USART1_IRQn,
DMA2_Stream5_IRQn, DMA2_Stream7_IRQn, DMA2_Stream5, DMA2_Stream7, DMA_Channel_4, DMA_IT_TCIF5, DMA_IT_TCIF7},
{USART2, GPIOA, GPIO_Pin_10, GPIO_Pin_9, GPIO_PinSource10, GPIO_PinSource9, GPIO_AF_USART2, USART2_IRQn,
DMA1_Stream5_IRQn, DMA1_Stream6_IRQn, DMA1_Stream5, DMA1_Stream6, DMA_Channel_5, DMA_IT_TCIF5, DMA_IT_TCIF6},
{USART3, GPIOB, GPIO_Pin_11, GPIO_Pin_10, GPIO_PinSource11, GPIO_PinSource10, GPIO_AF_USART3, USART3_IRQn,
DMA1_Stream1_IRQn, DMA1_Stream3_IRQn, DMA1_Stream1, DMA1_Stream3, DMA_Channel_4, DMA_IT_TCIF1, DMA_IT_TCIF3},
{USART1, GPIOA, GPIO_Pin_10, GPIO_Pin_9, GPIO_PinSource10, GPIO_PinSource9,
GPIO_AF_USART1, USART1_IRQn, DMA2_Stream5_IRQn, DMA2_Stream7_IRQn, DMA2_Stream5, //main port?
DMA2_Stream7, DMA_Channel_4, DMA_IT_TCIF5, DMA_IT_TCIF7},
{USART2, GPIOA, GPIO_Pin_10, GPIO_Pin_9, GPIO_PinSource10, GPIO_PinSource9,
GPIO_AF_USART2, USART2_IRQn, DMA1_Stream5_IRQn, DMA1_Stream6_IRQn, DMA1_Stream5, //Flex-IO port?
DMA1_Stream6, DMA_Channel_5, DMA_IT_TCIF5, DMA_IT_TCIF6},
{USART3, GPIOB, GPIO_Pin_11, GPIO_Pin_10, GPIO_PinSource11, GPIO_PinSource10,
GPIO_AF_USART3, USART3_IRQn, DMA1_Stream1_IRQn, DMA1_Stream3_IRQn, DMA1_Stream1, //Flexi port?
DMA1_Stream3, DMA_Channel_4, DMA_IT_TCIF1, DMA_IT_TCIF3},
};

#define SBUS_UART 0
Expand Down
Loading

0 comments on commit 14902a6

Please sign in to comment.