From 04ca97e5f81371175ea7013a8610e7beb63ff7a8 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 13 Aug 2017 18:51:09 +0100 Subject: [PATCH 01/17] Add enhancements suggested by IZ1MLT. --- DStarRX.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index c55edd5..4f65f6f 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -28,11 +28,7 @@ const uint32_t PLLMAX = 0x10000U; const uint32_t PLLINC = PLLMAX / DSTAR_RADIO_BIT_LENGTH; const uint32_t INC = PLLINC / 32U; -const unsigned int MAX_SYNC_BITS = 50U * DSTAR_DATA_LENGTH_BITS; - -const unsigned int SYNC_POS = 21U * DSTAR_DATA_LENGTH_BITS; -const unsigned int SYNC_SCAN_START = SYNC_POS - 3U; -const unsigned int SYNC_SCAN_END = SYNC_POS + 3U; +const unsigned int MAX_SYNC_BITS = 100U * DSTAR_DATA_LENGTH_BITS; // D-Star bit order version of 0x55 0x55 0x6E 0x0A const uint32_t FRAME_SYNC_DATA = 0x00557650U; @@ -372,7 +368,7 @@ void CDStarRX::processNone(bool bit) ::memset(m_rxBuffer, 0x00U, DSTAR_DATA_LENGTH_BYTES + 2U); m_rxBufferBits = 0U; - m_dataBits = 0U; + m_dataBits = MAX_SYNC_BITS; m_rxState = DSRXS_DATA; return; } @@ -401,8 +397,8 @@ void CDStarRX::processHeader(bool bit) ::memset(m_rxBuffer, 0x00U, DSTAR_DATA_LENGTH_BYTES + 2U); m_rxBufferBits = 0U; - m_rxState = DSRXS_DATA; - m_dataBits = SYNC_POS - DSTAR_DATA_LENGTH_BITS + 1U; + m_rxState = DSRXS_DATA; + m_dataBits = MAX_SYNC_BITS; } else { // The checksum failed, return to looking for syncs m_rxState = DSRXS_NONE; @@ -434,37 +430,29 @@ void CDStarRX::processData(bool bit) // Fuzzy matching of the data sync bit sequence bool syncSeen = false; - if (m_dataBits >= SYNC_SCAN_START && m_dataBits <= (SYNC_POS + 1U)) { + if (m_rxBufferBits >= (DSTAR_DATA_LENGTH_BITS - 3U)) { if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) { - if (m_dataBits < SYNC_POS) - DEBUG2("DStarRX: found data sync in Data, early", SYNC_POS - m_dataBits); - else - DEBUG1("DStarRX: found data sync in Data"); - m_rxBufferBits = DSTAR_DATA_LENGTH_BITS; - m_dataBits = 0U; - syncSeen = true; + m_dataBits = MAX_SYNC_BITS; + syncSeen = true; } } // Check to see if the sync is arriving late - if (m_dataBits == SYNC_POS) { + if (m_rxBufferBits == DSTAR_DATA_LENGTH_BITS && !syncSeen) { for (uint8_t i = 1U; i <= 3U; i++) { uint32_t syncMask = DATA_SYNC_MASK >> i; uint32_t syncData = DATA_SYNC_DATA >> i; if (countBits32((m_patternBuffer & syncMask) ^ syncData) <= DATA_SYNC_ERRS) { - DEBUG2("DStarRX: found data sync in Data, late", i); m_rxBufferBits -= i; - m_dataBits -= i; break; } } } - m_dataBits++; + m_dataBits--; - // We've not seen a data sync for too long, signal RXLOST and change to RX_NONE - if (m_dataBits >= MAX_SYNC_BITS) { + if (m_dataBits == 0U) { DEBUG1("DStarRX: data sync timed out, lost lock"); io.setDecode(false); From 74682e7ac0900bb735749d23ffbe4e7a35c4756d Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 18 Aug 2017 10:27:23 +0100 Subject: [PATCH 02/17] Optimise the DC offset code. --- DStarRX.cpp | 27 ++------------------------- DStarRX.h | 2 -- IO.cpp | 40 +++++++++++++++++++++++++++++++++++----- IO.h | 3 +++ P25RX.cpp | 29 ++--------------------------- P25RX.h | 2 -- YSFRX.cpp | 29 ++--------------------------- YSFRX.h | 2 -- 8 files changed, 44 insertions(+), 90 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index 4f65f6f..6321dff 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -237,10 +237,6 @@ const uint16_t CCITT_TABLE[] = { 0xf78fU, 0xe606U, 0xd49dU, 0xc514U, 0xb1abU, 0xa022U, 0x92b9U, 0x8330U, 0x7bc7U, 0x6a4eU, 0x58d5U, 0x495cU, 0x3de3U, 0x2c6aU, 0x1ef1U, 0x0f78U}; -// Generated using [b, a] = butter(1, 0.001) in MATLAB -static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} -const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage - CDStarRX::CDStarRX() : m_pll(0U), m_prev(false), @@ -257,16 +253,8 @@ m_pathMemory2(), m_pathMemory3(), m_fecOutput(), m_rssiAccum(0U), -m_rssiCount(0U), -m_dcFilter(), -m_dcState() +m_rssiCount(0U) { - ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); - - m_dcFilter.numStages = DC_FILTER_STAGES; - m_dcFilter.pState = m_dcState; - m_dcFilter.pCoeffs = DC_FILTER; - m_dcFilter.postShift = 0; } void CDStarRX::reset() @@ -283,22 +271,11 @@ void CDStarRX::reset() void CDStarRX::samples(q15_t* samples, const uint16_t* rssi, uint8_t length) { - q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; - - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); - - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; - for (uint16_t i = 0U; i < length; i++) { m_rssiAccum += rssi[i]; m_rssiCount++; - bool bit = (q31Samples[i] - dcLevel) < 0; + bool bit = samples[i] < 0; if (bit != m_prev) { if (m_pll < (PLLMAX / 2U)) diff --git a/DStarRX.h b/DStarRX.h index 49dab0b..48bb1a9 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -53,8 +53,6 @@ private: uint8_t m_fecOutput[42U]; uint32_t m_rssiAccum; uint16_t m_rssiCount; - arm_biquad_casd_df1_inst_q31 m_dcFilter; - q31_t m_dcState[4]; void processNone(bool bit); void processHeader(bool bit); diff --git a/IO.cpp b/IO.cpp index 0188d62..626f072 100644 --- a/IO.cpp +++ b/IO.cpp @@ -22,6 +22,10 @@ #include "Globals.h" #include "IO.h" +// Generated using [b, a] = butter(1, 0.001) in MATLAB +static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} +const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage + // Generated using rcosdesign(0.2, 8, 5, 'sqrt') in MATLAB static q15_t RRC_0_2_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 1472, 1450, 683, -675, -2144, -3040, -2706, -770, 2667, 6995, 11237, 14331, 15464, 14331, 11237, 6995, 2667, -770, -2706, -3040, -2144, -675, 683, 1450, 1472, 909, 112, @@ -43,6 +47,8 @@ m_started(false), m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), m_rssiBuffer(RX_RINGBUFFER_SIZE), +m_dcFilter(), +m_dcState(), m_rrcFilter(), m_gaussianFilter(), m_boxcarFilter(), @@ -67,6 +73,12 @@ m_lockout(false) ::memset(m_rrcState, 0x00U, 70U * sizeof(q15_t)); ::memset(m_gaussianState, 0x00U, 40U * sizeof(q15_t)); ::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t)); + ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); + + m_dcFilter.numStages = DC_FILTER_STAGES; + m_dcFilter.pState = m_dcState; + m_dcFilter.pCoeffs = DC_FILTER; + m_dcFilter.postShift = 0; m_rrcFilter.numTaps = RRC_0_2_FILTER_LEN; m_rrcFilter.pState = m_rrcState; @@ -157,21 +169,39 @@ void CIO::process() if (m_lockout) return; + q31_t dcLevel = 0; + q31_t dcVals[20U]; + q31_t q31Samples[20U]; + + ::arm_q15_to_q31(samples, q31Samples, length); + ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); + + for (uint8_t i = 0U; i < length; i++) + dcLevel += dcVals[i]; + dcLevel /= length; + + q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; + + q15_t dcSamples[RX_BLOCK_SIZE]; + for (uint8_t i = 0U; i < length; i++) + dcSamples[i] = samples[i] - offset; + if (m_modemState == STATE_IDLE) { if (m_dstarEnable) { q15_t GMSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_gaussianFilter, dcSamples, GMSKVals, RX_BLOCK_SIZE); dstarRX.samples(GMSKVals, rssi, RX_BLOCK_SIZE); } if (m_p25Enable) { q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_boxcarFilter, dcSamples, P25Vals, RX_BLOCK_SIZE); p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } + // XXX YSF should use dcSamples, but DMR not if (m_dmrEnable || m_ysfEnable) { q15_t C4FSKVals[RX_BLOCK_SIZE]; ::arm_fir_fast_q15(&m_rrcFilter, samples, C4FSKVals, RX_BLOCK_SIZE); @@ -189,7 +219,7 @@ void CIO::process() } else if (m_modemState == STATE_DSTAR) { if (m_dstarEnable) { q15_t GMSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_gaussianFilter, dcSamples, GMSKVals, RX_BLOCK_SIZE); dstarRX.samples(GMSKVals, rssi, RX_BLOCK_SIZE); } @@ -211,14 +241,14 @@ void CIO::process() } else if (m_modemState == STATE_YSF) { if (m_ysfEnable) { q15_t C4FSKVals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_rrcFilter, samples, C4FSKVals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_rrcFilter, dcSamples, C4FSKVals, RX_BLOCK_SIZE); ysfRX.samples(C4FSKVals, rssi, RX_BLOCK_SIZE); } } else if (m_modemState == STATE_P25) { if (m_p25Enable) { q15_t P25Vals[RX_BLOCK_SIZE]; - ::arm_fir_fast_q15(&m_boxcarFilter, samples, P25Vals, RX_BLOCK_SIZE); + ::arm_fir_fast_q15(&m_boxcarFilter, dcSamples, P25Vals, RX_BLOCK_SIZE); p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } diff --git a/IO.h b/IO.h index 80a6d28..5421881 100644 --- a/IO.h +++ b/IO.h @@ -60,6 +60,9 @@ private: CSampleRB m_txBuffer; CRSSIRB m_rssiBuffer; + arm_biquad_casd_df1_inst_q31 m_dcFilter; + q31_t m_dcState[4]; + arm_fir_instance_q15 m_rrcFilter; arm_fir_instance_q15 m_gaussianFilter; arm_fir_instance_q15 m_boxcarFilter; diff --git a/P25RX.cpp b/P25RX.cpp index 6c1d0af..6b4cfd4 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -38,10 +38,6 @@ const uint16_t NOENDPTR = 9999U; const unsigned int MAX_SYNC_FRAMES = 4U + 1U; -// Generated using [b, a] = butter(1, 0.001) in MATLAB -static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} -const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage - CP25RX::CP25RX() : m_state(P25RXS_NONE), m_bitBuffer(), @@ -64,16 +60,8 @@ m_threshold(), m_thresholdVal(0), m_averagePtr(NOAVEPTR), m_rssiAccum(0U), -m_rssiCount(0U), -m_dcFilter(), -m_dcState() +m_rssiCount(0U) { - ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); - - m_dcFilter.numStages = DC_FILTER_STAGES; - m_dcFilter.pState = m_dcState; - m_dcFilter.pCoeffs = DC_FILTER; - m_dcFilter.postShift = 0; } void CP25RX::reset() @@ -100,21 +88,8 @@ void CP25RX::reset() void CP25RX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) { - q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; - - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); - - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; - - q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; - for (uint8_t i = 0U; i < length; i++) { - q15_t sample = samples[i] - offset; + q15_t sample = samples[i]; m_rssiAccum += rssi[i]; m_rssiCount++; diff --git a/P25RX.h b/P25RX.h index 16f6cf3..48af4f9 100644 --- a/P25RX.h +++ b/P25RX.h @@ -59,8 +59,6 @@ private: uint8_t m_averagePtr; uint32_t m_rssiAccum; uint16_t m_rssiCount; - arm_biquad_casd_df1_inst_q31 m_dcFilter; - q31_t m_dcState[4]; void processNone(q15_t sample); void processHdr(q15_t sample); diff --git a/YSFRX.cpp b/YSFRX.cpp index f3be78c..3b156af 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -38,10 +38,6 @@ const uint16_t NOENDPTR = 9999U; const unsigned int MAX_SYNC_FRAMES = 4U + 1U; -// Generated using [b, a] = butter(1, 0.001) in MATLAB -static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} -const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage - CYSFRX::CYSFRX() : m_state(YSFRXS_NONE), m_bitBuffer(), @@ -62,16 +58,8 @@ m_threshold(), m_thresholdVal(0), m_averagePtr(NOAVEPTR), m_rssiAccum(0U), -m_rssiCount(0U), -m_dcFilter(), -m_dcState() +m_rssiCount(0U) { - ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); - - m_dcFilter.numStages = DC_FILTER_STAGES; - m_dcFilter.pState = m_dcState; - m_dcFilter.pCoeffs = DC_FILTER; - m_dcFilter.postShift = 0; } void CYSFRX::reset() @@ -96,21 +84,8 @@ void CYSFRX::reset() void CYSFRX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) { - q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; - - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); - - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; - - q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; - for (uint8_t i = 0U; i < length; i++) { - q15_t sample = samples[i] - offset; + q15_t sample = samples[i]; m_rssiAccum += rssi[i]; m_rssiCount++; diff --git a/YSFRX.h b/YSFRX.h index f00d6c4..a4aea4a 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -56,8 +56,6 @@ private: uint8_t m_averagePtr; uint32_t m_rssiAccum; uint16_t m_rssiCount; - arm_biquad_casd_df1_inst_q31 m_dcFilter; - q31_t m_dcState[4]; void processNone(q15_t sample); void processData(q15_t sample); From e707391a5eeec2c0673b20887897e5860fce5314 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 18 Aug 2017 10:40:34 +0100 Subject: [PATCH 03/17] Optimise the DC offset removal. --- DStarRX.cpp | 27 ++------------------------- DStarRX.h | 2 -- IO.cpp | 41 +++++++++++++++++++++++++++++++++++------ IO.h | 3 +++ P25RX.cpp | 29 ++--------------------------- P25RX.h | 2 -- YSFRX.cpp | 29 ++--------------------------- YSFRX.h | 2 -- 8 files changed, 44 insertions(+), 91 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index 4f65f6f..6321dff 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -237,10 +237,6 @@ const uint16_t CCITT_TABLE[] = { 0xf78fU, 0xe606U, 0xd49dU, 0xc514U, 0xb1abU, 0xa022U, 0x92b9U, 0x8330U, 0x7bc7U, 0x6a4eU, 0x58d5U, 0x495cU, 0x3de3U, 0x2c6aU, 0x1ef1U, 0x0f78U}; -// Generated using [b, a] = butter(1, 0.001) in MATLAB -static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} -const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage - CDStarRX::CDStarRX() : m_pll(0U), m_prev(false), @@ -257,16 +253,8 @@ m_pathMemory2(), m_pathMemory3(), m_fecOutput(), m_rssiAccum(0U), -m_rssiCount(0U), -m_dcFilter(), -m_dcState() +m_rssiCount(0U) { - ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); - - m_dcFilter.numStages = DC_FILTER_STAGES; - m_dcFilter.pState = m_dcState; - m_dcFilter.pCoeffs = DC_FILTER; - m_dcFilter.postShift = 0; } void CDStarRX::reset() @@ -283,22 +271,11 @@ void CDStarRX::reset() void CDStarRX::samples(q15_t* samples, const uint16_t* rssi, uint8_t length) { - q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; - - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); - - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; - for (uint16_t i = 0U; i < length; i++) { m_rssiAccum += rssi[i]; m_rssiCount++; - bool bit = (q31Samples[i] - dcLevel) < 0; + bool bit = samples[i] < 0; if (bit != m_prev) { if (m_pll < (PLLMAX / 2U)) diff --git a/DStarRX.h b/DStarRX.h index 49dab0b..48bb1a9 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -53,8 +53,6 @@ private: uint8_t m_fecOutput[42U]; uint32_t m_rssiAccum; uint16_t m_rssiCount; - arm_biquad_casd_df1_inst_q31 m_dcFilter; - q31_t m_dcState[4]; void processNone(bool bit); void processHeader(bool bit); diff --git a/IO.cpp b/IO.cpp index 1a65a8e..8b77f85 100644 --- a/IO.cpp +++ b/IO.cpp @@ -22,6 +22,10 @@ #include "Globals.h" #include "IO.h" +// Generated using [b, a] = butter(1, 0.001) in MATLAB +static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} +const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage + // One symbol boxcar filter static q15_t BOXCAR_FILTER[] = {12000, 12000, 12000, 12000, 12000, 0}; const uint16_t BOXCAR_FILTER_LEN = 6U; @@ -33,6 +37,8 @@ m_started(false), m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), m_rssiBuffer(RX_RINGBUFFER_SIZE), +m_dcFilter(), +m_dcState(), m_boxcarFilter(), m_boxcarState(), m_pttInvert(false), @@ -51,6 +57,12 @@ m_watchdog(0U), m_lockout(false) { ::memset(m_boxcarState, 0x00U, 30U * sizeof(q15_t)); + ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); + + m_dcFilter.numStages = DC_FILTER_STAGES; + m_dcFilter.pState = m_dcState; + m_dcFilter.pCoeffs = DC_FILTER; + m_dcFilter.postShift = 0; m_boxcarFilter.numTaps = BOXCAR_FILTER_LEN; m_boxcarFilter.pState = m_boxcarState; @@ -136,12 +148,29 @@ void CIO::process() q15_t vals[RX_BLOCK_SIZE]; ::arm_fir_fast_q15(&m_boxcarFilter, samples, vals, RX_BLOCK_SIZE); + q31_t dcLevel = 0; + q31_t dcValues[RX_BLOCK_SIZE]; + q31_t q31Vals[RX_BLOCK_SIZE]; + + ::arm_q15_to_q31(vals, q31Vals, RX_BLOCK_SIZE); + ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Vals, dcValues, RX_BLOCK_SIZE); + + for (uint8_t i = 0U; i < RX_BLOCK_SIZE; i++) + dcLevel += dcValues[i]; + dcLevel /= RX_BLOCK_SIZE; + + q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; + + q15_t dcVals[RX_BLOCK_SIZE]; + for (uint8_t i = 0U; i < RX_BLOCK_SIZE; i++) + dcVals[i] = vals[i] - offset; + if (m_modemState == STATE_IDLE) { if (m_dstarEnable) - dstarRX.samples(vals, rssi, RX_BLOCK_SIZE); + dstarRX.samples(dcVals, rssi, RX_BLOCK_SIZE); if (m_p25Enable) - p25RX.samples(vals, rssi, RX_BLOCK_SIZE); + p25RX.samples(dcVals, rssi, RX_BLOCK_SIZE); if (m_dmrEnable) { if (m_duplex) @@ -151,10 +180,10 @@ void CIO::process() } if (m_ysfEnable) - ysfRX.samples(vals, rssi, RX_BLOCK_SIZE); + ysfRX.samples(dcVals, rssi, RX_BLOCK_SIZE); } else if (m_modemState == STATE_DSTAR) { if (m_dstarEnable) - dstarRX.samples(vals, rssi, RX_BLOCK_SIZE); + dstarRX.samples(dcVals, rssi, RX_BLOCK_SIZE); } else if (m_modemState == STATE_DMR) { if (m_dmrEnable) { if (m_duplex) { @@ -169,10 +198,10 @@ void CIO::process() } } else if (m_modemState == STATE_YSF) { if (m_ysfEnable) - ysfRX.samples(vals, rssi, RX_BLOCK_SIZE); + ysfRX.samples(dcVals, rssi, RX_BLOCK_SIZE); } else if (m_modemState == STATE_P25) { if (m_p25Enable) - p25RX.samples(vals, rssi, RX_BLOCK_SIZE); + p25RX.samples(dcVals, rssi, RX_BLOCK_SIZE); } else if (m_modemState == STATE_DSTARCAL) { calDStarRX.samples(vals, RX_BLOCK_SIZE); } else if (m_modemState == STATE_RSSICAL) { diff --git a/IO.h b/IO.h index 8498b75..4c0c727 100644 --- a/IO.h +++ b/IO.h @@ -60,6 +60,9 @@ private: CSampleRB m_txBuffer; CRSSIRB m_rssiBuffer; + arm_biquad_casd_df1_inst_q31 m_dcFilter; + q31_t m_dcState[4]; + arm_fir_instance_q15 m_boxcarFilter; q15_t m_boxcarState[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare diff --git a/P25RX.cpp b/P25RX.cpp index 6c1d0af..6b4cfd4 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -38,10 +38,6 @@ const uint16_t NOENDPTR = 9999U; const unsigned int MAX_SYNC_FRAMES = 4U + 1U; -// Generated using [b, a] = butter(1, 0.001) in MATLAB -static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} -const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage - CP25RX::CP25RX() : m_state(P25RXS_NONE), m_bitBuffer(), @@ -64,16 +60,8 @@ m_threshold(), m_thresholdVal(0), m_averagePtr(NOAVEPTR), m_rssiAccum(0U), -m_rssiCount(0U), -m_dcFilter(), -m_dcState() +m_rssiCount(0U) { - ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); - - m_dcFilter.numStages = DC_FILTER_STAGES; - m_dcFilter.pState = m_dcState; - m_dcFilter.pCoeffs = DC_FILTER; - m_dcFilter.postShift = 0; } void CP25RX::reset() @@ -100,21 +88,8 @@ void CP25RX::reset() void CP25RX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) { - q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; - - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); - - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; - - q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; - for (uint8_t i = 0U; i < length; i++) { - q15_t sample = samples[i] - offset; + q15_t sample = samples[i]; m_rssiAccum += rssi[i]; m_rssiCount++; diff --git a/P25RX.h b/P25RX.h index 16f6cf3..48af4f9 100644 --- a/P25RX.h +++ b/P25RX.h @@ -59,8 +59,6 @@ private: uint8_t m_averagePtr; uint32_t m_rssiAccum; uint16_t m_rssiCount; - arm_biquad_casd_df1_inst_q31 m_dcFilter; - q31_t m_dcState[4]; void processNone(q15_t sample); void processHdr(q15_t sample); diff --git a/YSFRX.cpp b/YSFRX.cpp index f3be78c..3b156af 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -38,10 +38,6 @@ const uint16_t NOENDPTR = 9999U; const unsigned int MAX_SYNC_FRAMES = 4U + 1U; -// Generated using [b, a] = butter(1, 0.001) in MATLAB -static q31_t DC_FILTER[] = {3367972, 0, 3367972, 0, 2140747704, 0}; // {b0, 0, b1, b2, -a1, -a2} -const uint32_t DC_FILTER_STAGES = 1U; // One Biquad stage - CYSFRX::CYSFRX() : m_state(YSFRXS_NONE), m_bitBuffer(), @@ -62,16 +58,8 @@ m_threshold(), m_thresholdVal(0), m_averagePtr(NOAVEPTR), m_rssiAccum(0U), -m_rssiCount(0U), -m_dcFilter(), -m_dcState() +m_rssiCount(0U) { - ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); - - m_dcFilter.numStages = DC_FILTER_STAGES; - m_dcFilter.pState = m_dcState; - m_dcFilter.pCoeffs = DC_FILTER; - m_dcFilter.postShift = 0; } void CYSFRX::reset() @@ -96,21 +84,8 @@ void CYSFRX::reset() void CYSFRX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) { - q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; - - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); - - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; - - q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; - for (uint8_t i = 0U; i < length; i++) { - q15_t sample = samples[i] - offset; + q15_t sample = samples[i]; m_rssiAccum += rssi[i]; m_rssiCount++; diff --git a/YSFRX.h b/YSFRX.h index f00d6c4..a4aea4a 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -56,8 +56,6 @@ private: uint8_t m_averagePtr; uint32_t m_rssiAccum; uint16_t m_rssiCount; - arm_biquad_casd_df1_inst_q31 m_dcFilter; - q31_t m_dcState[4]; void processNone(q15_t sample); void processData(q15_t sample); From 3e03fcff8e533d6f993b7979dcbb9efd50f5b282 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 18 Aug 2017 10:42:41 +0100 Subject: [PATCH 04/17] Fix the lengths in the DC removal code. --- IO.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/IO.cpp b/IO.cpp index 626f072..90c04c2 100644 --- a/IO.cpp +++ b/IO.cpp @@ -170,20 +170,20 @@ void CIO::process() return; q31_t dcLevel = 0; - q31_t dcVals[20U]; - q31_t q31Samples[20U]; + q31_t dcValues[RX_BLOCK_SIZE]; + q31_t q31Samples[RX_BLOCK_SIZE]; - ::arm_q15_to_q31(samples, q31Samples, length); - ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcVals, length); + ::arm_q15_to_q31(samples, q31Samples, RX_BLOCK_SIZE); + ::arm_biquad_cascade_df1_q31(&m_dcFilter, q31Samples, dcValues, RX_BLOCK_SIZE); - for (uint8_t i = 0U; i < length; i++) - dcLevel += dcVals[i]; - dcLevel /= length; + for (uint8_t i = 0U; i < RX_BLOCK_SIZE; i++) + dcLevel += dcValues[i]; + dcLevel /= RX_BLOCK_SIZE; q15_t offset = q15_t(__SSAT((dcLevel >> 16), 16));; q15_t dcSamples[RX_BLOCK_SIZE]; - for (uint8_t i = 0U; i < length; i++) + for (uint8_t i = 0U; i < RX_BLOCK_SIZE; i++) dcSamples[i] = samples[i] - offset; if (m_modemState == STATE_IDLE) { From f4637585f680ef0f166889fb04a8efaa1cd63784 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 18 Aug 2017 10:57:47 +0100 Subject: [PATCH 05/17] Re-add the const qualifiers. --- DStarRX.cpp | 2 +- DStarRX.h | 2 +- IO.cpp | 2 +- P25RX.cpp | 2 +- P25RX.h | 2 +- YSFRX.cpp | 2 +- YSFRX.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index 6321dff..a6a4e34 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -269,7 +269,7 @@ void CDStarRX::reset() m_rssiCount = 0U; } -void CDStarRX::samples(q15_t* samples, const uint16_t* rssi, uint8_t length) +void CDStarRX::samples(const q15_t* samples, const uint16_t* rssi, uint8_t length) { for (uint16_t i = 0U; i < length; i++) { m_rssiAccum += rssi[i]; diff --git a/DStarRX.h b/DStarRX.h index 48bb1a9..d636cde 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -32,7 +32,7 @@ class CDStarRX { public: CDStarRX(); - void samples(q15_t* samples, const uint16_t* rssi, uint8_t length); + void samples(const q15_t* samples, const uint16_t* rssi, uint8_t length); void reset(); diff --git a/IO.cpp b/IO.cpp index 90c04c2..f711172 100644 --- a/IO.cpp +++ b/IO.cpp @@ -201,7 +201,7 @@ void CIO::process() p25RX.samples(P25Vals, rssi, RX_BLOCK_SIZE); } - // XXX YSF should use dcSamples, but DMR not + // XXX YSF should use dcSamples, but DMR not if (m_dmrEnable || m_ysfEnable) { q15_t C4FSKVals[RX_BLOCK_SIZE]; ::arm_fir_fast_q15(&m_rrcFilter, samples, C4FSKVals, RX_BLOCK_SIZE); diff --git a/P25RX.cpp b/P25RX.cpp index 6b4cfd4..9228c5b 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -86,7 +86,7 @@ void CP25RX::reset() m_rssiCount = 0U; } -void CP25RX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) +void CP25RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) { for (uint8_t i = 0U; i < length; i++) { q15_t sample = samples[i]; diff --git a/P25RX.h b/P25RX.h index 48af4f9..0bdf3c5 100644 --- a/P25RX.h +++ b/P25RX.h @@ -32,7 +32,7 @@ class CP25RX { public: CP25RX(); - void samples(q15_t* samples, uint16_t* rssi, uint8_t length); + void samples(const q15_t* samples, uint16_t* rssi, uint8_t length); void reset(); diff --git a/YSFRX.cpp b/YSFRX.cpp index 3b156af..88c6f83 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -82,7 +82,7 @@ void CYSFRX::reset() m_rssiCount = 0U; } -void CYSFRX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) +void CYSFRX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) { for (uint8_t i = 0U; i < length; i++) { q15_t sample = samples[i]; diff --git a/YSFRX.h b/YSFRX.h index a4aea4a..556280a 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -31,7 +31,7 @@ class CYSFRX { public: CYSFRX(); - void samples(q15_t* samples, uint16_t* rssi, uint8_t length); + void samples(const q15_t* samples, uint16_t* rssi, uint8_t length); void reset(); From 58966406da01a2c50bc303babb422eba975702d3 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 18 Aug 2017 11:00:25 +0100 Subject: [PATCH 06/17] Re-add the const qualifiers. --- DStarRX.cpp | 2 +- DStarRX.h | 2 +- P25RX.cpp | 2 +- P25RX.h | 2 +- YSFRX.cpp | 2 +- YSFRX.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index 6321dff..a6a4e34 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -269,7 +269,7 @@ void CDStarRX::reset() m_rssiCount = 0U; } -void CDStarRX::samples(q15_t* samples, const uint16_t* rssi, uint8_t length) +void CDStarRX::samples(const q15_t* samples, const uint16_t* rssi, uint8_t length) { for (uint16_t i = 0U; i < length; i++) { m_rssiAccum += rssi[i]; diff --git a/DStarRX.h b/DStarRX.h index 48bb1a9..d636cde 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -32,7 +32,7 @@ class CDStarRX { public: CDStarRX(); - void samples(q15_t* samples, const uint16_t* rssi, uint8_t length); + void samples(const q15_t* samples, const uint16_t* rssi, uint8_t length); void reset(); diff --git a/P25RX.cpp b/P25RX.cpp index 6b4cfd4..9228c5b 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -86,7 +86,7 @@ void CP25RX::reset() m_rssiCount = 0U; } -void CP25RX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) +void CP25RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) { for (uint8_t i = 0U; i < length; i++) { q15_t sample = samples[i]; diff --git a/P25RX.h b/P25RX.h index 48af4f9..0bdf3c5 100644 --- a/P25RX.h +++ b/P25RX.h @@ -32,7 +32,7 @@ class CP25RX { public: CP25RX(); - void samples(q15_t* samples, uint16_t* rssi, uint8_t length); + void samples(const q15_t* samples, uint16_t* rssi, uint8_t length); void reset(); diff --git a/YSFRX.cpp b/YSFRX.cpp index 3b156af..88c6f83 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -82,7 +82,7 @@ void CYSFRX::reset() m_rssiCount = 0U; } -void CYSFRX::samples(q15_t* samples, uint16_t* rssi, uint8_t length) +void CYSFRX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) { for (uint8_t i = 0U; i < length; i++) { q15_t sample = samples[i]; diff --git a/YSFRX.h b/YSFRX.h index a4aea4a..556280a 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -31,7 +31,7 @@ class CYSFRX { public: CYSFRX(); - void samples(q15_t* samples, uint16_t* rssi, uint8_t length); + void samples(const q15_t* samples, uint16_t* rssi, uint8_t length); void reset(); From 5b313b7cec7d8eb3bf698e276ffcc2c15799aff4 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sat, 19 Aug 2017 13:54:03 -0300 Subject: [PATCH 07/17] =?UTF-8?q?Replace=20=E2=80=9CGPIO=5FSpeed=5F50MHz?= =?UTF-8?q?=E2=80=9D=20definition=20for=20a=20better=20one=20=E2=80=9CGPIO?= =?UTF-8?q?=5FFast=5FSpeed=E2=80=9D=20(STM32F4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IOSTM.cpp | 2 +- SerialSTM.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/IOSTM.cpp b/IOSTM.cpp index 56826bb..f02c347 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -355,7 +355,7 @@ void CIO::initInt() { GPIO_InitTypeDef GPIO_InitStruct; GPIO_StructInit(&GPIO_InitStruct); - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStruct.GPIO_Speed = GPIO_Fast_Speed; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; diff --git a/SerialSTM.cpp b/SerialSTM.cpp index e2b128e..263c034 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -184,7 +184,7 @@ void InitUSART1(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; // Tx | Rx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure USART baud rate @@ -375,7 +375,7 @@ void InitUSART2(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; // Tx | Rx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure USART baud rate @@ -566,7 +566,7 @@ void InitUSART3(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; // Tx | Rx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOC, &GPIO_InitStructure); // Configure USART baud rate @@ -758,7 +758,7 @@ void InitUART5(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // Tx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // Rx From 1cee9e19c03005aa30bdc786620d272d79a4e3c5 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 20 Aug 2017 12:07:05 +0100 Subject: [PATCH 08/17] Add an adjustable transmit DC offset. --- IO.cpp | 7 +++++-- IO.h | 4 +++- SerialPort.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/IO.cpp b/IO.cpp index f711172..9880ab4 100644 --- a/IO.cpp +++ b/IO.cpp @@ -62,6 +62,7 @@ m_dstarTXLevel(128 * 128), m_dmrTXLevel(128 * 128), m_ysfTXLevel(128 * 128), m_p25TXLevel(128 * 128), +m_txDCOffset(DC_OFFSET), m_ledCount(0U), m_ledValue(true), m_detect(false), @@ -299,7 +300,7 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t for (uint16_t i = 0U; i < length; i++) { q31_t res1 = samples[i] * txLevel; q15_t res2 = q15_t(__SSAT((res1 >> 15), 16)); - uint16_t res3 = uint16_t(res2 + DC_OFFSET); + uint16_t res3 = uint16_t(res2 + m_txDCOffset); // Detect DAC overflow if (res3 > 4095U) @@ -340,7 +341,7 @@ void CIO::setMode() #endif } -void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel) +void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel, int16_t txDCOffset) { m_pttInvert = pttInvert; @@ -350,6 +351,8 @@ void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rx m_dmrTXLevel = q15_t(dmrTXLevel * 128); m_ysfTXLevel = q15_t(ysfTXLevel * 128); m_p25TXLevel = q15_t(p25TXLevel * 128); + + m_txDCOffset = DC_OFFSET + txDCOffset; if (rxInvert) m_rxLevel = -m_rxLevel; diff --git a/IO.h b/IO.h index 5421881..19807b1 100644 --- a/IO.h +++ b/IO.h @@ -42,7 +42,7 @@ public: void interrupt(); - void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel); + void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel, int16_t txDCOffset); void getOverflow(bool& adcOverflow, bool& dacOverflow); @@ -78,6 +78,8 @@ private: q15_t m_ysfTXLevel; q15_t m_p25TXLevel; + uint16_t m_txDCOffset; + uint32_t m_ledCount; bool m_ledValue; diff --git a/SerialPort.cpp b/SerialPort.cpp index 3ee2f21..235257d 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -221,7 +221,7 @@ void CSerialPort::getVersion() uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) { - if (length < 13U) + if (length < 14U) return 4U; bool rxInvert = (data[0U] & 0x01U) == 0x01U; @@ -268,6 +268,8 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) uint8_t ysfTXLevel = data[11U]; uint8_t p25TXLevel = data[12U]; + int16_t txDCOffset = int16_t(data[13U]) - 128; + m_modemState = modemState; m_dstarEnable = dstarEnable; @@ -289,7 +291,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) ysfTX.setLoDev(ysfLoDev); - io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel); + io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, txDCOffset); io.start(); From fbd9c4d18bd5e1f996f05e589a6b51058ad94ce0 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 20 Aug 2017 12:14:58 +0100 Subject: [PATCH 09/17] Add an optional TX DC offset. --- IO.cpp | 7 +++++-- IO.h | 4 +++- SerialPort.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/IO.cpp b/IO.cpp index 8b77f85..ea69377 100644 --- a/IO.cpp +++ b/IO.cpp @@ -48,6 +48,7 @@ m_dstarTXLevel(128 * 128), m_dmrTXLevel(128 * 128), m_ysfTXLevel(128 * 128), m_p25TXLevel(128 * 128), +m_txDCOffset(DC_OFFSET), m_ledCount(0U), m_ledValue(true), m_detect(false), @@ -246,7 +247,7 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t for (uint16_t i = 0U; i < length; i++) { q31_t res1 = samples[i] * txLevel; q15_t res2 = q15_t(__SSAT((res1 >> 15), 16)); - uint16_t res3 = uint16_t(res2 + DC_OFFSET); + uint16_t res3 = uint16_t(res2 + m_txDCOffset); // Detect DAC overflow if (res3 > 4095U) @@ -287,7 +288,7 @@ void CIO::setMode() #endif } -void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel) +void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel, int16_t txDCOffset) { m_pttInvert = pttInvert; @@ -297,6 +298,8 @@ void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rx m_dmrTXLevel = q15_t(dmrTXLevel * 128); m_ysfTXLevel = q15_t(ysfTXLevel * 128); m_p25TXLevel = q15_t(p25TXLevel * 128); + + m_txDCOffset = DC_OFFSET + txDCOffset; if (rxInvert) m_rxLevel = -m_rxLevel; diff --git a/IO.h b/IO.h index 4c0c727..ba7bbfa 100644 --- a/IO.h +++ b/IO.h @@ -42,7 +42,7 @@ public: void interrupt(); - void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel); + void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel, int16_t txDCOffset); void getOverflow(bool& adcOverflow, bool& dacOverflow); @@ -74,6 +74,8 @@ private: q15_t m_ysfTXLevel; q15_t m_p25TXLevel; + uint16_t m_txDCOffset; + uint32_t m_ledCount; bool m_ledValue; diff --git a/SerialPort.cpp b/SerialPort.cpp index 3ee2f21..235257d 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -221,7 +221,7 @@ void CSerialPort::getVersion() uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) { - if (length < 13U) + if (length < 14U) return 4U; bool rxInvert = (data[0U] & 0x01U) == 0x01U; @@ -268,6 +268,8 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) uint8_t ysfTXLevel = data[11U]; uint8_t p25TXLevel = data[12U]; + int16_t txDCOffset = int16_t(data[13U]) - 128; + m_modemState = modemState; m_dstarEnable = dstarEnable; @@ -289,7 +291,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) ysfTX.setLoDev(ysfLoDev); - io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel); + io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, txDCOffset); io.start(); From 8f317fd332992e410a399af47d6244f933edce42 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sun, 20 Aug 2017 11:19:58 -0300 Subject: [PATCH 10/17] Adding watchdog to host serial port --- IO.cpp | 5 +++++ IO.h | 1 + SerialPort.cpp | 43 ++++++++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/IO.cpp b/IO.cpp index f711172..fb9a325 100644 --- a/IO.cpp +++ b/IO.cpp @@ -386,6 +386,11 @@ void CIO::resetWatchdog() m_watchdog = 0U; } +uint32_t CIO::getWatchdog() +{ + return m_watchdog; +} + bool CIO::hasLockout() const { return m_lockout; diff --git a/IO.h b/IO.h index 5421881..6e243c8 100644 --- a/IO.h +++ b/IO.h @@ -52,6 +52,7 @@ public: bool hasLockout() const; void resetWatchdog(); + uint32_t getWatchdog(); private: bool m_started; diff --git a/SerialPort.cpp b/SerialPort.cpp index 3ee2f21..daf0ee9 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -421,6 +421,10 @@ void CSerialPort::process() m_ptr = 1U; m_len = 0U; } + else { + m_ptr = 0U; + m_len = 0U; + } } else if (m_ptr == 1U) { // Handle the frame length m_len = m_buffer[m_ptr] = c; @@ -645,9 +649,9 @@ void CSerialPort::process() #if defined(SERIAL_REPEATER) case MMDVM_SERIAL: { - for (uint8_t i = 3U; i < m_len; i++) - m_repeat.put(m_buffer[i]); - } + for (uint8_t i = 3U; i < m_len; i++) + m_repeat.put(m_buffer[i]); + } break; #endif @@ -663,23 +667,28 @@ void CSerialPort::process() } } + if (io.getWatchdog() >= 48000U) { + m_ptr = 0U; + m_len = 0U; + } + #if defined(SERIAL_REPEATER) - // Write any outgoing serial data - uint16_t space = m_repeat.getData(); - if (space > 0U) { - int avail = availableForWriteInt(3U); - if (avail < space) - space = avail; + // Write any outgoing serial data + uint16_t space = m_repeat.getData(); + if (space > 0U) { + int avail = availableForWriteInt(3U); + if (avail < space) + space = avail; - for (uint16_t i = 0U; i < space; i++) { - uint8_t c = m_repeat.get(); - writeInt(3U, &c, 1U); - } - } + for (uint16_t i = 0U; i < space; i++) { + uint8_t c = m_repeat.get(); + writeInt(3U, &c, 1U); + } + } - // Read any incoming serial data - while (availableInt(3U)) - readInt(3U); + // Read any incoming serial data + while (availableInt(3U)) + readInt(3U); #endif } From 7bb042a6cac0ee5bda7ffc1ab003c83fea9048e2 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 20 Aug 2017 15:52:52 +0100 Subject: [PATCH 11/17] Adding watchdog to the host serial port. --- IO.cpp | 5 +++++ IO.h | 1 + IOSTM.cpp | 2 +- SerialPort.cpp | 42 +++++++++++++++++++++++++----------------- SerialSTM.cpp | 8 ++++---- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/IO.cpp b/IO.cpp index ea69377..9df584c 100644 --- a/IO.cpp +++ b/IO.cpp @@ -336,6 +336,11 @@ void CIO::resetWatchdog() m_watchdog = 0U; } +uint32_t CIO::getWatchdog() +{ + return m_watchdog; +} + bool CIO::hasLockout() const { return m_lockout; diff --git a/IO.h b/IO.h index ba7bbfa..1dba4a4 100644 --- a/IO.h +++ b/IO.h @@ -52,6 +52,7 @@ public: bool hasLockout() const; void resetWatchdog(); + uint32_t getWatchdog(); private: bool m_started; diff --git a/IOSTM.cpp b/IOSTM.cpp index 56826bb..f02c347 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -355,7 +355,7 @@ void CIO::initInt() { GPIO_InitTypeDef GPIO_InitStruct; GPIO_StructInit(&GPIO_InitStruct); - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStruct.GPIO_Speed = GPIO_Fast_Speed; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; diff --git a/SerialPort.cpp b/SerialPort.cpp index 235257d..c012ab0 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -422,6 +422,9 @@ void CSerialPort::process() m_buffer[0U] = c; m_ptr = 1U; m_len = 0U; + } else { + m_ptr = 0U; + m_len = 0U; } } else if (m_ptr == 1U) { // Handle the frame length @@ -647,9 +650,9 @@ void CSerialPort::process() #if defined(SERIAL_REPEATER) case MMDVM_SERIAL: { - for (uint8_t i = 3U; i < m_len; i++) - m_repeat.put(m_buffer[i]); - } + for (uint8_t i = 3U; i < m_len; i++) + m_repeat.put(m_buffer[i]); + } break; #endif @@ -665,23 +668,28 @@ void CSerialPort::process() } } + if (io.getWatchdog() >= 48000U) { + m_ptr = 0U; + m_len = 0U; + } + #if defined(SERIAL_REPEATER) - // Write any outgoing serial data - uint16_t space = m_repeat.getData(); - if (space > 0U) { - int avail = availableForWriteInt(3U); - if (avail < space) - space = avail; + // Write any outgoing serial data + uint16_t space = m_repeat.getData(); + if (space > 0U) { + int avail = availableForWriteInt(3U); + if (avail < space) + space = avail; - for (uint16_t i = 0U; i < space; i++) { - uint8_t c = m_repeat.get(); - writeInt(3U, &c, 1U); - } - } + for (uint16_t i = 0U; i < space; i++) { + uint8_t c = m_repeat.get(); + writeInt(3U, &c, 1U); + } + } - // Read any incoming serial data - while (availableInt(3U)) - readInt(3U); + // Read any incoming serial data + while (availableInt(3U)) + readInt(3U); #endif } diff --git a/SerialSTM.cpp b/SerialSTM.cpp index e2b128e..263c034 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -184,7 +184,7 @@ void InitUSART1(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; // Tx | Rx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure USART baud rate @@ -375,7 +375,7 @@ void InitUSART2(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; // Tx | Rx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure USART baud rate @@ -566,7 +566,7 @@ void InitUSART3(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; // Tx | Rx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOC, &GPIO_InitStructure); // Configure USART baud rate @@ -758,7 +758,7 @@ void InitUART5(int speed) GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // Tx - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // Rx From a60059bc9073f402b00ceab033c014c2b8cd3c21 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Thu, 24 Aug 2017 22:24:27 -0300 Subject: [PATCH 12/17] Adding preliminary support for STM32F767 (Nucleo-144 F767ZI) --- Globals.h | 4 ++ IOSTM.cpp | 97 +++++++++++++++++++++++++- MMDVM.cpp | 2 +- Makefile.F7 | 173 ++++++++++++++++++++++++++++++++++++++++++++++ RSSIRB.h | 3 + SampleRB.h | 3 + SerialRB.h | 3 + SerialSTM.cpp | 43 ++++++++---- Utils.h | 3 + stm32f7xx_link.ld | 137 ++++++++++++++++++++++++++++++++++++ 10 files changed, 452 insertions(+), 16 deletions(-) create mode 100644 Makefile.F7 create mode 100644 stm32f7xx_link.ld diff --git a/Globals.h b/Globals.h index 7b80226..26599c4 100644 --- a/Globals.h +++ b/Globals.h @@ -21,6 +21,8 @@ #if defined(STM32F4XX) || defined(STM32F4) #include "stm32f4xx.h" +#elif defined(STM32F7XX) +#include "stm32f7xx.h" #elif defined(STM32F105xC) #include "stm32f1xx.h" #include "STM32Utils.h" @@ -30,6 +32,8 @@ #if defined(__SAM3X8E__) || defined(STM32F105xC) #define ARM_MATH_CM3 +#elif defined(STM32F7XX) +#define ARM_MATH_CM7 #elif defined(STM32F4XX) || defined(STM32F4) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #define ARM_MATH_CM4 #else diff --git a/IOSTM.cpp b/IOSTM.cpp index f02c347..be6f1ce 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -22,7 +22,7 @@ #include "Globals.h" #include "IO.h" -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F7XX) #if defined(STM32F4_DISCOVERY) /* @@ -333,8 +333,101 @@ EXT_CLK PB8 input CN5 Pin10 #error "Either STM32F4_NUCLEO_MORPHO_HEADER or STM32F4_NUCLEO_ARDUINO_HEADER need to be defined in Config.h" #endif +#elif defined(STM32F7_NUCLEO) +/* +Pin definitions for STM32F7 Nucleo boards (ST Morpho header): + +PTT PB13 output CN10 Pin30 +COSLED PB14 output CN10 Pin28 +LED PB0 output CN10 Pin11 +COS PB15 input CN10 Pin26 + +DSTAR PB10 output CN10 Pin25 +DMR PB4 output CN10 Pin27 +YSF PB5 output CN10 Pin29 +P25 PB3 output CN10 Pin + +MDSTAR PC4 output CN7 Pin34 +MDMR PC5 output CN7 Pin6 +MYSF PC2 output CN7 Pin35 +MP25 PC3 output CN7 Pin37 + +RX PA0 analog input CN7 Pin28 +RSSI PA1 analog input CN7 Pin30 +TX PA4 analog output CN7 Pin32 + +EXT_CLK PA15 input CN7 Pin18 +*/ + +#define PIN_COS GPIO_Pin_15 +#define PORT_COS GPIOB +#define RCC_Per_COS RCC_AHB1Periph_GPIOB + +#define PIN_PTT GPIO_Pin_13 +#define PORT_PTT GPIOB +#define RCC_Per_PTT RCC_AHB1Periph_GPIOB + +#define PIN_COSLED GPIO_Pin_14 +#define PORT_COSLED GPIOB +#define RCC_Per_COSLED RCC_AHB1Periph_GPIOB + +#define PIN_LED GPIO_Pin_0 +#define PORT_LED GPIOB +#define RCC_Per_LED RCC_AHB1Periph_GPIOB + +#define PIN_P25 GPIO_Pin_3 +#define PORT_P25 GPIOB +#define RCC_Per_P25 RCC_AHB1Periph_GPIOB + +#define PIN_DSTAR GPIO_Pin_10 +#define PORT_DSTAR GPIOB +#define RCC_Per_DSTAR RCC_AHB1Periph_GPIOB + +#define PIN_DMR GPIO_Pin_4 +#define PORT_DMR GPIOB +#define RCC_Per_DMR RCC_AHB1Periph_GPIOB + +#define PIN_YSF GPIO_Pin_5 +#define PORT_YSF GPIOB +#define RCC_Per_YSF RCC_AHB1Periph_GPIOB + +#if defined(STM32F4_NUCLEO_MODE_PINS) +#define PIN_MP25 GPIO_Pin_3 +#define PORT_MP25 GPIOC +#define RCC_Per_MP25 RCC_AHB1Periph_GPIOC + +#define PIN_MDSTAR GPIO_Pin_4 +#define PORT_MDSTAR GPIOC +#define RCC_Per_MDSTAR RCC_AHB1Periph_GPIOC + +#define PIN_MDMR GPIO_Pin_5 +#define PORT_MDMR GPIOC +#define RCC_Per_MDMR RCC_AHB1Periph_GPIOC + +#define PIN_MYSF GPIO_Pin_2 +#define PORT_MYSF GPIOC +#define RCC_Per_MYSF RCC_AHB1Periph_GPIOC +#endif + +#define PIN_EXT_CLK GPIO_Pin_15 +#define SRC_EXT_CLK GPIO_PinSource15 +#define PORT_EXT_CLK GPIOA + +#define PIN_RX GPIO_Pin_0 +#define PIN_RX_CH ADC_Channel_0 +#define PORT_RX GPIOA +#define RCC_Per_RX RCC_AHB1Periph_GPIOA + +#define PIN_RSSI GPIO_Pin_1 +#define PIN_RSSI_CH ADC_Channel_1 +#define PORT_RSSI GPIOA +#define RCC_Per_RSSI RCC_AHB1Periph_GPIOA + +#define PIN_TX GPIO_Pin_4 +#define PIN_TX_CH DAC_Channel_1 + #else -#error "Either STM32F4_DISCOVERY, STM32F4_PI or STM32F4_NUCLEO need to be defined" +#error "Either STM32F4_DISCOVERY, STM32F4_PI, STM32F4_NUCLEO or STM32F7_NUCLEO need to be defined" #endif const uint16_t DC_OFFSET = 2048U; diff --git a/MMDVM.cpp b/MMDVM.cpp index 6e2be23..cbeeef5 100644 --- a/MMDVM.cpp +++ b/MMDVM.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F105xC) +#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F7XX) || defined(STM32F105xC) #include "Config.h" #include "Globals.h" diff --git a/Makefile.F7 b/Makefile.F7 new file mode 100644 index 0000000..956e2b2 --- /dev/null +++ b/Makefile.F7 @@ -0,0 +1,173 @@ +# Copyright (C) 2016,2017 by Andy Uribe CA6JAU +# Copyright (C) 2016 by Jim McLaughlin KI6ZUM + +# 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 +# (at your option) any later version. + +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# GNU ARM Embedded Toolchain +CC=arm-none-eabi-gcc +CXX=arm-none-eabi-g++ +LD=arm-none-eabi-ld +AR=arm-none-eabi-ar +AS=arm-none-eabi-as +CP=arm-none-eabi-objcopy +OD=arm-none-eabi-objdump +NM=arm-none-eabi-nm +SIZE=arm-none-eabi-size +A2L=arm-none-eabi-addr2line + +# Directory Structure +BINDIR=bin + +# Find source files +# "SystemRoot" is only defined in Windows +ifdef SYSTEMROOT + ASOURCES=$(shell dir /S /B *.s) + CSOURCES=$(shell dir /S /B *.c) + CXXSOURCES=$(shell dir /S /B *.cpp) + CLEANCMD=del /S *.o *.hex *.bin *.elf GitVersion.h + MDBIN=md $@ +else ifdef SystemRoot + ASOURCES=$(shell dir /S /B *.s) + CSOURCES=$(shell dir /S /B *.c) + CXXSOURCES=$(shell dir /S /B *.cpp) + CLEANCMD=del /S *.o *.hex *.bin *.elf GitVersion.h + MDBIN=md $@ +else + ASOURCES=$(shell find . -name '*.s') + CSOURCES=$(shell find . -name '*.c') + CXXSOURCES=$(shell find . -name '*.cpp') + CLEANCMD=rm -f $(OBJECTS) $(BINDIR)/$(BINELF) $(BINDIR)/$(BINHEX) $(BINDIR)/$(BINBIN) GitVersion.h + MDBIN=mkdir $@ +endif + +# Default reference oscillator frequencies +ifndef $(OSC) + ifeq ($(MAKECMDGOALS),pi) + OSC=12000000 + else + OSC=8000000 + endif +endif + +# Find header directories +INC= . STM32F7XX_Lib/CMSIS/Include/ STM32F7XX_Lib/Device/ STM32F7XX_Lib/STM32F7xx_StdPeriph_Driver/inc/ +INCLUDES=$(INC:%=-I%) + +# Find libraries +INCLUDES_LIBS=STM32F7XX_Lib/CMSIS/Lib/GCC/libarm_cortexM7lfsp_math.a +LINK_LIBS= + +# Create object list +OBJECTS=$(ASOURCES:%.s=%.o) +OBJECTS+=$(CSOURCES:%.c=%.o) +OBJECTS+=$(CXXSOURCES:%.cpp=%.o) + +# Define output files ELF & IHEX +BINELF=outp.elf +BINHEX=outp.hex +BINBIN=outp.bin + +# MCU FLAGS +MCFLAGS=-mcpu=cortex-m7 -mthumb -mlittle-endian -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb-interwork + +# COMPILE FLAGS +# STM32F7 Nucleo-144-F767ZI board: +DEFS_NUCLEO=-DUSE_HAL_DRIVER -DSTM32F767xx -DSTM32F7XX -DSTM32F7_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE + +CFLAGS=-c $(MCFLAGS) $(INCLUDES) +CXXFLAGS=-c $(MCFLAGS) $(INCLUDES) + +# LINKER FLAGS +LDSCRIPT=stm32f7xx_link.ld +LDFLAGS =-T $(LDSCRIPT) $(MCFLAGS) --specs=nosys.specs $(INCLUDES_LIBS) $(LINK_LIBS) + +# Build Rules +.PHONY: all release nucleo debug clean + +# Default target: STM32F7 Nucleo-144-F767ZI board +all: nucleo + +nucleo: GitVersion.h +nucleo: CFLAGS+=$(DEFS_NUCLEO) -Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS +nucleo: CXXFLAGS+=$(DEFS_NUCLEO) -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS +nucleo: LDFLAGS+=-Os --specs=nano.specs +nucleo: release + +debug: CFLAGS+=-g +debug: CXXFLAGS+=-g +debug: LDFLAGS+=-g +debug: release + +release: $(BINDIR) +release: $(BINDIR)/$(BINHEX) +release: $(BINDIR)/$(BINBIN) + +$(BINDIR): + $(MDBIN) + +$(BINDIR)/$(BINHEX): $(BINDIR)/$(BINELF) + $(CP) -O ihex $< $@ + @echo "Objcopy from ELF to IHEX complete!\n" + +$(BINDIR)/$(BINBIN): $(BINDIR)/$(BINELF) + $(CP) -O binary $< $@ + @echo "Objcopy from ELF to BINARY complete!\n" + +$(BINDIR)/$(BINELF): $(OBJECTS) + $(CXX) $(OBJECTS) $(LDFLAGS) -o $@ + @echo "Linking complete!\n" + $(SIZE) $(BINDIR)/$(BINELF) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) $< -o $@ + @echo "Compiled "$<"!\n" + +%.o: %.c + $(CC) $(CFLAGS) $< -o $@ + @echo "Compiled "$<"!\n" + +%.o: %.s + $(CC) $(CFLAGS) $< -o $@ + @echo "Assambled "$<"!\n" + +clean: + $(CLEANCMD) + +deploy: +ifneq ($(wildcard /usr/bin/openocd),) + /usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" +endif + +ifneq ($(wildcard /usr/local/bin/openocd),) + /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" +endif + +ifneq ($(wildcard /opt/openocd/bin/openocd),) + /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" +endif + +# Export the current git version if the index file exists, else 000... +GitVersion.h: +ifdef SYSTEMROOT + echo #define GITVERSION "0000000" > $@ +else ifdef SystemRoot + echo #define GITVERSION "0000000" > $@ +else +ifneq ("$(wildcard .git/index)","") + echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@ +else + echo "#define GITVERSION \"0000000\"" > $@ +endif +endif diff --git a/RSSIRB.h b/RSSIRB.h index 637090e..6c751bf 100644 --- a/RSSIRB.h +++ b/RSSIRB.h @@ -24,6 +24,9 @@ Boston, MA 02110-1301, USA. #if defined(STM32F4XX) || defined(STM32F4) #include "stm32f4xx.h" #include +#elif defined(STM32F7XX) +#include "stm32f7xx.h" +#include #elif defined(STM32F105xC) #include "stm32f1xx.h" #include diff --git a/SampleRB.h b/SampleRB.h index 07ebf61..35522b3 100644 --- a/SampleRB.h +++ b/SampleRB.h @@ -24,6 +24,9 @@ Boston, MA 02110-1301, USA. #if defined(STM32F4XX) || defined(STM32F4) #include "stm32f4xx.h" #include +#elif defined(STM32F7XX) +#include "stm32f7xx.h" +#include #elif defined(STM32F105xC) #include "stm32f1xx.h" #include diff --git a/SerialRB.h b/SerialRB.h index 64cee44..f669cbc 100644 --- a/SerialRB.h +++ b/SerialRB.h @@ -24,6 +24,9 @@ Boston, MA 02110-1301, USA. #if defined(STM32F4XX) || defined(STM32F4) #include "stm32f4xx.h" #include +#elif defined(STM32F7XX) +#include "stm32f7xx.h" +#include #elif defined(STM32F105xC) #include "stm32f1xx.h" #include diff --git a/SerialSTM.cpp b/SerialSTM.cpp index 263c034..f813dd7 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -37,7 +37,7 @@ UART5 - TXD PC12 - RXD PD2 (Discovery, Pi and Nucleo with Morpho header) */ -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F7XX) #define TX_SERIAL_FIFO_SIZE 512U #define RX_SERIAL_FIFO_SIZE 512U @@ -432,7 +432,7 @@ void WriteUSART2(const uint8_t* data, uint16_t length) #endif /* ************* USART3 ***************** */ -#if defined(STM32F4_DISCOVERY) || defined(STM32F4_PI) +#if defined(STM32F4_DISCOVERY) || defined(STM32F4_PI) || defined(STM32F7_NUCLEO) volatile uint8_t TXSerialfifo3[TX_SERIAL_FIFO_SIZE]; volatile uint8_t RXSerialfifo3[RX_SERIAL_FIFO_SIZE]; @@ -541,17 +541,34 @@ void USART3_IRQHandler() } } +#if defined(STM32F7_NUCLEO) +// USART3 - TXD PD8 - RXD PD9 +#define USART3_GPIO_PinSource_TX GPIO_PinSource8 +#define USART3_GPIO_PinSource_RX GPIO_PinSource9 +#define USART3_GPIO_Pin_TX GPIO_Pin_8 +#define USART3_GPIO_Pin_RX GPIO_Pin_9 +#define USART3_GPIO_PORT GPIOD +#define USART3_RCC_Periph RCC_AHB1Periph_GPIOD +#else +// USART3 - TXD PC10 - RXD PC11 +#define USART3_GPIO_PinSource_TX GPIO_PinSource10 +#define USART3_GPIO_PinSource_RX GPIO_PinSource11 +#define USART3_GPIO_Pin_TX GPIO_Pin_10 +#define USART3_GPIO_Pin_RX GPIO_Pin_11 +#define USART3_GPIO_PORT GPIOC +#define USART3_RCC_Periph RCC_AHB1Periph_GPIOC +#endif + void InitUSART3(int speed) { - // USART3 - TXD PC10 - RXD PC11 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); + RCC_AHB1PeriphClockCmd(USART3_RCC_Periph, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); - GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3); - GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3); + GPIO_PinAFConfig(USART3_GPIO_PORT, USART3_GPIO_PinSource_TX, GPIO_AF_USART3); + GPIO_PinAFConfig(USART3_GPIO_PORT, USART3_GPIO_PinSource_RX, GPIO_AF_USART3); // USART IRQ init NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; @@ -565,9 +582,9 @@ void InitUSART3(int speed) GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; // Tx | Rx + GPIO_InitStructure.GPIO_Pin = USART3_GPIO_Pin_TX | USART3_GPIO_Pin_RX; // Tx | Rx GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed; - GPIO_Init(GPIOC, &GPIO_InitStructure); + GPIO_Init(USART3_GPIO_PORT, &GPIO_InitStructure); // Configure USART baud rate USART_StructInit(&USART_InitStructure); @@ -822,7 +839,7 @@ void CSerialPort::beginInt(uint8_t n, int speed) { switch (n) { case 1U: - #if defined(STM32F4_DISCOVERY) + #if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO) InitUSART3(speed); #elif defined(STM32F4_PI) InitUSART1(speed); @@ -846,7 +863,7 @@ int CSerialPort::availableInt(uint8_t n) { switch (n) { case 1U: - #if defined(STM32F4_DISCOVERY) + #if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO) return AvailUSART3(); #elif defined(STM32F4_PI) return AvailUSART1(); @@ -868,7 +885,7 @@ int CSerialPort::availableForWriteInt(uint8_t n) { switch (n) { case 1U: - #if defined(STM32F4_DISCOVERY) + #if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO) return AvailForWriteUSART3(); #elif defined(STM32F4_PI) return AvailForWriteUSART1(); @@ -890,7 +907,7 @@ uint8_t CSerialPort::readInt(uint8_t n) { switch (n) { case 1U: - #if defined(STM32F4_DISCOVERY) + #if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO) return ReadUSART3(); #elif defined(STM32F4_PI) return ReadUSART1(); @@ -912,7 +929,7 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool { switch (n) { case 1U: - #if defined(STM32F4_DISCOVERY) + #if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO) WriteUSART3(data, length); if (flush) TXSerialFlush3(); diff --git a/Utils.h b/Utils.h index 5297e93..5d8c76e 100644 --- a/Utils.h +++ b/Utils.h @@ -22,6 +22,9 @@ #if defined(STM32F4XX) || defined(STM32F4) #include "stm32f4xx.h" #include +#elif defined(STM32F7XX) +#include "stm32f7xx.h" +#include #elif defined(STM32F105xC) #include "stm32f1xx.h" #include diff --git a/stm32f7xx_link.ld b/stm32f7xx_link.ld new file mode 100644 index 0000000..3f82067 --- /dev/null +++ b/stm32f7xx_link.ld @@ -0,0 +1,137 @@ +/* + * Copyright (C) 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Required amount of heap and stack */ +_min_heap_size = 0x1000; +_min_stack_size = 0x0800; + +/* The entry point in the interrupt vector table */ +ENTRY(Reset_Handler) + +/* Memory areas */ +MEMORY +{ + ROM (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* FLASH */ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K /* Main RAM */ +} + +/* Stack start address (end of 512K RAM) */ +_estack = ORIGIN(RAM) + LENGTH(RAM); + +SECTIONS +{ + .text : + { + /* The interrupt vector table */ + . = ALIGN(4); + KEEP(*(.isr_vector .isr_vector.*)) + + /* The program code */ + . = ALIGN(4); + *(.text .text*) + *(.rodata .rodata*) + + /* ARM-Thumb code */ + *(.glue_7) *(.glue_7t) + + . = ALIGN(4); + KEEP(*(.init)) + KEEP(*(.fini)) + + /* EABI C++ global constructors support */ + . = ALIGN(4); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; + + /* EABI C++ global constructors support */ + . = ALIGN(4); + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; + + /* EABI C++ global constructors support */ + . = ALIGN(4); + __fini_array_start = .; + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + __fini_array_end = .; + + } > ROM + + /* ARM sections containing exception unwinding information */ + .ARM.extab : { + __extab_start = .; + *(.ARM.extab* .gnu.linkonce.armextab.*) + __extab_end = .; + } > ROM + + /* ARM index entries for section unwinding */ + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > ROM + + /* Start address for the initialization values of the .data section */ + _sidata = .; + + /* The .data section (initialized data) */ + .data : AT ( _sidata ) + { + . = ALIGN(4); + _sdata = . ; /* Start address for the .data section */ + *(.data .data*) + + . = ALIGN(4); + _edata = . ; /* End address for the .data section */ + } > RAM + + /* The .bss section (uninitialized data) */ + .bss : + { + . = ALIGN(4); + _sbss = .; /* Start address for the .bss section */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = . ; /* End address for the .bss section */ + __bss_end__ = _ebss; + } > RAM + + /* Space for heap and stack */ + .heap_stack : + { + end = . ; /* 'end' symbol defines heap location */ + _end = end ; + . = . + _min_heap_size; /* Additional space for heap and stack */ + . = . + _min_stack_size; + } > RAM + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } +} From 1f5a4f1ad7a7f48871e58be97b31ac1cbfc24ea5 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sun, 27 Aug 2017 15:20:46 -0300 Subject: [PATCH 13/17] =?UTF-8?q?Removing=20unnecessary=20=E2=80=9Cdefined?= =?UTF-8?q?(STM32F4)=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Globals.h | 4 ++-- IOSTM.cpp | 2 +- MMDVM.cpp | 2 +- RSSIRB.h | 2 +- SampleRB.h | 2 +- SerialRB.h | 2 +- SerialSTM.cpp | 2 +- Utils.h | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Globals.h b/Globals.h index 26599c4..02c0502 100644 --- a/Globals.h +++ b/Globals.h @@ -19,7 +19,7 @@ #if !defined(GLOBALS_H) #define GLOBALS_H -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) #include "stm32f4xx.h" #elif defined(STM32F7XX) #include "stm32f7xx.h" @@ -34,7 +34,7 @@ #define ARM_MATH_CM3 #elif defined(STM32F7XX) #define ARM_MATH_CM7 -#elif defined(STM32F4XX) || defined(STM32F4) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) +#elif defined(STM32F4XX) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #define ARM_MATH_CM4 #else #error "Unknown processor type" diff --git a/IOSTM.cpp b/IOSTM.cpp index be6f1ce..3abf820 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -22,7 +22,7 @@ #include "Globals.h" #include "IO.h" -#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F7XX) +#if defined(STM32F4XX) || defined(STM32F7XX) #if defined(STM32F4_DISCOVERY) /* diff --git a/MMDVM.cpp b/MMDVM.cpp index cbeeef5..12673e4 100644 --- a/MMDVM.cpp +++ b/MMDVM.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F7XX) || defined(STM32F105xC) +#if defined(STM32F4XX) || defined(STM32F7XX) || defined(STM32F105xC) #include "Config.h" #include "Globals.h" diff --git a/RSSIRB.h b/RSSIRB.h index 6c751bf..0f855a3 100644 --- a/RSSIRB.h +++ b/RSSIRB.h @@ -21,7 +21,7 @@ Boston, MA 02110-1301, USA. #if !defined(RSSIRB_H) #define RSSIRB_H -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) #include "stm32f4xx.h" #include #elif defined(STM32F7XX) diff --git a/SampleRB.h b/SampleRB.h index 35522b3..305bf8b 100644 --- a/SampleRB.h +++ b/SampleRB.h @@ -21,7 +21,7 @@ Boston, MA 02110-1301, USA. #if !defined(SAMPLERB_H) #define SAMPLERB_H -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) #include "stm32f4xx.h" #include #elif defined(STM32F7XX) diff --git a/SerialRB.h b/SerialRB.h index f669cbc..91ebcc1 100644 --- a/SerialRB.h +++ b/SerialRB.h @@ -21,7 +21,7 @@ Boston, MA 02110-1301, USA. #if !defined(SERIALRB_H) #define SERIALRB_H -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) #include "stm32f4xx.h" #include #elif defined(STM32F7XX) diff --git a/SerialSTM.cpp b/SerialSTM.cpp index f813dd7..e0aa6c3 100644 --- a/SerialSTM.cpp +++ b/SerialSTM.cpp @@ -37,7 +37,7 @@ UART5 - TXD PC12 - RXD PD2 (Discovery, Pi and Nucleo with Morpho header) */ -#if defined(STM32F4XX) || defined(STM32F4) || defined(STM32F7XX) +#if defined(STM32F4XX) || defined(STM32F7XX) #define TX_SERIAL_FIFO_SIZE 512U #define RX_SERIAL_FIFO_SIZE 512U diff --git a/Utils.h b/Utils.h index 5d8c76e..7656b23 100644 --- a/Utils.h +++ b/Utils.h @@ -19,7 +19,7 @@ #if !defined(UTILS_H) #define UTILS_H -#if defined(STM32F4XX) || defined(STM32F4) +#if defined(STM32F4XX) #include "stm32f4xx.h" #include #elif defined(STM32F7XX) From cce2cc3cfc1d308b4f4507d9fcf50d4d72c55846 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sun, 27 Aug 2017 16:28:08 -0300 Subject: [PATCH 14/17] Including F767 target into the Makefile --- Makefile | 87 ++++++++++++++++---------- Makefile.F7 | 173 ---------------------------------------------------- 2 files changed, 56 insertions(+), 204 deletions(-) delete mode 100644 Makefile.F7 diff --git a/Makefile b/Makefile index 2358e67..acef4e1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 2016 by Andy Uribe CA6JAU +# Copyright (C) 2016,2017 by Andy Uribe CA6JAU # Copyright (C) 2016 by Jim McLaughlin KI6ZUM # This program is free software; you can redistribute it and/or modify @@ -62,12 +62,14 @@ ifndef $(OSC) endif # Find header directories -INC= . STM32F4XX_Lib/CMSIS/Include/ STM32F4XX_Lib/Device/ STM32F4XX_Lib/STM32F4xx_StdPeriph_Driver/include/ -INCLUDES=$(INC:%=-I%) +INC_F4= . STM32F4XX_Lib/CMSIS/Include/ STM32F4XX_Lib/Device/ STM32F4XX_Lib/STM32F4xx_StdPeriph_Driver/include/ +INCLUDES_F4=$(INC_F4:%=-I%) +INC_F7= . STM32F7XX_Lib/CMSIS/Include/ STM32F7XX_Lib/Device/ STM32F7XX_Lib/STM32F7xx_StdPeriph_Driver/inc/ +INCLUDES_F7=$(INC_F7:%=-I%) # Find libraries -INCLUDES_LIBS=STM32F4XX_Lib/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a -LINK_LIBS= +INCLUDES_LIBS_F4=STM32F4XX_Lib/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a +INCLUDES_LIBS_F7=STM32F7XX_Lib/CMSIS/Lib/GCC/libarm_cortexM7lfsp_math.a # Create object list OBJECTS=$(ASOURCES:%.s=%.o) @@ -80,52 +82,62 @@ BINHEX=outp.hex BINBIN=outp.bin # MCU FLAGS -MCFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian \ --mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb-interwork +MCFLAGS_F4=-mcpu=cortex-m4 -mthumb -mlittle-endian -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb-interwork +MCFLAGS_F7=-mcpu=cortex-m7 -mthumb -mlittle-endian -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb-interwork # COMPILE FLAGS # STM32F4 Discovery board: DEFS_DIS=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F40_41xxx -DSTM32F4_DISCOVERY -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE -# Pi board: -DEFS_PI=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_PI -DARDUINO_MODE_PINS -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE -# STM32F4 Nucleo 446 board: +# MMDVM-Pi board: +DEFS_PI=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_PI -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE +# STM32F4 Nucleo-64 F446RE board: DEFS_NUCLEO=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE +# STM32F7 Nucleo-144-F767ZI board: +DEFS_NUCLEO_F767=-DUSE_HAL_DRIVER -DSTM32F767xx -DSTM32F7XX -DSTM32F7_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE -CFLAGS=-c $(MCFLAGS) $(INCLUDES) -CXXFLAGS=-c $(MCFLAGS) $(INCLUDES) +CFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4) +CXXFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4) +CFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7) +CXXFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7) # LINKER FLAGS -LDSCRIPT=stm32f4xx_link.ld -LDFLAGS =-T $(LDSCRIPT) $(MCFLAGS) --specs=nosys.specs $(INCLUDES_LIBS) $(LINK_LIBS) +LDFLAGS_F4 =-T stm32f4xx_link.ld $(MCFLAGS_F4) --specs=nosys.specs $(INCLUDES_LIBS_F4) +LDFLAGS_F7 =-T stm32f7xx_link.ld $(MCFLAGS_F7) --specs=nosys.specs $(INCLUDES_LIBS_F7) + +# COMMON FLAGS +CFLAGS=-Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS +CXXFLAGS=-Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS +LDFLAGS=-Os --specs=nano.specs # Build Rules -.PHONY: all release dis pi nucleo debug clean +.PHONY: all release dis pi nucleo clean # Default target: STM32F4 Nucleo F446RE board all: nucleo pi: GitVersion.h -pi: CFLAGS+=$(DEFS_PI) -Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS -pi: CXXFLAGS+=$(DEFS_PI) -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS -pi: LDFLAGS+=-Os --specs=nano.specs +pi: CFLAGS+=$(CFLAGS_F4) $(DEFS_PI) +pi: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_PI) +pi: LDFLAGS+=$(LDFLAGS_F4) pi: release nucleo: GitVersion.h -nucleo: CFLAGS+=$(DEFS_NUCLEO) -Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS -nucleo: CXXFLAGS+=$(DEFS_NUCLEO) -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS -nucleo: LDFLAGS+=-Os --specs=nano.specs +nucleo: CFLAGS+=$(CFLAGS_F4) $(DEFS_NUCLEO) +nucleo: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_NUCLEO) +nucleo: LDFLAGS+=$(LDFLAGS_F4) nucleo: release dis: GitVersion.h -dis: CFLAGS+=$(DEFS_DIS) -Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS -dis: CXXFLAGS+=$(DEFS_DIS) -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS -dis: LDFLAGS+=-Os --specs=nano.specs +dis: CFLAGS+=$(CFLAGS_F4) $(DEFS_DIS) +dis: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_DIS) +dis: LDFLAGS+=$(LDFLAGS_F4) dis: release -debug: CFLAGS+=-g -debug: CXXFLAGS+=-g -debug: LDFLAGS+=-g -debug: release +f767: GitVersion.h +f767: CFLAGS+=$(CFLAGS_F7) $(DEFS_NUCLEO_F767) +f767: CXXFLAGS+=$(CXXFLAGS_F7) $(DEFS_NUCLEO_F767) +f767: LDFLAGS+=$(LDFLAGS_F7) +f767: release release: $(BINDIR) release: $(BINDIR)/$(BINHEX) @@ -164,15 +176,28 @@ clean: deploy: ifneq ($(wildcard /usr/bin/openocd),) - /usr/bin/openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg -c "program bin/$(BINELF) verify reset exit" + /usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f4x.cfg -c "program bin/$(BINELF) verify reset exit" endif ifneq ($(wildcard /usr/local/bin/openocd),) - /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/board/stm32f4discovery.cfg -c "program bin/$(BINELF) verify reset exit" + /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f4x.cfg -c "program bin/$(BINELF) verify reset exit" endif ifneq ($(wildcard /opt/openocd/bin/openocd),) - /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/board/stm32f4discovery.cfg -c "program bin/$(BINELF) verify reset exit" + /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f4x.cfg -c "program bin/$(BINELF) verify reset exit" +endif + +deploy-f7: +ifneq ($(wildcard /usr/bin/openocd),) + /usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" +endif + +ifneq ($(wildcard /usr/local/bin/openocd),) + /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" +endif + +ifneq ($(wildcard /opt/openocd/bin/openocd),) + /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" endif deploy-pi: diff --git a/Makefile.F7 b/Makefile.F7 deleted file mode 100644 index 956e2b2..0000000 --- a/Makefile.F7 +++ /dev/null @@ -1,173 +0,0 @@ -# Copyright (C) 2016,2017 by Andy Uribe CA6JAU -# Copyright (C) 2016 by Jim McLaughlin KI6ZUM - -# 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 -# (at your option) any later version. - -# This program 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 this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -# GNU ARM Embedded Toolchain -CC=arm-none-eabi-gcc -CXX=arm-none-eabi-g++ -LD=arm-none-eabi-ld -AR=arm-none-eabi-ar -AS=arm-none-eabi-as -CP=arm-none-eabi-objcopy -OD=arm-none-eabi-objdump -NM=arm-none-eabi-nm -SIZE=arm-none-eabi-size -A2L=arm-none-eabi-addr2line - -# Directory Structure -BINDIR=bin - -# Find source files -# "SystemRoot" is only defined in Windows -ifdef SYSTEMROOT - ASOURCES=$(shell dir /S /B *.s) - CSOURCES=$(shell dir /S /B *.c) - CXXSOURCES=$(shell dir /S /B *.cpp) - CLEANCMD=del /S *.o *.hex *.bin *.elf GitVersion.h - MDBIN=md $@ -else ifdef SystemRoot - ASOURCES=$(shell dir /S /B *.s) - CSOURCES=$(shell dir /S /B *.c) - CXXSOURCES=$(shell dir /S /B *.cpp) - CLEANCMD=del /S *.o *.hex *.bin *.elf GitVersion.h - MDBIN=md $@ -else - ASOURCES=$(shell find . -name '*.s') - CSOURCES=$(shell find . -name '*.c') - CXXSOURCES=$(shell find . -name '*.cpp') - CLEANCMD=rm -f $(OBJECTS) $(BINDIR)/$(BINELF) $(BINDIR)/$(BINHEX) $(BINDIR)/$(BINBIN) GitVersion.h - MDBIN=mkdir $@ -endif - -# Default reference oscillator frequencies -ifndef $(OSC) - ifeq ($(MAKECMDGOALS),pi) - OSC=12000000 - else - OSC=8000000 - endif -endif - -# Find header directories -INC= . STM32F7XX_Lib/CMSIS/Include/ STM32F7XX_Lib/Device/ STM32F7XX_Lib/STM32F7xx_StdPeriph_Driver/inc/ -INCLUDES=$(INC:%=-I%) - -# Find libraries -INCLUDES_LIBS=STM32F7XX_Lib/CMSIS/Lib/GCC/libarm_cortexM7lfsp_math.a -LINK_LIBS= - -# Create object list -OBJECTS=$(ASOURCES:%.s=%.o) -OBJECTS+=$(CSOURCES:%.c=%.o) -OBJECTS+=$(CXXSOURCES:%.cpp=%.o) - -# Define output files ELF & IHEX -BINELF=outp.elf -BINHEX=outp.hex -BINBIN=outp.bin - -# MCU FLAGS -MCFLAGS=-mcpu=cortex-m7 -mthumb -mlittle-endian -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb-interwork - -# COMPILE FLAGS -# STM32F7 Nucleo-144-F767ZI board: -DEFS_NUCLEO=-DUSE_HAL_DRIVER -DSTM32F767xx -DSTM32F7XX -DSTM32F7_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE - -CFLAGS=-c $(MCFLAGS) $(INCLUDES) -CXXFLAGS=-c $(MCFLAGS) $(INCLUDES) - -# LINKER FLAGS -LDSCRIPT=stm32f7xx_link.ld -LDFLAGS =-T $(LDSCRIPT) $(MCFLAGS) --specs=nosys.specs $(INCLUDES_LIBS) $(LINK_LIBS) - -# Build Rules -.PHONY: all release nucleo debug clean - -# Default target: STM32F7 Nucleo-144-F767ZI board -all: nucleo - -nucleo: GitVersion.h -nucleo: CFLAGS+=$(DEFS_NUCLEO) -Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS -nucleo: CXXFLAGS+=$(DEFS_NUCLEO) -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS -nucleo: LDFLAGS+=-Os --specs=nano.specs -nucleo: release - -debug: CFLAGS+=-g -debug: CXXFLAGS+=-g -debug: LDFLAGS+=-g -debug: release - -release: $(BINDIR) -release: $(BINDIR)/$(BINHEX) -release: $(BINDIR)/$(BINBIN) - -$(BINDIR): - $(MDBIN) - -$(BINDIR)/$(BINHEX): $(BINDIR)/$(BINELF) - $(CP) -O ihex $< $@ - @echo "Objcopy from ELF to IHEX complete!\n" - -$(BINDIR)/$(BINBIN): $(BINDIR)/$(BINELF) - $(CP) -O binary $< $@ - @echo "Objcopy from ELF to BINARY complete!\n" - -$(BINDIR)/$(BINELF): $(OBJECTS) - $(CXX) $(OBJECTS) $(LDFLAGS) -o $@ - @echo "Linking complete!\n" - $(SIZE) $(BINDIR)/$(BINELF) - -%.o: %.cpp - $(CXX) $(CXXFLAGS) $< -o $@ - @echo "Compiled "$<"!\n" - -%.o: %.c - $(CC) $(CFLAGS) $< -o $@ - @echo "Compiled "$<"!\n" - -%.o: %.s - $(CC) $(CFLAGS) $< -o $@ - @echo "Assambled "$<"!\n" - -clean: - $(CLEANCMD) - -deploy: -ifneq ($(wildcard /usr/bin/openocd),) - /usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" -endif - -ifneq ($(wildcard /usr/local/bin/openocd),) - /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" -endif - -ifneq ($(wildcard /opt/openocd/bin/openocd),) - /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF) verify reset exit" -endif - -# Export the current git version if the index file exists, else 000... -GitVersion.h: -ifdef SYSTEMROOT - echo #define GITVERSION "0000000" > $@ -else ifdef SystemRoot - echo #define GITVERSION "0000000" > $@ -else -ifneq ("$(wildcard .git/index)","") - echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@ -else - echo "#define GITVERSION \"0000000\"" > $@ -endif -endif From ebd86df3ef9243a2aa35c8dd56bbb71f47c82d7c Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Mon, 28 Aug 2017 21:25:40 -0300 Subject: [PATCH 15/17] Fix Config.h --- Config.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Config.h b/Config.h index 2a9f009..b201991 100644 --- a/Config.h +++ b/Config.h @@ -27,7 +27,7 @@ // Frequencies such as 10.0 Mhz (48000 * 208.333) or 20 Mhz (48000 * 416.666) are not suitable. // // For 12 MHz -// #define EXTERNAL_OSC 12000000 +#define EXTERNAL_OSC 12000000 // For 12.288 MHz // #define EXTERNAL_OSC 12288000 // For 14.4 MHz @@ -39,7 +39,7 @@ // #define USE_COS_AS_LOCKOUT // Use pins to output the current mode -#define ARDUINO_MODE_PINS +// #define ARDUINO_MODE_PINS // For the original Arduino Due pin layout // #define ARDUINO_DUE_PAPA @@ -54,16 +54,16 @@ // #define ARDUINO_DUE_NTH // For ST Nucleo-64 STM32F446RE board -#define STM32F4_NUCLEO_MORPHO_HEADER +// #define STM32F4_NUCLEO_MORPHO_HEADER // #define STM32F4_NUCLEO_ARDUINO_HEADER // Use separate mode pins to switch external filters/bandwidth for example // #define STM32F4_NUCLEO_MODE_PINS // Pass RSSI information to the host -#define SEND_RSSI_DATA +// #define SEND_RSSI_DATA // Use the modem as a serial repeater for Nextion displays -#define SERIAL_REPEATER +// #define SERIAL_REPEATER #endif From 7fae32042fb9630711bdc438a3f9229a3abc8e3b Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Mon, 28 Aug 2017 23:07:30 -0300 Subject: [PATCH 16/17] Fix typo --- SerialPort.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SerialPort.cpp b/SerialPort.cpp index 623aa75..b707c36 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -426,10 +426,6 @@ void CSerialPort::process() m_ptr = 0U; m_len = 0U; } - else { - m_ptr = 0U; - m_len = 0U; - } } else if (m_ptr == 1U) { // Handle the frame length m_len = m_buffer[m_ptr] = c; @@ -682,7 +678,6 @@ void CSerialPort::process() uint16_t space = m_repeat.getData(); if (space > 0U) { int avail = availableForWriteInt(3U); - if (avail < space) space = avail; From 7e85a64a41703d5cc0c92925444f17a71683455f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 29 Aug 2017 08:37:48 +0100 Subject: [PATCH 17/17] Remove compiler warning. --- YSFRX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YSFRX.h b/YSFRX.h index 556280a..f8abfc2 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -43,9 +43,9 @@ private: uint16_t m_dataPtr; uint16_t m_startPtr; uint16_t m_endPtr; + uint16_t m_syncPtr; uint16_t m_minSyncPtr; uint16_t m_maxSyncPtr; - uint16_t m_syncPtr; q31_t m_maxCorr; uint16_t m_lostCount; uint8_t m_countdown;