Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding NOX Softserial port #5334

Closed
tonyyng opened this issue Jan 18, 2020 · 8 comments
Closed

Adding NOX Softserial port #5334

tonyyng opened this issue Jan 18, 2020 · 8 comments
Labels

Comments

@tonyyng
Copy link
Contributor

tonyyng commented Jan 18, 2020

I'm trying to add a SoftSerial port to the NOX target to allow SmartAudio VTX control using the LED pad.

I'm a software developer, but don't have experience with this type of hardware. I hope this is the appropriate place to ask these questions.

I looked over the existing code for NOX and have a couple of questions.

There appears to be a SoftSerial 1 defined already as a workaround for ESC telemetry:

#define USE_SOFTSERIAL1
#define SOFTSERIAL_1_TX_PIN      PA2 // Workaround for softserial not initializing with only RX
#define SOFTSERIAL_1_RX_PIN      PA2 // Backdoor timer on UART2_TX, used for ESC telemetry

If I don't need ESC telemetry, can I redefine SoftSerial1 on PA0 (LED PAD)?

My current plan is to define SoftSerial2 to PA0.

#define USE_SOFTSERIAL2
#define SOFTSERIAL_2_TX_PIN      PA0 // Softserial on the LED pad
#define SOFTSERIAL_2_RX_PIN      PA0 

In target.c, there is a timerHardware section I don't understand.

const timerHardware_t timerHardware[] = {
    DEF_TIM(TIM2, CH3, PB10, TIM_USE_PPM,  0, 0),   //PPM
    DEF_TIM(TIM2, CH1, PA0,  TIM_USE_LED,  0, 0), //2812LED
    DEF_TIM(TIM5, CH2, PA1,  TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR,  0, 0), // S1_OUT
    DEF_TIM(TIM1, CH1N, PA7,  TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR,  0, 0), // S2_OUT
    DEF_TIM(TIM4, CH3, PB8,  TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO,  0, 0), // S3_OUT
    DEF_TIM(TIM3, CH4, PB1,  TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO,  0, 0), // S4_OUT
    DEF_TIM(TIM9, CH1, PA2,  TIM_USE_ANY,  0, 0), //UART2 TX
    DEF_TIM(TIM9, CH2, PA3,  TIM_USE_ANY,  0, 0), //UART2 RX
};

I assume the line DEF_TIM(TIM2, CH1, PA0, TIM_USE_LED needs to change, but I'm not sure to what.
Are TIM2 and CH1 still okay? Looking at other targets, there is a mix of TIM_USE_PPM and TIM_USE_ANY for softserial.

    DEF_TIM(TIM2, CH1, PA0, TIM_USE_ANY,  0, 0), // Softserial on LED PAD

Note, I'll make my changes to a new target using the appropriate #ifdefs. I didn't want to complicate the discussion here.

Thanks for any help.

@issue-label-bot
Copy link

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

@PachisPachis
Copy link

Hi m8

I just modded and compiled for TARGET=NOX to get softserial working and also I2c. Tested with GPS on softserial on LED PAD and PPM PAD. I2c is on UART1. You can still using UART1 as uart and also LED/PPM as their original function (but not both functions at once).

target.mk

F411_TARGETS    += $(TARGET)
FEATURES        += VCP ONBOARDFLASH

TARGET_SRC = \
			drivers/accgyro/accgyro_mpu6000.c \
			drivers/barometer/barometer_bmp085.c \
			drivers/barometer/barometer_bmp280.c \
			drivers/barometer/barometer_ms56xx.c \
			drivers/compass/compass_hmc5883l.c \
			drivers/compass/compass_mag3110.c \
			drivers/compass/compass_qmc5883l.c \
			drivers/compass/compass_ist8310.c \
			drivers/compass/compass_lis3mdl.c \
			drivers/pitotmeter_adc.c \
			drivers/light_ws2811strip.c \
            drivers/flash_m25p16.c \
            drivers/max7456.c

target.h

/*
 * This file is part of Cleanflight.
 *
 * Cleanflight is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cleanflight 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 Cleanflight.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once


#define TARGET_BOARD_IDENTIFIER "NOX1"
#define USBD_PRODUCT_STRING  "NoxF4V1"

#define LED0                    PA4

#define BEEPER                  PC13
#define BEEPER_INVERTED

//I2C
#define USE_I2C
#define USE_I2C_DEVICE_1
#define I2C1_SCL               PB6
#define I2C1_SDA               PB7
#define I2C2_SCL               NONE
#define I2C2_SDA               NONE
#define I2C3_SCL               NONE
#define I2C3_SDA               NONE
#define DEFAULT_I2C_BUS	 BUS_I2C1
#define I2C_DEVICE_1_SHARES_UART1

#define TEMPERATURE_I2C_BUS     BUS_I2C1

#define USE_MAG
#define MAG_I2C_BUS             BUS_I2C1
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
#define USE_MAG_IST8310
#define USE_MAG_MAG3110
#define USE_MAG_LIS3MDL

#define PITOT_I2C_BUS           BUS_I2C1

// *************** SPI **********************
#define USE_SPI
#define USE_SPI_DEVICE_1
#define SPI1_SCK_PIN            PB3
#define SPI1_MISO_PIN   	    PB4
#define SPI1_MOSI_PIN   	    PB5

#define USE_SPI_DEVICE_2
#define SPI2_SCK_PIN            PB13
#define SPI2_MISO_PIN   		PB14
#define SPI2_MOSI_PIN   		PB15


// *************** SPI Gyro & ACC **********************
#define MPU6000_CS_PIN          PB12
#define MPU6000_SPI_BUS         BUS_SPI2

#define USE_EXTI
#define GYRO_INT_EXTI           PA8
#define USE_MPU_DATA_READY_SIGNAL

#define USE_GYRO
#define USE_GYRO_MPU6000

#define USE_ACC
#define USE_ACC_MPU6000

// *************** SPI BARO *****************************
#define USE_BARO
#define USE_BARO_BMP280
#define USE_BARO_SPI_BMP280
#define BMP280_SPI_BUS          BUS_SPI2
#define BMP280_CS_PIN           PA9

// *************** SPI OSD *****************************
#define USE_OSD
#define USE_MAX7456
#define MAX7456_SPI_BUS         BUS_SPI2
#define MAX7456_CS_PIN          PA10
//#define MAX7456_SPI_CLK         (SPI_CLOCK_STANDARD*2)
//#define MAX7456_RESTORE_CLK     (SPI_CLOCK_FAST)

// *************** SPI FLASH **************************
#define USE_FLASHFS
#define USE_FLASH_M25P16
#define M25P16_CS_PIN           PA15
#define M25P16_SPI_BUS          BUS_SPI1
#define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT

// *************** UART *****************************
#define USE_UART_INVERTER

#define USE_VCP

#define USE_UART1
#define UART1_TX_PIN            PB6
#define UART1_RX_PIN            PB7

#define USE_UART2
#define UART2_TX_PIN            PA2
#define UART2_RX_PIN            PA3

// #define INVERTER_PIN_UART2      PC14
#define INVERTER_PIN_UART2_RX   PC14 // PC14 used as inverter select GPIO

#define USE_SOFTSERIAL1
#define SOFTSERIAL_1_TX_PIN      PB10
#define SOFTSERIAL_1_RX_PIN      PA0

#define SERIAL_PORT_COUNT       4 //VCP, USART1, USART2, SOFTSERIAL1

#define DEFAULT_RX_TYPE         RX_TYPE_SERIAL
#define SERIALRX_PROVIDER       SERIALRX_SBUS
#define SERIALRX_UART           SERIAL_PORT_USART2

// *************** ADC *****************************
#define USE_ADC
#define ADC_INSTANCE                         ADC1
#define ADC_CHANNEL_1_PIN               NONE
#define ADC_CHANNEL_2_PIN               PA5
#define ADC_CHANNEL_3_PIN               NONE

#define CURRENT_METER_ADC_CHANNEL        ADC_CHN_1
#define VBAT_ADC_CHANNEL                 ADC_CHN_2
#define RSSI_ADC_CHANNEL                   ADC_CHN_3
/*
#define ADC_INSTANCE                ADC1
#define ADC1_DMA_STREAM             DMA2_Stream0
#define ADC_CHANNEL_1_PIN           PA5
#define ADC_CHANNEL_2_PIN           NONE
//#define ADC_CHANNEL_3_PIN           PA0
#define VBAT_ADC_CHANNEL            ADC_CHN_1
//#define CURRENT_METER_ADC_CHANNEL   ADC_CHN_2
//#define RSSI_ADC_CHANNEL            ADC_CHN_3
*/
// *************** LED2812 ************************
//#define USE_LED_STRIP
//#define WS2811_PIN                      PA0
//#define WS2811_DMA_HANDLER_IDENTIFER    DMA2_ST1_HANDLER
//#define WS2811_DMA_STREAM               DMA2_Stream1
//#define WS2811_DMA_CHANNEL              DMA_Channel_6

// ***************  OTHERS *************************
#define DEFAULT_FEATURES        (FEATURE_OSD | FEATURE_SOFTSERIAL | FEATURE_VBAT)


// #define USE_SPEKTRUM_BIND
// #define BIND_PIN                PA10 //  RX1

#define USE_SERIAL_4WAY_BLHELI_INTERFACE

#define TARGET_IO_PORTA (0xffff & ~(BIT(14)|BIT(13)))
#define TARGET_IO_PORTB (0xffff & ~(BIT(2)|BIT(11)))
#define TARGET_IO_PORTC (BIT(13)|BIT(14)|BIT(15))

#define MAX_PWM_OUTPUT_PORTS       4

target.c

/*
 * This file is part of Cleanflight.
 *
 * Cleanflight is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cleanflight 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 Cleanflight.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdbool.h>
#include <platform.h>

#include "drivers/io.h"

#include "drivers/dma.h"
#include "drivers/timer.h"

const timerHardware_t timerHardware[] = {
    DEF_TIM(TIM2, CH3, PB10, TIM_USE_PPM,  0, 0),   //PPM
    DEF_TIM(TIM2, CH1, PA0,  TIM_USE_LED,  0, 0), //2812LED

    DEF_TIM(TIM5, CH2, PA1,  TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR,  0, 0), // S1_OUT
    DEF_TIM(TIM1, CH1N, PA7,  TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR,  0, 0), // S2_OUT
    DEF_TIM(TIM4, CH3, PB8,  TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO,  0, 0), // S3_OUT
    DEF_TIM(TIM3, CH4, PB1,  TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO,  0, 0), // S4_OUT

    DEF_TIM(TIM9, CH1, PA2,  TIM_USE_ANY,  0, 0), //UART2 TX
    DEF_TIM(TIM9, CH2, PA3,  TIM_USE_ANY,  0, 0), //UART2 RX
};

const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]);

@tonyyng
Copy link
Contributor Author

tonyyng commented Feb 11, 2020

Thanks for your code. I looked it over to try to understand it. It is not necessary to change these lines in target.c when you are using softserial on the LED and PPM pads?

DEF_TIM(TIM2, CH3, PB10, TIM_USE_PPM,  0, 0),   //PPM
DEF_TIM(TIM2, CH1, PA0,  TIM_USE_LED,  0, 0), //2812LED

I'm planning to use GPS on UART1, Frsky FPORT on UART2 and SmartAudio VTX control on Softserial TX (PPM PAD). Will that combination work?

@PachisPachis
Copy link

I guess there is some kind of conditional anywhere, you can preserve that lines as is. I have already a working GPS on softserial1, located on pins PPM and LED. Your combination should work. Regards.

@stale
Copy link

stale bot commented Apr 25, 2020

This issue / pull request has been automatically marked as stale because it has not had any activity in 60 days. The resources of the INAV team are limited, and so we are asking for your help.
This issue / pull request will be closed if no further activity occurs within two weeks.

@stale stale bot added the Inactive label Apr 25, 2020
@stale
Copy link

stale bot commented May 9, 2020

Automatically closing as inactive.

@stale stale bot closed this as completed May 9, 2020
@Feldsalat
Copy link

I would also need a soft serial port for SmartAudio, preferably on the LED pad. Could someone maybe add that?

@s2kaka
Copy link

s2kaka commented Aug 8, 2020

Can Youy show me how to connect Fport, Gps on this board!
I use UART 1 for Fport, UART2 for GPS but GPS not work.
When use Uart 2 for Fport, UART 1 for GPS, Gps work but Fport not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants