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

Add support for Generic NRF52805 #442

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ script:
- buildExampleSketch sandeepmistry:nRF5:SeeedArchLink 01.Basics Blink
- buildExampleSketch sandeepmistry:nRF5:Generic_nRF52833 01.Basics Blink
- buildExampleSketch sandeepmistry:nRF5:BBCmicrobitV2 01.Basics Blink
- buildExampleSketch sandeepmistry:nRF5:Generic_nRF52805 01.Basics Blink
32 changes: 32 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,38 @@ menu.version=Version
menu.lfclk=Low Frequency Clock
menu.board_variant=Board Variant

# nRF52805 variants
###################

Generic_nRF52805.name=Generic nRF52805

Generic_nRF52805.upload.tool=sandeepmistry:openocd
Generic_nRF52805.upload.target=nrf52
Generic_nRF52805.upload.maximum_size=192000
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here a60f6db


Generic_nRF52805.bootloader.tool=sandeepmistry:openocd

Generic_nRF52805.build.mcu=cortex-m4
Generic_nRF52805.build.f_cpu=64000000
Generic_nRF52805.build.board=GENERIC
Generic_nRF52805.build.core=nRF5
Generic_nRF52805.build.variant=Generic
Generic_nRF52805.build.variant_system_lib=
Generic_nRF52805.build.extra_flags=-DNRF52805_XXAA
Generic_nRF52805.build.float_flags=
Generic_nRF52805.build.ldscript=nrf52805_xxaa.ld

Generic_nRF52805.menu.softdevice.none=None
Generic_nRF52805.menu.softdevice.none.softdevice=none
Generic_nRF52805.menu.softdevice.none.softdeviceversion=

Generic_nRF52805.menu.lfclk.lfxo=Crystal Oscillator
Generic_nRF52805.menu.lfclk.lfxo.build.lfclk_flags=-DUSE_LFXO
Generic_nRF52805.menu.lfclk.lfrc=RC Oscillator
Generic_nRF52805.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC
Generic_nRF52805.menu.lfclk.lfsynt=Synthesized
Generic_nRF52805.menu.lfclk.lfsynt.build.lfclk_flags=-DUSE_LFSYNT

# nRF52833 variants
###################

Expand Down
18 changes: 18 additions & 0 deletions cores/nRF5/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,22 @@ void Uart::begin(unsigned long baudrate)

void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
{
#ifdef NRF52805_XXAA
Copy link

@sureshsitaula sureshsitaula Jan 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit the macros in the compat header instead?
This is what I did here: edited cores/nRF5/SDK/components/device/nrf52_to_nrf52810.h and I didn't need to modify this file.

(See existing implementation for some other chips, see nrf52840 for example).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be touching code in the SDK? Does that introduce potential upgrade complexity?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question for @sandeepmistry :)
It would be nice to have this consistency between compat .h files, like nrf52_to_nrf52840.h referenced above.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be touching code in the SDK? Does that introduce potential upgrade complexity?

It would be better to avoid doing this, as it would be one more thing to manage when updating the SDK.

That said if it's the best approach wrapping changes in #ifdef ARDUINO would be best.

Copy link
Author

@nikolac nikolac Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I good to leave this as-is for now? There is already series and, in some special cases, chip specific logic in the .cpp library files. I would prefer to leave this condition where it is until we decide on the best way/place to extend SDK definitions without modifying the SDK.

However, I'll do whatever you feel is best. There is increased interest to get this merged in, so whatever I can do to help expedite.

nrfUart->PSEL.TXD = uc_pinTX;
nrfUart->PSEL.RXD = uc_pinRX;
#else
nrfUart->PSELTXD = uc_pinTX;
nrfUart->PSELRXD = uc_pinRX;
#endif

if (uc_hwFlow == 1) {
#ifdef NRF52805_XXAA
nrfUart->PSEL.CTS = uc_pinCTS;
nrfUart->PSEL.RTS = uc_pinRTS;
#else
nrfUart->PSELCTS = uc_pinCTS;
nrfUart->PSELRTS = uc_pinRTS;
#endif
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled;
} else {
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
Expand Down Expand Up @@ -175,12 +185,20 @@ void Uart::end()
nrfUart->TASKS_STOPTX = 0x1UL;

nrfUart->ENABLE = UART_ENABLE_ENABLE_Disabled;

#ifdef NRF52805_XXAA
nrfUart->PSEL.TXD = 0xFFFFFFFF;
nrfUart->PSEL.RXD = 0xFFFFFFFF;

nrfUart->PSEL.RTS = 0xFFFFFFFF;
nrfUart->PSEL.CTS = 0xFFFFFFFF;
#else
nrfUart->PSELTXD = 0xFFFFFFFF;
nrfUart->PSELRXD = 0xFFFFFFFF;

nrfUart->PSELRTS = 0xFFFFFFFF;
nrfUart->PSELCTS = 0xFFFFFFFF;
#endif

rxBuffer.clear();
}
Expand Down
4 changes: 4 additions & 0 deletions cores/nRF5/wiring_analog_nRF52.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern "C" {
static uint32_t saadcReference = SAADC_CH_CONFIG_REFSEL_Internal;
static uint32_t saadcGain = SAADC_CH_CONFIG_GAIN_Gain1_5;

#ifdef PWM_PRESENT
static NRF_PWM_Type* pwms[PWM_COUNT] = {
NRF_PWM0,
NRF_PWM1,
Expand All @@ -47,6 +48,7 @@ static uint32_t pwmChannelPins[PWM_COUNT] = {
#endif
};
static uint16_t pwmChannelSequence[PWM_COUNT];
#endif

static int readResolution = 10;
static int writeResolution = 8;
Expand Down Expand Up @@ -215,6 +217,7 @@ uint32_t analogRead( uint32_t ulPin )
// to digital output.
void analogWrite( uint32_t ulPin, uint32_t ulValue )
{
#ifdef PWM_PRESENT
if (ulPin >= PINS_COUNT) {
return;
}
Expand Down Expand Up @@ -247,6 +250,7 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
break;
}
}
#endif
}

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void SPIClass::detachInterrupt() {
}

#if SPI_INTERFACES_COUNT > 0
#if defined(NRF52_SERIES)
#if defined(NRF52_SERIES) && !defined(NRF52805_XXAA)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be #if defined(NRF_SPI2)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 That would make it work on nrf52810 as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here 1109102

SPIClass SPI (NRF_SPI2, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
#else
SPIClass SPI (NRF_SPI0, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
Expand Down
33 changes: 25 additions & 8 deletions libraries/Wire/Wire_nRF52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,34 @@ void TwoWire::onService(void)
}
}

TwoWire Wire(NRF_TWIM1, NRF_TWIS1, SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, PIN_WIRE_SDA, PIN_WIRE_SCL);
#if defined(NRF52805_XXAA)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also consider #if defined(NRF_TWIM1 here as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the NRF52805 has completely different handler names (TWIM0_TWIS0_TWI0_IRQn vs SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn) which was part of the reason for using the board specific logic.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, sorry for not checking this out before!


#if WIRE_INTERFACES_COUNT > 0
extern "C"
{
void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void)
TwoWire Wire(NRF_TWIM0, NRF_TWIS0, TWIM0_TWIS0_TWI0_IRQn, PIN_WIRE_SDA, PIN_WIRE_SCL);

#if WIRE_INTERFACES_COUNT > 0
extern "C"
{
Wire.onService();
void TWIM0_TWIS0_TWI0_IRQn_IRQHandler(void)
{
Wire.onService();
}
}
}
#endif
#endif

#else

TwoWire Wire(NRF_TWIM1, NRF_TWIS1, SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, PIN_WIRE_SDA, PIN_WIRE_SCL);

#if WIRE_INTERFACES_COUNT > 0
extern "C"
{
void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void)
{
Wire.onService();
}
}
#endif
#endif //defined(NRF52805_XXAA)

#if WIRE_INTERFACES_COUNT > 1

Expand Down