arduino-nRF5 icon indicating copy to clipboard operation
arduino-nRF5 copied to clipboard

In support of issue #98 (SoftwareSerial not working)

Open micooke opened this issue 8 years ago • 16 comments
trafficstars

This PR includes a SoftwareSerial library, and is compatible with the arduino-org and adafruit nrf52 SoftwareSerial libraries.

Arduino.h

  • fix errors in #defines for digitalPinToPort, portOutputRegister, portModeRegister

WInterrupts

  • change attachInterrupt define to return the interrupt mask
  • callbacksInt, channelMap now uses an initialiser list instead of memset
  • GPIOTE_IRQn priority dropped from 1 to 3 (same as Uart priority)
  • LOW and HIGH modes added to attachInterrupt for compatibility, which are the same as FALLING and RISING respectively as GPIOTE does not support HIGH and LOW modes
  • To free up clock cycles between GPIOTE interrupts GPIOTE_IRQHandler now searches for the first GPIOTE event and breaks to execute, rather than staying in the interrupt and executing each GPIOTE callback that has triggered an interrupt.

micooke avatar Oct 17 '17 02:10 micooke

I noticed a comment from @sandeepmistry that you only wanted to include the core libraries so I added my SoftwareSerial variant. Let me know if you prefer the one from arduino-org (which mine is based off) or adafruit and i can merge that in instead.

micooke avatar Oct 25 '17 02:10 micooke

Which one is better?

dlabun avatar Oct 25 '17 11:10 dlabun

Im biased so ill say that my variant of the arduino-org one (which i added to this PR) is the best as it allows you to configure the buffer size without modifying the library, and you can configure it to be transmit only (saves a pin, a pin interrupt a little over 1kB of flash). To achieve this it is a header only library, so compile time is slightly longer.

The arduino-org one was first, the adafruit one looks to be a direct copy. All three work, but not as well as the tuned AVR original source as the tuning on the bit timing is courser.

micooke avatar Oct 25 '17 12:10 micooke

Has this been tested with nRF51s as well?

carlosperate avatar Dec 28 '17 02:12 carlosperate

@carlosperate - thankyou for your review! Sorry for not addressing each point in situ, my access is mobile only while on holidays.

First up - thanks for spotting the #ifdef bug, ill fix this!

Ive tested this against the nrf52832 and nrf51822, but it won't work for all pins of the nrf52840. The comment in Arduino.h is a hinter comment that more work is required for the nrf52840.

Copyright is different to licensing, I have not/cannot changed the original license. I dont believe it is possible to sublicense within a source file, but i may be correct. As per your suggestion I'm happy to just add my name to the list for clarity, i just wanted to imply that the prior work was far more significant than my own hacks :blush:

The library.properties file is for the Arduino library manager incase i decide to register this library with them. It also stops the library from being available to incompatible cores i.e. AVR. The Author is generally the most significant contribution, which is Arduino, and i will maintain modifications in my local copy unless it is incorporated in this core at which point the maintainer will need to be changed. I think the original source library version was 1.0.0, but i will check this.

micooke avatar Dec 28 '17 03:12 micooke

I can confirm that the code in this PR works with the micro:bit (nRF51822) using the included SoftwareSerial library. I was able to drive a Serial MP3 Player board off the micro:bit via a SoftwareSerial interface. Assuming that the above issues are resolved, it would be great if this PR (including SoftwareSerial) could be merged into master, as I've been working on a forked branch that requires both SoftwareSerial as well as other changes. Thanks in advance!

ct6502 avatar Dec 28 '17 05:12 ct6502

@carlosperate @micooke Could you give me a status update on this PR? I am thinking we may be ready for another release in the near future.

dlabun avatar Jan 06 '18 22:01 dlabun

Im away for another week, ill be able to fix these minor changes by Friday

micooke avatar Jan 07 '18 02:01 micooke

Updates pushed earlier than expected..

micooke avatar Jan 08 '18 01:01 micooke

@dlabun, @sandeepmistry - Travis build failed, not sure why. It failed when it tries to get any packages; ubuntu packages, this repo from github.com. Very strange. I made a small update to trigger the build again - hopefully it is resolved by now!?

micooke avatar Jan 09 '18 04:01 micooke

I think it was just a temporary outage between Travis and Github, it's all good right now

dlabun avatar Jan 09 '18 06:01 dlabun

@micooke Travis is passing with this PR, any issues with merging it?

dlabun avatar Feb 27 '18 23:02 dlabun

Go for it :+1:

micooke avatar Feb 28 '18 06:02 micooke

Bump (I'm trying to clean up my PRs :blush:)

micooke avatar May 09 '18 22:05 micooke

@dlabun I'm unsure what to do about this one. Concerns:

  • the priority of attachInterrupt(...) has be lowered
  • when I started this project, one goal was to track the official SAMD core. In this case, it doesn't support SoftwareSerial, but maybe we can diverge from this?
  • it's a lot more code to maintain

sandeepmistry avatar Aug 19 '18 13:08 sandeepmistry

the priority of attachInterrupt(...) has be lowered

This was to put the priority the same as Uart, and lower than Wire interrupts. The concern is that GPIOTE can be triggered with a very high duty cycle, which could interfere with higher-priority tasking like I2C comms. On a related note, RTC interrupt priority is 15 in this core and 0 in the SAMD core. Just something to note as we are talking about interrupt priorities.

when I started this project, one goal was to track the official SAMD core. In this case, it doesn't support

SoftwareSerial, but maybe we can diverge from this? Maybe the SAMD core should be modified to support SoftwareSerial? I would say its a fairly essential library.

it's a lot more code to maintain

The changes i made to support SoftwareSerial are in line with modifications made by Arduino-org and Adafruit (who started with you core by the looks of it). You certainly dont need to use my variant of SoftwareSerial, the core changes make it compatible with the Adafruit and Arduino-org variants.

micooke avatar Aug 19 '18 23:08 micooke