Fix serial port bug and several small changes

This commit is contained in:
Andy CA6JAU 2017-02-02 22:08:59 -03:00
parent 66fe701251
commit 39de090f19
30 changed files with 103 additions and 51 deletions

View file

@ -2,6 +2,9 @@
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View file

@ -1,6 +1,7 @@
/*
TX fifo control - Copyright (C) KI6ZUM 2015
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
modify it under the terms of the GNU Library General Public

View file

@ -1,6 +1,7 @@
/*
Serial fifo control - Copyright (C) KI6ZUM 2015
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
modify it under the terms of the GNU Library General Public

View file

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

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,6 +1,7 @@
/*
* Copyright (C) 2009-2016 by Jonathan Naylor G4KLX
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,6 +1,7 @@
/*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

20
IO.cpp
View file

@ -79,6 +79,9 @@ void CIO::interrupt()
{
uint8_t bit = 0;
if (!m_started)
return;
if(m_tx) {
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)
{
if (!m_started)

3
IO.h
View file

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

View file

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

View file

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

View file

@ -2,6 +2,7 @@
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Mathis Schmieder DB9MAT
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,6 +1,7 @@
/*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

52
SerialArduino.cpp Executable file → Normal file
View file

@ -1,5 +1,6 @@
/*
* 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
* 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) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
Serial1.begin(speed);
#else
Serial.begin(speed);
break;
/* case 2U:
Serial2.begin(speed);
#endif
break;
case 3U:
Serial3.begin(speed);
break;*/
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
Serial2.begin(speed);
#endif
break;
default:
break;
}
@ -44,11 +48,15 @@ int CSerialPort::availableInt(uint8_t n)
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
return Serial1.available();
#else
return Serial.available();
/* case 2U:
return Serial2.available();
#endif
case 3U:
return Serial3.available();*/
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
return Serial2.available();
#endif
default:
return false;
}
@ -58,11 +66,15 @@ uint8_t CSerialPort::readInt(uint8_t n)
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
return Serial1.read();
#else
return Serial.read();
/* case 2U:
return Serial2.read();
#endif
case 3U:
return Serial3.read();*/
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
return Serial2.read();
#endif
default:
return 0U;
}
@ -72,20 +84,20 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool
{
switch (n) {
case 1U:
#if defined(STM32_USART1_HOST) && defined(__STM32F1__)
Serial1.write(data, length);
break;
#else
Serial.write(data, length);
if (flush)
Serial.flush();
break;
/* case 2U:
Serial2.write(data, length);
if (flush)
Serial2.flush();
break;
#endif
case 3U:
Serial3.write(data, length);
if (flush)
Serial3.flush();
break;*/
#if defined(SERIAL_REPEATER) && defined(__STM32F1__)
Serial2.write(data, length);
break;
#endif
default:
break;
}

View file

@ -1,6 +1,7 @@
/*
* Copyright (C) 2013,2015,2016 by Jonathan Naylor G4KLX
* 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
* 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);
io.ifInit();
io.start();
return 0U;
}

View file

@ -41,11 +41,11 @@ USART2 - TXD PA2 - RXD PA3
*/
#if defined(STM32_USART1_HOST)
#define TX_SERIAL_FIFO_SIZE 256U
#define RX_SERIAL_FIFO_SIZE 256U
#if defined(STM32_USART1_HOST)
extern "C" {
void USART1_IRQHandler();
}
@ -174,8 +174,8 @@ void InitUSART1(int speed)
// USART IRQ init
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);
// Configure USART as alternate function
@ -363,8 +363,8 @@ void InitUSART2(int speed)
// USART IRQ init
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);
// Configure USART as alternate function
@ -498,7 +498,7 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool
usbserial.flush();
break;
#endif
#if defined(SERIAL_REPEATER)
#if defined(SERIAL_REPEATER)
case 3U:
WriteUSART2(data, length);
if (flush)

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,6 @@
/*
* 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
* it under the terms of the GNU General Public License as published by