Fix serial port bug and several small changes

pull/2/head
Andy CA6JAU 9 years ago
parent 66fe701251
commit 39de090f19

@ -2,6 +2,9 @@
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM * Copyright (C) 2016 by Jim McLaughlin KI6ZUM
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU * Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* Some of the code is based on work of Guus Van Dooren PE1PLM:
* https://github.com/ki6zum/gmsk-dstar/blob/master/firmware/dvmega/dvmega.ino
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

@ -1,6 +1,7 @@
/* /*
TX fifo control - Copyright (C) KI6ZUM 2015 TX fifo control - Copyright (C) KI6ZUM 2015
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public

@ -1,6 +1,7 @@
/* /*
Serial fifo control - Copyright (C) KI6ZUM 2015 Serial fifo control - Copyright (C) KI6ZUM 2015
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public

@ -19,11 +19,14 @@
#if !defined(CONFIG_H) #if !defined(CONFIG_H)
#define CONFIG_H #define CONFIG_H
// Enable ADF7021 support:
#define ADF7021 #define ADF7021
// Host communication selection:
//#define STM32_USART1_HOST //#define STM32_USART1_HOST
#define STM32_USB_HOST #define STM32_USB_HOST
//#define SERIAL_REPEATER // Enable Nextion LCD serial port repeater:
#define SERIAL_REPEATER
#endif #endif

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -79,6 +79,9 @@ void CIO::interrupt()
{ {
uint8_t bit = 0; uint8_t bit = 0;
if (!m_started)
return;
if(m_tx) { if(m_tx) {
m_txBuffer.get(bit); m_txBuffer.get(bit);
@ -98,6 +101,23 @@ void CIO::interrupt()
} }
void CIO::start()
{
if (m_started)
return;
ifConf();
delay_rx();
setRX();
startInt();
m_started = true;
setMode();
}
void CIO::write(uint8_t* data, uint16_t length) void CIO::write(uint8_t* data, uint16_t length)
{ {
if (!m_started) if (!m_started)

@ -71,7 +71,8 @@ public:
void setTX(); void setTX();
void setRX(); void setRX();
void ifConf(); void ifConf();
void ifInit(); void start();
void startInt();
// Misc functions // Misc functions
void dlybit(void); void dlybit(void);

@ -99,21 +99,16 @@ void CIO::Init()
pinMode(PIN_P25_LED, OUTPUT); pinMode(PIN_P25_LED, OUTPUT);
pinMode(PIN_PTT_LED, OUTPUT); pinMode(PIN_PTT_LED, OUTPUT);
pinMode(PIN_COS_LED, OUTPUT); pinMode(PIN_COS_LED, OUTPUT);
} }
void CIO::ifInit() void CIO::startInt()
{ {
m_started = true;
#if defined (__STM32F1__) #if defined (__STM32F1__)
attachInterrupt(PIN_TXRX_CLK, EXT_IRQHandler, RISING); attachInterrupt(PIN_TXRX_CLK, EXT_IRQHandler, RISING);
#else #else
attachInterrupt(digitalPinToInterrupt(PIN_TXRX_CLK), EXT_IRQHandler, RISING); attachInterrupt(digitalPinToInterrupt(PIN_TXRX_CLK), EXT_IRQHandler, RISING);
#endif #endif
ifConf();
delay_rx();;
setRX();
} }
void CIO::SCLK_pin(bool on) void CIO::SCLK_pin(bool on)

@ -101,6 +101,8 @@ void CIO::Init()
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct); GPIO_StructInit(&GPIO_InitStruct);
@ -201,14 +203,6 @@ void CIO::Init()
GPIO_InitStruct.GPIO_Pin = PIN_COS_LED; GPIO_InitStruct.GPIO_Pin = PIN_COS_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_COS_LED, &GPIO_InitStruct); GPIO_Init(PORT_COS_LED, &GPIO_InitStruct);
}
void CIO::ifInit()
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
m_started = true;
// Connect EXTI15 Line // Connect EXTI15 Line
GPIO_EXTILineConfig(PORT_TXRX_CLK_INT, PIN_TXRX_CLK_INT); GPIO_EXTILineConfig(PORT_TXRX_CLK_INT, PIN_TXRX_CLK_INT);
@ -220,16 +214,18 @@ void CIO::ifInit()
EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); EXTI_Init(&EXTI_InitStructure);
}
void CIO::startInt()
{
NVIC_InitTypeDef NVIC_InitStructure;
// Enable and set EXTI15 Interrupt // Enable and set EXTI15 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); NVIC_Init(&NVIC_InitStructure);
ifConf();
delay_rx();;
setRX();
} }
void CIO::SCLK_pin(bool on) void CIO::SCLK_pin(bool on)

@ -2,6 +2,7 @@
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Mathis Schmieder DB9MAT * Copyright (C) 2016 by Mathis Schmieder DB9MAT
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016 by Jonathan Naylor G4KLX * Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016 by Jonathan Naylor G4KLX * Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -27,14 +28,17 @@ void CSerialPort::beginInt(uint8_t n, int speed)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
Serial1.begin(speed);
#else
Serial.begin(speed); Serial.begin(speed);
#endif
break; break;
/* case 2U: case 3U:
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
Serial2.begin(speed); Serial2.begin(speed);
#endif
break; break;
case 3U:
Serial3.begin(speed);
break;*/
default: default:
break; break;
} }
@ -44,11 +48,15 @@ int CSerialPort::availableInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
return Serial1.available();
#else
return Serial.available(); return Serial.available();
/* case 2U: #endif
return Serial2.available();
case 3U: case 3U:
return Serial3.available();*/ #if defined(SERIAL_REPEATER) && defined(__STM32F1__)
return Serial2.available();
#endif
default: default:
return false; return false;
} }
@ -58,11 +66,15 @@ uint8_t CSerialPort::readInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
return Serial1.read();
#else
return Serial.read(); return Serial.read();
/* case 2U: #endif
return Serial2.read();
case 3U: case 3U:
return Serial3.read();*/ #if defined(SERIAL_REPEATER) && defined(__STM32F1__)
return Serial2.read();
#endif
default: default:
return 0U; return 0U;
} }
@ -72,20 +84,20 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
Serial1.write(data, length);
break;
#else
Serial.write(data, length); Serial.write(data, length);
if (flush) if (flush)
Serial.flush(); Serial.flush();
break; break;
/* case 2U: #endif
case 3U:
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
Serial2.write(data, length); Serial2.write(data, length);
if (flush)
Serial2.flush();
break; break;
case 3U: #endif
Serial3.write(data, length);
if (flush)
Serial3.flush();
break;*/
default: default:
break; break;
} }

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2013,2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2013,2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -227,7 +228,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
dmrDMORX.setColorCode(colorCode); dmrDMORX.setColorCode(colorCode);
io.ifInit(); io.start();
return 0U; return 0U;
} }

@ -41,11 +41,11 @@ USART2 - TXD PA2 - RXD PA3
*/ */
#if defined(STM32_USART1_HOST)
#define TX_SERIAL_FIFO_SIZE 256U #define TX_SERIAL_FIFO_SIZE 256U
#define RX_SERIAL_FIFO_SIZE 256U #define RX_SERIAL_FIFO_SIZE 256U
#if defined(STM32_USART1_HOST)
extern "C" { extern "C" {
void USART1_IRQHandler(); void USART1_IRQHandler();
} }
@ -174,8 +174,8 @@ void InitUSART1(int speed)
// USART IRQ init // USART IRQ init
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure); NVIC_Init(&NVIC_InitStructure);
// Configure USART as alternate function // Configure USART as alternate function
@ -363,8 +363,8 @@ void InitUSART2(int speed)
// USART IRQ init // USART IRQ init
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure); NVIC_Init(&NVIC_InitStructure);
// Configure USART as alternate function // Configure USART as alternate function

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2009-2017 by Jonathan Naylor G4KLX * Copyright (C) 2009-2017 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX * Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

Loading…
Cancel
Save

Powered by TurnKey Linux.