<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14401/compile-sdk11-with-arm-compiler-version-6</link><description>I would like to use the latest ARM Compiler Version 6 ( armclang ) because I need some features of the C++11 language. 
 Is it possible to use the latest ARM Compiler Version 6 to compile the SDK 11 ? Which flags should we use to be compatible with all</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 10 Sep 2018 13:12:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14401/compile-sdk11-with-arm-compiler-version-6" /><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/148036?ContentTypeID=1</link><pubDate>Mon, 10 Sep 2018 13:12:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af316b89-86cd-4839-8839-4d9c2b248f53</guid><dc:creator>Emmanuel Blot</dc:creator><description>&lt;p&gt;As well as SDK v15.1 / S132 v6 / LLVM v7. See&amp;nbsp;&lt;a href="https://github.com/eblot/nrf5-llvm"&gt;https://github.com/eblot/nrf5-llvm&lt;/a&gt;&amp;nbsp;for details&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/55005?ContentTypeID=1</link><pubDate>Thu, 31 Aug 2017 10:05:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1bce9cc-b9df-491c-9b4a-bcc95746f59e</guid><dc:creator>Emmanuel Blot</dc:creator><description>&lt;p&gt;FWIW, it also works fine with clang-5.0.0-rc4&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/55004?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 10:06:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:878f43a7-2690-4f96-b8b8-90a5e59e5174</guid><dc:creator>Emmanuel Blot</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I was sick and tired not to being able to use a modern toolchain and getting stuck with a deprecated GCC version, because of these (somewhat dodgy) SVC calls.&lt;/p&gt;
&lt;p&gt;Unfortunately, I did not find a way to fix it with a couple of additional macros, because the &amp;quot;signature&amp;quot; parameter of the &lt;code&gt;SVCALL()&lt;/code&gt; macro cannot be broken down (at least with the C/C++ preprocessor) into argument types and argument names. It would require the macro arguments to be rewritten with another, less readable syntax.&lt;/p&gt;
&lt;p&gt;Anyway, it is still possible to fix the SDK to build with Clang/LLVM. At least, it now works smoothly with both a BLE 4.0 central and BLE 4.0 peripheral projects, with SDK13, S132 on nRF52 chips, with clang 4.0.1 and -O2 and -O3 optimisation level. YMMV :-)&lt;/p&gt;
&lt;p&gt;The easiest solution I found for now is to modify (to be more precise: add some lines to) a couple of Nordic header files, &lt;em&gt;i.e.&lt;/em&gt; the files that contain SVCALL invocations, plus the one that defines this macro (&lt;code&gt;nrf_svc.h&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;As hand-writing the files could be quite error-prone and because this task would have to be repeated on each SDK release, I wrote a small Python3 script to deal with it.&lt;/p&gt;
&lt;p&gt;Building with Clang/LLVM (assuming you have downloaded or built the toolchain with support for ARM Cortex-M4 for use with nRF52) now requires to execute once the following simple steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Edit &lt;code&gt;softdevice/s132/include/nrf_svc.h&lt;/code&gt; so that &lt;code&gt;SVCALL&lt;/code&gt; declare a static inline function when Clang is in used.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;--- a/components/softdevice/s132/headers/nrf_svc.h
+++ b/components/softdevice/s132/headers/nrf_svc.h
@@ -50,6 +50,9 @@
 #ifndef SVCALL
 #if defined (__CC_ARM)
 #define SVCALL(number, return_type, signature) return_type __svc(number) signature
+#elif defined(__clang__)
+#define SVCALL(number, return_type, signature) \
+   static inline return_type signature;
 #elif defined (__GNUC__)
 #ifdef __cplusplus
 #define GCC_CAST_CPP (uint16_t)
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the Python script on your SDK installation. It should print out (to stderr) which are the files to be patched.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python3.5 nrfsvc.py components/softdevice/s132
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If everything looks ok, run the same script with the &lt;code&gt;-u&lt;/code&gt; option switch, to update the source files. &lt;strong&gt;Do not execute this step if you have easy no way to revert back in case something goes wrong, you&amp;#39;ve been warned...&lt;/strong&gt; Any SCM tool is your friend here.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python3.5 nrfsvc.py -u components/softdevice/s132
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use your favorite SCM tool to check the changes - &lt;code&gt;svn diff&lt;/code&gt;, &lt;code&gt;git diff&lt;/code&gt;, ... - and (re)build your project with Clang/LLVM.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note that if you run the script on a higher directory level, you&amp;#39;ll find a couple of files which contain non-ASCII characters, so the script will discard those files without analysing them, namely:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;components/ble/common/ble_date_time.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;components/ble/common/ble_sensor_location.h&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;components/libraries/crypto/nrf_crypto_keys.h&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It should not hurt as they do not contain &lt;code&gt;SVCALL&lt;/code&gt; calls, and I got lazy dealing with those files (and bothering to support Python2.x) - maybe Nordic have fixed them since?&lt;/p&gt;
&lt;p&gt;Basically, what the script does it quite simple:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;it searches for all header files from the specified top-level directory&lt;/li&gt;
&lt;li&gt;for each script that contains one or more &lt;code&gt;SVCALL&lt;/code&gt; invocation, it parses this macro arguments, then emits a static inline function. See below for the details about these functions.&lt;/li&gt;
&lt;li&gt;it packages in a new header file the original content of the SDK header file, and appends to this file the new inline function(s), with a couple of macros to generate the proper ARM SVC calls.&lt;/li&gt;
&lt;li&gt;if the generation completes successfully, it swaps the original header file with the newly generated one. This last step should prevent from trashing a valid file is something goes wrong, but it should not prevent you from using a SCM tool to revert back at any time.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The emitted static inline functions are straighgforward:&lt;/p&gt;
&lt;p&gt;Each static inline function declares &lt;strong&gt;which&lt;/strong&gt; ARM registers are actually used by the supervisor call, to let the compiler know which registers are used and spilled, so it does not attempt to optimise them out. This is the root cause of the issue with the incomplete declaration made with the designed-for-GCC, provided macro.&lt;/p&gt;
&lt;p&gt;This is at least &lt;code&gt;r0&lt;/code&gt; - which is used for the return code, and from none up to (&lt;code&gt;r0&lt;/code&gt;,) &lt;code&gt;r1&lt;/code&gt;, &lt;code&gt;r2&lt;/code&gt;, and &lt;code&gt;r3&lt;/code&gt; scratch registers, i.e. for up to 4 32-bit SVC arguments. It would fail with any 64-bit argument (or return code) and would be left undetected, but AFAICT, Nordic does not use them. It also encodes in the SVC opcode which supervisor call is to be made, as with the original macro.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re interested in the script, the latest version it is available from here: &lt;a href="https://github.com/eblot/homebrew-armeabi/blob/master/nrfsvc.py"&gt;github.com/.../nrfsvc.py&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/55003?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 13:37:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86fd2875-e2ff-4a58-ab47-49ce5316eba8</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;... a macro which takes the current SVCALL() parameters and spits out that wrapper. That&amp;#39;s because in order to do it, you need to know how many arguments you have and possibly have them listed out (I don&amp;#39;t remember, it&amp;#39;s 2 years since I did this).&lt;/p&gt;
&lt;p&gt;It would mean adding some parameters to SVCCALL() which the other compilers don&amp;#39;t use, but clang does, or writing a quick shim for clang. Either works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/55002?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 13:23:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e041ad28-3d5d-4ac8-9f2c-f4acc71ea101</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;It&amp;#39;s a bit of both. the gcc optimiser doesn&amp;#39;t require the definitions of naked ASM functions to say they do actually use the values of all parameters, it always sets the stack up and it always takes the return value and doesn&amp;#39;t try to optimise. That&amp;#39;s arguably wrong because you can specify which arguments are really used and probably should. If they changed that however, it would break so much code I can&amp;#39;t imagine they ever will. So the ASM code for the SVC calls is kind of technically wrong, but it works with GCC and is unlikely to break.&lt;/p&gt;
&lt;p&gt;clang works rather differently, so unless you specify exactly that all the arguments to an sd_ function are used, it can, and does, optimise away the ones which it believes aren&amp;#39;t.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s quite easy to write an sd_ function which works perfectly well in clang, under all cases of optimisation. However what&amp;#39;s NOT easy, is writing ..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/55001?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 13:03:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0242f971-d58a-49cd-bda7-22991cf1d222</guid><dc:creator>Christopher</dc:creator><description>&lt;p&gt;@hkn Thanks for your reply. I understand the reasons why this will take some time and effort.&lt;/p&gt;
&lt;p&gt;For now GCC is the only alternative which supports some of the latest C++ features I like to work with when I develop embedded BLE applications, let&amp;#39;s hope other compilers will support them too ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/55000?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 12:46:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b60923f-0c3e-46dd-bd8d-ac8f5ed22e97</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;I cannot comment if we&amp;#39;re officially going to support the llvm toolchain in the future (AFAIK: It has not been discussed with management at this moment), but I am quite sure if we&amp;#39;re going to support it in the future; it is not going to be for the next SDK release.&lt;/p&gt;
&lt;p&gt;I can however comment on the status as-of nRF5 SDK v11:&lt;/p&gt;
&lt;p&gt;One of the huge problems with our SDK + llvm/armclang is that the SVC handling is unreliable. This could be a problem on our side, or it can be a problem with the clang compiler. We&amp;#39;re not sure at this moment.&lt;/p&gt;
&lt;p&gt;For Nordic to support a new toolchain, we have to make sure that all the functionality that we provide, and use in our SDK, works with this new toolchain without compromises. At this moment; it does not do that.&lt;/p&gt;
&lt;p&gt;Cheers,
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54999?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 12:11:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55a4a716-3816-4228-9c0c-1350afe09d67</guid><dc:creator>Christopher</dc:creator><description>&lt;p&gt;@Nordic Any plan to officially support the ARM Compiler Version 6 for the next SDK releases ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54998?ContentTypeID=1</link><pubDate>Fri, 10 Jun 2016 09:47:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c08f9ec2-eb71-4ddb-bc68-9b5d77acc445</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;that would be very welcome. I have actually done this work some time ago, it was just too manual to keep up but I&amp;#39;m happy to share anything I still have if you want it. It&amp;#39;s going to be a one-time pain thing to come up with a version of SVCALL which works, all my other testing with clang showed up no other issues than that although any use of __asm() probably needs auditing because inline assembler is treated quite differently from gcc, any other assembler in .s files, will be fine.&lt;/p&gt;
&lt;p&gt;Segger Embedded Studio also has a clang option, so that&amp;#39;s another product people are going to see a clang option and try it out.&lt;/p&gt;
&lt;p&gt;clang is a nice compiler, it can do some very clever optimisations although it&amp;#39;s better at making fast code than small code in my limited experience. These days with the wonderful amount of flash we get to play with it&amp;#39;s less of an issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54997?ContentTypeID=1</link><pubDate>Fri, 10 Jun 2016 09:13:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:206650d1-0377-4a90-b321-45c895ff75b7</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;I noticed the same thing when trying -O2 or -O3. -O1 worked fine, anything over this failed (including Os/Oz). I really like clang as a compiler and the features that it provides, and I&amp;#39;ll try to push for a deeper investigation of the llvm toolchain internally. Since Keil v5.20/DS-5/SES all have the option to use llvm, it will become more widespread in the near future.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54996?ContentTypeID=1</link><pubDate>Fri, 10 Jun 2016 08:06:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6b5ae19-f146-476b-b735-fb3992c3e1f4</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;unfortunately even optnone doesn&amp;#39;t work in many cases, the clang optimiser is very aggressive and because there&amp;#39;s nothing saying the arguments are used at all, even if it leaves them alone in the function itself, it often just doesn&amp;#39;t even set them up for the call.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been through every single option clang has for trying to control this and not one works at high optimisation levels properly.&lt;/p&gt;
&lt;p&gt;What&amp;#39;s needed, unfortunately, is for the SVCALL macro to expand to have some more information, eg the count of parameters, in that way it&amp;#39;s possible to have different stubs for different argument counts and reference that the arguments are used (and that r0 contains the return).&lt;/p&gt;
&lt;p&gt;Arguably clang is actually right here and gcc is sort of wrong, but that doesn&amp;#39;t really help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54995?ContentTypeID=1</link><pubDate>Fri, 10 Jun 2016 07:44:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58e185a2-b210-46f2-ada9-609e0f296d2a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;I have tested both armclang and clang-3.8, and can confirm what you state, RK. It will optimize away &lt;em&gt;something&lt;/em&gt; (arguments in registers R0-R3 I assume?) in the SVC-calls. You can get around this with &amp;quot;optnone&amp;quot; attribute to the SVCALL macro, but that&amp;#39;s not a proper workaround in my mind. Cheers, Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54994?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2016 13:34:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39e76cfa-5d3a-4ad7-9896-7b183c09b5d4</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;is armclang related to clang, as in the LLVM compiler? If so, it&amp;#39;s very likely not going to work at all. clang/llvm fails to generate proper softdevice calls in release mode for reasons I and others have gone into at length on other threads. You can&amp;#39;t currently use clang to compile so if armclang is based on LLVM, give up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile SDK11 with ARM Compiler Version 6</title><link>https://devzone.nordicsemi.com/thread/54993?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2016 13:28:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb79dc51-e1e6-4dcd-834d-49fe5794c49b</guid><dc:creator>Christopher</dc:creator><description>&lt;p&gt;It seems to be quite impossible to patch every files of the SDK by myself to add the new compiler abstraction...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>