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

printDetails() do not work on SAMD platform (Adafruit Feather M0) #414

Closed
DanoPTT opened this issue Feb 20, 2018 · 12 comments · Fixed by #750
Closed

printDetails() do not work on SAMD platform (Adafruit Feather M0) #414

DanoPTT opened this issue Feb 20, 2018 · 12 comments · Fixed by #750
Assignees

Comments

@DanoPTT
Copy link

DanoPTT commented Feb 20, 2018

It looks that there is problem with printf function used in printDetails(), when library is used with Adafruit Feather M0 board (same processor like on Zero boards, identified as SAMD_ZERO Cortex M0). Probably it is due the remapping Serial to USBSerial. I have found out that Serial.println works, but printf doesn't.

@2bndy5
Copy link
Member

2bndy5 commented Sep 17, 2020

+1 to this. I tried the same thing using both Arduino IDE & PlatformIO using suggested code from docs, and still printDetails() doesn't work.

@TMRh20
Copy link
Member

TMRh20 commented Sep 17, 2020

Yeah, the printf.h file only includes support for AVR and X86 devices. Most other devices seem to have it working by default.

It sounds like printf is not working at all on SAMD? I'm guessing Serial.printf doesn't work either?

Looking here: arduino/ArduinoCore-samd#458 it looks like a modification would need to be made to get it working. If the Arduino API and SAMD platform are not going to include it, changes could maybe be made to the printf.h file to make it work with SAMD, but I don't have a device to test with.

@2bndy5
Copy link
Member

2bndy5 commented Sep 17, 2020

Serial.printf() does work on my Adafruit Feather M0 Express!

If the Arduino API and SAMD platform are not going to include it, changes could maybe be made to the printf.h file to make it work with SAMD

I'm ok with closing this and just deferring to the status of #189 & #322 because the issue you mentioned referenced the fact that the

Arduino team has specifically decided against including printf...

I don't mind trying to alter printf.h for this issue if it helps progress the other 2 issues I referenced. But I wouldn't impose upon everyone (with this particular problem) take that action.

@TMRh20
Copy link
Member

TMRh20 commented Sep 17, 2020 via email

@2bndy5
Copy link
Member

2bndy5 commented Sep 18, 2020

clever idea, but it doesn't seem to work. I put the #define printf Serial.printf before #include "RF24.h". I don't understand why it doesn't work. Calling Serial.printf() & printf() (with the clever define) does work, but not for printDetails().

@TMRh20
Copy link
Member

TMRh20 commented Sep 18, 2020

https://github.com/nRF24/RF24/blob/master/RF24_config.h#L155

If you take a look at the above, I'm going to guess it has to do with the program memory related defines. It may be necessary to redefine a few more things for SAMD to use normal functions instead of progmem related ones.

ie: change

        #ifndef printf_P
          #define printf_P printf
        #endif

to

          #define printf_P printf

@2bndy5 You seem to have a very good grasp of programming along with an understanding of RF24, would you like to be an 'official' contributor? You could make small changes as required, but for larger changes, it would be good to do a PR.

@2bndy5
Copy link
Member

2bndy5 commented Sep 18, 2020

would you like to be an 'official' contributor?

YES PLEASE! I mean, it would be my honor. Of course, I would open a simple issue (if 1 doesn't exist) for your (& other's) input before making small commits. I absolutely agree about the PR stipulation (github can be a nightmare for experts). Not sure if/when the awe for your work on this device will "wear off". My nRF24 understanding comes from my pure python attempt to mimic this repo for CircuitPython devices, but the ATSAMD51 has very little memory left for user-space code (~15kB) with the CircuitPython firmware loaded. So, I've been recommending this library for boards with that chip in relation the nRF24L01.

Back to the issue at hand. I have to dig deeper into the SAMD Arduino core to see what other changes might need to be made. Initial attempt with example you posted wasn't enough.

@TMRh20
Copy link
Member

TMRh20 commented Sep 18, 2020

Awesome, I mostly just want to keep up to date with changes, so for urgent fixes or really minor changes, feel free to do what you need. Things can always be reverted.

ps: I'm sure it will wear off quickly once you realize that none of us really know what we're doing :p

@2bndy5
Copy link
Member

2bndy5 commented Sep 18, 2020

Follow up to the comment I made on that issue: DEAD END found the post with a link to a zip supposedly containing working code on the STM32 concerning printf... Unfortunately, the forum must have suffered an attack or meltdown. the link goes to the forum home page with a notice at the top talking about restoring data.

@2bndy5
Copy link
Member

2bndy5 commented Mar 21, 2021

Figured I'd look into this again (since I seem to be on a roll sifting through the #ifdef soup). And I got it working on my adafruit QtPy board (uses the same exact ATSAMD21 as the adafruit feather M0).

For those interested I just added to the RF24_arch.h using the ARDUINO_ARCH_SAMD macro :

    #else // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
        #if !defined (ARDUINO) // This doesn't work on Arduino DUE
            typedef char const char;

        #elif defined (ARDUINO_ARCH_SAMD)
            #define printf Serial.printf

        #else // Fill in pgm_read_byte that is used, but missing from DUE
            #if defined (ARDUINO_ARCH_AVR) || defined (ARDUINO_ARCH_SAMD)
                #include <avr/pgmspace.h>
// ...

changes will be part of #750

@2bndy5
Copy link
Member

2bndy5 commented Mar 21, 2021

Above fix works for adafruit's fork of ArduinoCore-samd because they define pgmspace.h. CI failed to compile for OG ArduinoCore-samd... 😦 still exploring the problem.

@2bndy5
Copy link
Member

2bndy5 commented Mar 21, 2021

Looks like the Adafruit/ArduionoCore-samd fork includes a copy of avr/pgmspace.h for backwards compatibility with libraries like RF24. The original ArduinoCore-samd uses a newer unified API called api/ArduinoAPI.h which doesn't include avr/pgmspace.h.

This may be an increasing problem for new Arduino boards/cores going forward (like the upcoming RP2040 - tagging #727 ). The unified ArduinoCore-API repo has a copy of pgmspace.h in a subfolder titled deprecated-avr-comp/avr... I think this move to a unified ArduinoCore-API repo happened around 2016. The AVR core seems to be unaffected since it predates 2016.

@wmarkow The need to switch to a logger type library just got more pressing!

About the missing printf()

Serial.printf() was removed from the ArduinoCore-API repo's Print.h (which gets inherited by Stream.h which is then inherited by HardwareSerial.h). the original call to Serial.printf() (based on work in the Adafruit/ArdionoCore-samd repo) uses vnsprinf() (which I think is included from stdarg.h).

@2bndy5 2bndy5 self-assigned this Mar 23, 2021
kripton pushed a commit to kripton/RF24 that referenced this issue Apr 10, 2021
convert _SPI calls to pointers where applicable

typo made BCM driver fail

overload begin() and amended docs about begin()

fix faulty #ifdef logic

doxygen v1.9.1 deprecated COLS_IN_ALPHA_INDEX tag

bump version to v1.4.0

exclude only RF24_LINUX

apply ptr treatment to Teensy, LittleWire, & Due

trigger ArduinoCLI action

doxygen action shouldn't create a docs folder

no need to specify output dir in doxygen action

make my life simpler: use new RF24_SPI_PTR macro

trigger ArduinoCLI action

forgot about c'tor; fix 2-space indent in begin()

abstract SPI::begin() from _init_pins()

adjust csn_pin before SPI.begin() on BCM driver

conforming whitespace

add printf.h fix from @TonioChingon in nRF24#739

rename atxmega.md & add link to supported product

add Due to ArduinoCLI action

fix teensy support; add PIO CI for teensy

[PIO CI] use quoted matrix entries

[PIO CI] use single quotes?

I hate YML

Gimme that badge

add MRAA to Linux CI action

typo

[Linux CI] MRAA install needs special permission

try with "sudo bash -c"

[Linux CI] MRAA not cross compiling (I think)

add example code snippets to Arduino support pg

doc typos

Due can't use SPI_PTR; delete ATXMEGA/readme.md
(use docs/atxmega.md instead)

fix nRF24#414; note need mbed example in arduino.md

fix printf() only for adafruit/ArduinoCore-SAMD

add msg about COMMON_ISSUES to README

add estimated mbed example to arduino.md

avr/pgmspace.h was added to Due core in 2013

oops, undo my testing change

remove useless Due config file nRF24#752

ammend support for SPI_UART in csn()

Confirm working 2nd SPI bus on esp8266 nRF24#648

fix indent

c-n-p artifact; more indent inconcsistencies

comment out theroretical example snippets

add pinout img from RF24Audio repo

doxygen sux at reading imgs

implement nRF24#539

my CnP skills are lacking

need to test py wrapper

[py_wrap] begin fails to compile

[py wrap] oops left the old begin still in there

[py wrap] use thin wrapper for begin_w/_pins

[pr wrap] try explicit begin(void)

boost.py docs suck

[py wrap] try using same name for begin(pin, pin)

[py wrap] c'tor overload is bad

[py wrap] "optional<>" template didn't take

[py wrap] unmatched parenthesis

advise that teensy doesn't need overloaded begin()

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

Successfully merging a pull request may close this issue.

4 participants