Compiling Espruino for NRF52840DK without Blutetooth #7571
Replies: 1 comment
-
Posted at 2024-05-30 by @fanoush oh, looks like nobody tested this combination, at least 52832/SDK12 worked some time ago, hopefully the fix won't be too hard. Anyway, why do you need it? I have a patch with something like NRF.stop()/start() where I can turn softdevice completely off and later back on and it seems to work with Nordic 52840 dongle, would that help? Posted at 2024-05-30 by Chris3006 First of all thanks for your reply. Posted at 2024-05-30 by @fanoush Ah, OK, so that won't help you. Softdevice takes over hardware when enabled and breaks precise timing, so after NRF.stop() one can freely poke radio and other registers that are protected when softdevice is enabled and also interrupts go directly to the application and some reserved hardware is free to use. So that is not the reason for you. Looks like the issue goes deeper, it seems to be it is not that much supported now. I just tried build for NRF52832DK with bluetooth off and it breaks in one place
but then it still links softdevice into binary so no big flash saving happens, that would need different linker script which is not there (and never was?). I made such linker script now and yet it needs Makefile tunings as it still tries to merge softdevice in (and fails), anyway I quickly hacked that and produced a hex file, I wonder if it even starts in your board? attached is hex file built with SDK12 but I cannot test it right now. it should run both on 52832 and 52840 (but uses only 64K ram and 512K flash) and takes over whole device - no SoftDevice or bootloader if you want, you can try it, if it even starts and you get espruino console on serial it is promising I may look into this soon for 52840/SDK15 as I plan to try Enhanced ShockBurst radio protocol in Espruino with 52840 dongle and need USB which is not in SDK12 But anyway, it looks like running without softdevice is not really there and probably never was, without Bluetooth != without softdevice. Attachments: Posted at 2024-05-30 by @fanoush
Yes, checked more and when BLUETOOTH library is disabled it does not mean that softdevice is not needed. Some code always expects softdevice to be present - at least the flash erasing/writing code like https://github.com/espruino/Espruino/blob/52352efac4f8f40976a4d268a0a074ad15251b29/targets/nrf5x/jshardware.c#L2483 So no need to try that hex above, most probably it won't work at all or at least flash storage writing won't work. Also here it is hardcoded that softdevice is always present So basically it is doable to remove softdevice dependency but needs some work. What can be done easily is to just remove BLUETOOTH to trim the espruino binary down but softdevice still needs to be there for now. TO fix the error you are having with 52840DK/SDK15 you can try this change diff --git a/targets/nrf5x/jshardware.c b/targets/nrf5x/jshardware.c
index 879942b42..8a7299953 100644
--- a/targets/nrf5x/jshardware.c
+++ b/targets/nrf5x/jshardware.c
@@ -93,6 +93,8 @@ void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) {
#if NRF_SD_BLE_API_VERSION<5
#include "softdevice_handler.h"
#else
+#include "nrf_sdh.h"
+#include "nrf_sdh_soc.h"
#include "nrfx_spim.h"
#endif
@@ -984,7 +986,13 @@ void jshInit() {
#else // !BLUETOOTH
// because the code in bluetooth.c will call jsh_sys_evt_handler for us
// if we were using bluetooth
+#ifdef SOFTDEVICE_PRESENT
+#if NRF_SD_BLE_API_VERSION<5
softdevice_sys_evt_handler_set(jsh_sys_evt_handler);
+#else
+ NRF_SDH_SOC_OBSERVER(m_soc_observer, 1, jsh_sys_evt_handler, NULL);
+#endif
+#endif
#endif It builds for me with that but don't have any device to test around me now. Posted at 2024-05-30 by Chris3006 Thanks for the detailed explanation! I just added defines to ignore these lines if bluetooth is disabled.
It compiles and runs on the NRF52840DK and is the desired result i was looking for. Posted at 2024-05-30 by @fanoush Does flash writing work too? You can test by creating one file via Storage API or uploading file via IDE. The jsh_sys_evt_handler mainly handles waiting for flash operations to finish so if it does not work properly it may be stuck at writing. Posted at 2024-05-30 by Chris3006 No this unfortunately does not work. Posted at 2024-05-30 by @fanoush Yes, I thought so. I was afraid the code
actually does not work well when softdevice is disabled and both those parts should probably be removed. Attached is something I use in my version with NRF.stop()/start(). In my experience when softdevice is off the events do not come and those same sd_flash_xx calls block and directly return success/error without invoking the handler. Attachments: Posted at 2024-05-30 by @fanoush It is actually documented here https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v3.0.0/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?cp=5_7_3_9_2_7_2_9#ga8b49f2e72e97291aecc18ce396956eed
so I think registering jsh_sys_evt_handler above when BLUETOOTH is not defined is actually not needed, all it does now is here Posted at 2024-05-31 by Chris3006 Now i understand what is happening. So the lines in Posted at 2024-05-31 by @fanoush
Yes, I think it is there just in case there are more events handled in future but so far there are none other than the flash related ones that will not arrive. Also in your case the
could be simplified to have sd_enabled to be 0, so something like
could be a better patch handling both cases, but it doesn't matter that much. There is actually slight nuance because there is Posted at 2024-05-31 by Chris3006 I tried a little more and found out that that Posted at 2024-05-31 by @fanoush oh, yes, that's probably RTC not running because low frequency 32kHz source and/or RTC is not enabled, that is what sd_softdevice_enable does too :-( so looks like this was not really tested/used for a long time (or ever). there is in my
so that's basically but maybe even the crystal or RC oscillator is not running? try the poke above first if it helps Posted at 2024-05-31 by @fanoush if even 32kHz is not running then maybe
or maybe try Posted at 2024-05-31 by @fanoush however at least the LF clock should be started so maybe it is just RTC0 that was forgotten to be started(?) when BLUETOOTH is disabled so maybe into that
you can put EDIT: not sure about PRESCALER for the RTC, maybe default is OK? if not then the clock will run too fast Posted at 2024-06-03 by Chris3006 Hi, So i made your suggested changes:
It looks like the PRESCALER configuration works like this. At least the I've attached the complete changes. If anyone needs this too it can be found here. Attachments: Posted at 2024-06-03 by @fanoush
For calling the In fact if BLUETOOTH is enabled it can be set to 1. It is only my case, where I can turn it off and on via NFC.stop()/start(), that needs this call. Posted at 2024-06-03 by Chris3006 Ahh! I don't know why this happened! So i just reversed it.
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-05-29 by Chris3006
Hi,
i have successfully compiled an Espruino 2V22 binary for the NRF52840-DK using the NRF52840DK.py board definition file.
However if i try to compile without bluetooth i get the following errors:
any advice on how to get espruino working on the NRF52840DK without Bluetooth?
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions