openthread_nrf52_arduino icon indicating copy to clipboard operation
openthread_nrf52_arduino copied to clipboard

Support for the Makerdiary nRF52840 MDK USB Dongle

Open Brezensalzer opened this issue 2 years ago • 11 comments

Hello, Thank You for this excellent package/library! Would it be possible to add support for the nRF52840 MDK USB dongle? I have looked at the variants.h files but don't know how the Arduino packages work. Best regards

Brezensalzer avatar Jan 21 '22 15:01 Brezensalzer

Would it be possible to add support for the nRF52840 MDK USB dongle?

Of course, yes (in potentially). But I don't have one. And it can't use in my country because of radio regulation. (need to pass the compliance testing) So, I can't work to support it.

In general, the Arduino variants file is simple pin to number mapping file. If there are similar configuration devices, rewrite them and maybe work. And The bootloader file needs to consider for nRF52.

https://github.com/adafruit/Adafruit_nRF52_Bootloader/tree/master/src/boards/mdk_nrf52840_dongle

Fortunately, The configuration for the MDK USB dongle is available. Compiling it and store to this repository.

These are needed things to support a new device.


By the way, This repository fork from

https://github.com/adafruit/Adafruit_nRF52_Arduino/

, and still tracking it. For new functions added in this repository, I will soon merge it into my repository.

So, It may be a good way to request adafruit's project to support MDK dongle.

(I just only added an openthread library and add a few modifications from original one.)

soburi avatar Jan 23 '22 06:01 soburi

Thank You for Your reply! I have forked the repository and added the variants.h/cpp files for the board. I extended the boards.txt too. In the Arduino IDE I can select the board and compile a sketch. Brezensalzer/openthread_nrf52_arduino But the upload fails because the bootloader with support for the Softdevice 140 7.0.1 is missing. I have no idea what I'm doing, but I try it anyways ;)

Brezensalzer avatar Jan 23 '22 15:01 Brezensalzer

It looks rather promising now. I have managed to build a new bootloader with Softdevice 140 7.0.1 and flashed it to the MDK Dongle. The example sketch "ot-udp-echo" builds and flashes succesfully on the board. And it works! :) Next I will try some real world examples with i2c and SPI peripherals. If that works, I will make a pull request.

Brezensalzer avatar Jan 23 '22 18:01 Brezensalzer

While the radio and serial works, it is not possible to use the digital io pins. A blink sketch compiles and uploads fine, but the LED stays dark (while the serial output works). I have no clue what's going wrong.

Brezensalzer avatar Jan 24 '22 10:01 Brezensalzer

https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/hardware/nrf52840-mdk-usb-dongle-sch_v1_0.pdf

At first glance, it seems that the pin-number and GPIO number are the same. It is no need to remap. So, I think using pca10056 as a base of MDK dongle configuration is the preferred way. (g_ADigitalPinMap is not remapped in pca10056) The LED connects to GPIO 22,23,24. Please try to modify LED_BUILTIN on the blink sample to 22.

If work it, apply the changing value to LED_BUILTIN that defined in "variant.h".

soburi avatar Jan 24 '22 12:01 soburi

I'm completely lost.

I have flashed CircuitPython on the board (officially supported) with Softdevice 140 6.1.1 and everything works - LED's, I2C, DigitalIO. I looked at the pin definitions in CircuitPython and copied it over to the variants.h/cpp file. I again have flashed Softdevice 140 7.0.1 and the ot-Bootloader on the board. The Arduino IDE works fine, upload, serial monitor etc. OpenThread works, Serial works but not the LED's. I've tried pin numbers (22-24), it does'nt work.

Brezensalzer avatar Jan 25 '22 12:01 Brezensalzer

I'd verify this version can work blink example with pca10056. I think it is pin number problem.

Could you paste a source of your modification?

soburi avatar Jan 28 '22 06:01 soburi

@Brezensalzer,

https://github.com/Brezensalzer/openthread_nrf52_arduino/blob/ee078cd3bf83c331d2b454d9aea487782c038484/variants/mdk_nrf52840/variant.cpp#L27

This definition makes LED pin is 11,12,13, I think.

g_ADigitalPinMap used in digitalWrite, it is converting "printed pin-number" to "real GPIO pin-number".

https://github.com/soburi/openthread_nrf52_arduino/blob/d65d52a979be78b5726ce3ed6d7f1e0d81da7a60/cores/nRF5/wiring_digital.c#L188

11th in the table is 22. So might call digitalWrite(11, ...) will light the LED.

This board seems the printed pin-number is the same as the GPIO pin number.

I think the table should be defined as ... { 0, 1, 2, ... }

https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/assets/images/nrf52840-mdk-usb-dongle-pinout.png

(Padding unused pin values is mightbe a good idea. unconnected pin, or 18 that is occupied by reset feature ...)

soburi avatar Jan 28 '22 11:01 soburi

@soburi You made my day! That was exactly the problem. I changed the number of pins to 25 in the variants.h and enumerated the pins 0..24 in variants.cpp. Now the pins work as expected. I have pushed the changes to my fork and will try out i2c next.

Thank You very much!

Brezensalzer avatar Jan 28 '22 12:01 Brezensalzer

@soburi I have tested successfully I2C and SPI peripherals. Everything looks good, so I've made a pull request. Thank You very much for Your support!

Brezensalzer avatar Jan 28 '22 13:01 Brezensalzer

@Brezensalzer Could you push this patch into the upstream repository ?

It is useful for not only my openthread enabled arduino. so It is better to push upstream.

(In actual, I maintain this project with mainly merge upstream updates only. It will keep world peace if you push to upstream project. :-)

I wrote any I noticed to the PR review.

soburi avatar Jan 28 '22 14:01 soburi