jpconstantineau / Community_nRF52_Arduino

Community Add-on to the Adafruit_nRF52_Arduino Board Support Package
Other
13 stars 5 forks source link

Library has issues to compile for PCA10059 on Linux, needed fixes linked #23

Open mame82 opened 1 year ago

mame82 commented 1 year ago

Compilation for all sketches fails on KALI/Debian Linux.

Issues:

  1. Incompatible atomic declaration in HardwarePWN.h
  2. Missing utoa() declaration/definition

Diff to make things work (no PR, as I just copied over iota.c/.hfrom Adafruit repo, without further adjustments):

diff --git a/cores/nRF5/HardwarePWM.h b/cores/nRF5/HardwarePWM.h
index 47ec16c..f3ecbb3 100644
--- a/cores/nRF5/HardwarePWM.h
+++ b/cores/nRF5/HardwarePWM.h
@@ -51,7 +51,7 @@ class HardwarePWM
   private:
     enum { MAX_CHANNELS = 4 }; // Max channel per group
     NRF_PWM_Type * const _pwm;
-    std::atomic_uint32_t _owner_token;
+    std::atomic<uint32_t> _owner_token;

     uint16_t _seq0[MAX_CHANNELS];

diff --git a/cores/nRF5/itoa.c b/cores/nRF5/itoa.c
index 608145e..49aca53 100644
--- a/cores/nRF5/itoa.c
+++ b/cores/nRF5/itoa.c
@@ -1,5 +1,5 @@
 /*
-  Copyright (c) 2014 Arduino LLC.  All right reserved.
+  Copyright (c) 2016 Arduino.  All right reserved.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -8,7 +8,7 @@

   This library 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.
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
   See the GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
@@ -20,8 +20,56 @@
 #include <string.h>

 #ifdef __cplusplus
-extern "C" {
-#endif
+extern "C"{
+#endif // __cplusplus
+
+#if 0
+/* reverse:  reverse string s in place */
+static void reverse( char s[] )
+{
+  int i, j ;
+  char c ;
+
+  for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- )
+  {
+    c = s[i] ;
+    s[i] = s[j] ;
+    s[j] = c ;
+  }
+}
+
+/* itoa:  convert n to characters in s */
+extern void itoa( int n, char s[] )
+{
+  int i, sign ;
+
+  if ( (sign = n) < 0 )  /* record sign */
+  {
+    n = -n;          /* make n positive */
+  }
+
+  i = 0;
+  do
+  {       /* generate digits in reverse order */
+    s[i++] = n % 10 + '0';   /* get next digit */
+  } while ((n /= 10) > 0) ;     /* delete it */
+
+  if (sign < 0 )
+  {
+    s[i++] = '-';
+  }
+
+  s[i] = '\0';
+
+  reverse( s ) ;
+}
+
+#else
+
+extern char* itoa( int value, char *string, int radix )
+{
+  return ltoa( value, string, radix ) ;
+}

 extern char* ltoa( long value, char *string, int radix )
 {
@@ -73,6 +121,11 @@ extern char* ltoa( long value, char *string, int radix )
   return string;
 }

+extern char* utoa( unsigned long value, char *string, int radix )
+{
+  return ultoa( value, string, radix ) ;
+}
+
 extern char* ultoa( unsigned long value, char *string, int radix )
 {
   char tmp[33];
@@ -90,7 +143,7 @@ extern char* ultoa( unsigned long value, char *string, int radix )
   {
     return 0;
   }
-
+ 
   while (v || tp == tmp)
   {
     i = v % radix;
@@ -103,14 +156,15 @@ extern char* ultoa( unsigned long value, char *string, int radix )

   sp = string;

-
+ 
   while (tp > tmp)
     *sp++ = *--tp;
   *sp = 0;

   return string;
 }
+#endif /* 0 */

 #ifdef __cplusplus
 } // extern "C"
-#endif
+#endif // __cplusplus
diff --git a/cores/nRF5/itoa.h b/cores/nRF5/itoa.h
index ba0010a..a0cb31d 100644
--- a/cores/nRF5/itoa.h
+++ b/cores/nRF5/itoa.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (c) 2015 Arduino LLC.  All right reserved.
+  Copyright (c) 2016 Arduino.  All right reserved.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -8,7 +8,7 @@

   This library 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.
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
   See the GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
@@ -16,15 +16,27 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

-#pragma once
+#ifndef _ITOA_
+#define _ITOA_

 #ifdef __cplusplus
 extern "C"{
-#endif
+#endif // __cplusplus

+#if 0
+
+extern void itoa( int n, char s[] ) ;
+
+#else
+
+extern char* itoa( int value, char *string, int radix ) ;
 extern char* ltoa( long value, char *string, int radix ) ;
+extern char* utoa( unsigned long value, char *string, int radix ) ;
 extern char* ultoa( unsigned long value, char *string, int radix ) ;
+#endif /* 0 */

 #ifdef __cplusplus
 } // extern "C"
-#endif
+#endif // __cplusplus
+
+#endif // _ITOA_
mame82 commented 1 year ago

Some additional infos on flashing PCA10059 Arduino bootloader (Twitter thread, usage of cheap IBDAP CMSIS-DAP with OpenOCD instead of J-LINK debugger):

https://threadreaderapp.com/thread/1552233889867120641.html

mame82 commented 1 year ago

Cross reference to corresponding issue Adafruit-repo https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/200