@@ -82,6 +82,10 @@ struct da14531_protocol {
82
82
83
83
static struct da14531_protocol _protocol ;
84
84
85
+ static uint8_t * ble_fw = NULL ;
86
+ static size_t ble_fw_size = 0 ;
87
+ static uint8_t ble_fw_checksum = 0 ;
88
+
85
89
#if 0
86
90
static const char * _firmware_loader_state_str (enum firmware_loader_state state )
87
91
{
@@ -104,14 +108,7 @@ static const char* _firmware_loader_state_str(enum firmware_loader_state state)
104
108
105
109
static void _firmware_loader_init (struct firmware_loader * self )
106
110
{
107
- // If we are in factory setup we expect to load the ble firmware, so we start in IDLE.
108
- // In production bootloader and firmware we expect the da14531 to already be booted. We will still
109
- // load the firmware if it happens to not be loaded.
110
- #if FACTORYSETUP == 1
111
- self -> state = FIRMWARE_LOADER_STATE_IDLE ;
112
- #else
113
111
self -> state = FIRMWARE_LOADER_STATE_DONE ;
114
- #endif
115
112
}
116
113
117
114
#define SOH 0x01
@@ -125,10 +122,6 @@ static void _firmware_loader_poll(
125
122
uint16_t * buf_in_len ,
126
123
struct ringbuffer * out_queue )
127
124
{
128
- static uint8_t * ble_fw = NULL ;
129
- static size_t ble_fw_size = 0 ;
130
- static uint8_t ble_fw_checksum = 0 ;
131
-
132
125
// if (*buf_in_len > 0) {
133
126
// util_log(
134
127
// "%s, got bytes %s",
@@ -394,7 +387,7 @@ struct da14531_protocol_frame* da14531_protocol_poll(
394
387
const uint8_t * * hww_data ,
395
388
struct ringbuffer * out_queue )
396
389
{
397
- if (* hww_data ) {
390
+ if (hww_data && * hww_data ) {
398
391
uint8_t tmp [128 ];
399
392
int len = da14531_protocol_format (
400
393
& tmp [0 ], sizeof (tmp ), DA14531_PROTOCOL_PACKET_TYPE_BLE_DATA , * hww_data , 64 );
@@ -464,11 +457,19 @@ void da14531_protocol_init(void)
464
457
// Only attempt swd reset in factory setup or debug builds. In production swd is turned off and
465
458
// this is therefore useless.
466
459
#if FACTORYSETUP == 1 || !defined(NDEBUG )
460
+ // Load the firmware from external flash to RAM so that we are ready to flash.
461
+ if (ble_fw == NULL ) {
462
+ if (!memory_spi_get_active_ble_firmware (& ble_fw , & ble_fw_size , & ble_fw_checksum )) {
463
+ util_log ("da14531: no valid firmware" );
464
+ }
465
+ }
467
466
// Reset the device if possible, if we cannot reset it over SWD, it must already be running
468
467
if (!_swd_reset_da14531 ()) {
469
468
// This may fail if the BLE chip has been started with a production firmware that has
470
469
// disabled the debug interface
471
470
util_log ("da14531: Failed to reset over SWD" );
471
+ free (ble_fw );
472
+ ble_fw = NULL ;
472
473
} else {
473
474
// If we successfully reset the chip, we also would like to load it with firmware
474
475
_protocol .loader .state = FIRMWARE_LOADER_STATE_IDLE ;
0 commit comments