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

[WIP] Add officialstm32 eeprom write API functions and wrap in conditionals #13

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

chrysophylax
Copy link

@chrysophylax chrysophylax commented Dec 3, 2020

Started fixing up a patch for #12

I've no real experience working with the emulated eeprom/flash so feel free to rewrite any/all parts.

@chrysophylax
Copy link
Author

(save-image) seems to work but (load-image) crashes my bluepill. All help would be appreciated

@technoblogy
Copy link
Owner

OK I'll take a look at it this afternoon.

@technoblogy
Copy link
Owner

I've had a look at your code. However, I can't work out where the EEPROM library is that you're using. I have the official STM32 core version 1.9.0 installed, but the EEPROM library in libraries just looks like the original Arduino one.

Where did you find the example code such as:

	for (uint16_t i=0; i<E2END; i++){
		eeprom_buffered_write_byte(i, 0);
	}
	eeprom_buffer_flush();

The key question is: how much emulated EEPROM does it provide? With the current settings uLisp assumes there are 10240 bytes, and it uses a minimum of 512 for the symbol table.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 3, 2020

I saw the function defs in .arduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/stm32_eeprom.h and I read through some of the example code from the official examples package for an example of how to use it/how it works https:/stm32duino/STM32Examples/blob/master/examples/NonReg/BufferedEEPROM/BufferedEEPROM.ino and this example compiles and runs perfectly fine on my STM32f103xx blue pill

@chrysophylax
Copy link
Author

Looking closer, the actual implementation seems to be in .arduino15/packages/STM32/hardware/stm32/1.9.0/libraries/SrcWrapper/src/stm32/stm32_eeprom.c

@technoblogy
Copy link
Owner

I can't spot anything wrong with your code - I think it's unnecessary to clear the buffer, but it can't do any harm.

I'd be interested to know what the value of E2END is; can you insert:

Serial.println(E2END);

@chrysophylax
Copy link
Author

It gives me 1023 but I'm not sure in what unit that is.

From the stm32_eeprom.h I read

/*
 * FLASH_PAGE_SIZE is not defined for STM32F2xx, STM32F4xx and STM32F7xx
 * Could be redefined in variant.h or using build_opt.h
 * Warning: This is not the sector size, only the size used for EEPROM
 * emulation. Anyway, all the sector size will be erased.
 * So pay attention to not use this sector for other stuff.
 */
#define FLASH_PAGE_SIZE     ((uint32_t)(16*1024)) /* 16kB page */
#endif
#define E2END (FLASH_PAGE_SIZE - 1)
#endif

@technoblogy
Copy link
Owner

Try changing:

#define EEPROMSIZE 10240 

to:

 #define EEPROMSIZE 1023

@chrysophylax
Copy link
Author

With the change #define EEPROMSIZE 1023 I get the same thing happening on (load-image).
Looking in the Linux kernel message log, it seems the chip basically loses the ability to communicate over usb/serial

[73531.208839] xhci_hcd 0000:00:14.0: A Set TR Deq Ptr command is pending.
[73531.208847] xhci_hcd 0000:00:14.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[73531.209786] xhci_hcd 0000:00:14.0: WARN Cannot submit Set TR Deq Ptr
[73531.209790] xhci_hcd 0000:00:14.0: A Set TR Deq Ptr command is pending.
[73531.209799] xhci_hcd 0000:00:14.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[73531.220499] xhci_hcd 0000:00:14.0: WARN Cannot submit Set TR Deq Ptr
[73531.220504] xhci_hcd 0000:00:14.0: A Set TR Deq Ptr command is pending.
[73531.220514] xhci_hcd 0000:00:14.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[73540.553956] usb 1-1.3-port2: disabled by hub (EMI?), re-enabling...
[73540.554173] usb 1-1.3.2: USB disconnect, device number 28
[73540.556321] cdc_acm 1-1.3.2:1.0: failed to set dtr/rts
[73540.765182] usb 1-1.3.2: new full-speed USB device number 29 using xhci_hcd
[73540.845138] usb 1-1.3.2: device descriptor read/64, error -32
[73541.028518] usb 1-1.3.2: device descriptor read/64, error -32
[73541.208450] usb 1-1.3.2: new full-speed USB device number 30 using xhci_hcd
[73541.285139] usb 1-1.3.2: device descriptor read/64, error -32
[73541.468555] usb 1-1.3.2: device descriptor read/64, error -32
[73541.575497] usb 1-1.3-port2: attempt power cycle
[73541.655551] usb 1-1.3.3: reset full-speed USB device number 25 using xhci_hcd
[73541.852102] usb 1-1.3.3: reset full-speed USB device number 25 using xhci_hcd
[73542.221798] usb 1-1.3.2: new full-speed USB device number 31 using xhci_hcd
[73542.221932] usb 1-1.3.2: Device not responding to setup address.
[73542.428583] usb 1-1.3.2: Device not responding to setup address.
[73542.635396] usb 1-1.3.2: device not accepting address 31, error -71
[73542.708409] usb 1-1.3.2: new full-speed USB device number 32 using xhci_hcd
[73542.708505] usb 1-1.3.2: Device not responding to setup address.
[73542.915201] usb 1-1.3.2: Device not responding to setup address.
[73543.121784] usb 1-1.3.2: device not accepting address 32, error -71
[73543.121998] usb 1-1.3-port2: unable to enumerate USB device

@chrysophylax
Copy link
Author

Are we overwriting something or ... ? I can re-program it from Arduino using the STM32 ST-Link V2 STM32CubeProgrammer SWD .

@chrysophylax
Copy link
Author

chrysophylax commented Dec 3, 2020

#include <EEPROM.h>
#define DATA_LENGTH E2END

void setup() {
  Serial.begin(115200);
  while(!Serial) {;;} 
  // Fill the EEPROM buffer in memory with data
  for (uint16_t i = 0; i < DATA_LENGTH; i++) {
    eeprom_buffered_write_byte(i, (uint8_t) 255);
    Serial.println(i);
  }

  // Copy the data from the buffer to the flash
  eeprom_buffer_flush();

  // Clear the buffer for demonstration purpose
  for (uint16_t i = 0; i < DATA_LENGTH; i++) {
    eeprom_buffered_write_byte(i, 0);
  }

//  // Print the 254th byte of the current buffer (should be 0)
//  Serial.println(eeprom_buffered_read_byte(254));

  // Copy the data from the flash to the buffer
  eeprom_buffer_fill();

  // Print the last byte of the current buffer 
  Serial.println("Last byte of buffer");
  Serial.println(eeprom_buffered_read_byte(DATA_LENGTH - 1));
}

void loop() {}

This program leaves it in a good state and outputs

23:19:51.770 -> 0
23:19:51.770 -> 1
23:19:51.770 -> 2
23:19:51.770 -> 3
23:19:51.770 -> 4
23:19:51.770 -> 5
23:19:51.770 -> 6
23:19:51.770 -> 7
23:19:51.770 -> 8
23:19:51.770 -> 9
23:19:51.770 -> 10
23:19:51.770 -> 11
23:19:51.770 -> 12
23:19:51.770 -> 13
23:19:51.770 -> 14
23:19:51.770 -> 15
23:19:51.770 -> 16
23:19:51.770 -> 17
23:19:51.770 -> 18
23:19:51.770 -> 19
23:19:51.770 -> 20
23:19:51.770 -> 21
23:19:51.770 -> 22
23:19:51.770 -> 23
23:19:51.770 -> 24
23:19:51.770 -> 25
23:19:51.770 -> 26
23:19:51.770 -> 27
23:19:51.770 -> 28
23:19:51.770 -> 29
23:19:51.770 -> 30
23:19:51.770 -> 31
23:19:51.770 -> 32
23:19:51.770 -> 33
23:19:51.770 -> 34
23:19:51.770 -> 35
23:19:51.770 -> 36
23:19:51.770 -> 37
23:19:51.770 -> 38
23:19:51.770 -> 39
23:19:51.770 -> 40
23:19:51.770 -> 41
23:19:51.770 -> 42
23:19:51.770 -> 43
23:19:51.770 -> 44
23:19:51.770 -> 45
23:19:51.770 -> 46
23:19:51.770 -> 47
23:19:51.770 -> 48
23:19:51.770 -> 49
23:19:51.770 -> 50
23:19:51.770 -> 51
23:19:51.770 -> 52
23:19:51.770 -> 53
23:19:51.770 -> 54
23:19:51.770 -> 55
23:19:51.770 -> 56
23:19:51.770 -> 57
23:19:51.770 -> 58
23:19:51.770 -> 59
23:19:51.770 -> 60
23:19:51.770 -> 61
23:19:51.770 -> 62
23:19:51.770 -> 63
23:19:51.770 -> 64
23:19:51.770 -> 65
23:19:51.770 -> 66
23:19:51.770 -> 67
23:19:51.770 -> 68
23:19:51.770 -> 69
23:19:51.770 -> 70
23:19:51.770 -> 71
23:19:51.770 -> 72
23:19:51.770 -> 73
23:19:51.770 -> 74
23:19:51.770 -> 75
23:19:51.770 -> 76
23:19:51.770 -> 77
23:19:51.770 -> 78
23:19:51.770 -> 79
23:19:51.770 -> 80
23:19:51.770 -> 81
23:19:51.770 -> 82
23:19:51.770 -> 83
23:19:51.770 -> 84
23:19:51.770 -> 85
23:19:51.770 -> 86
23:19:51.770 -> 87
23:19:51.770 -> 88
23:19:51.770 -> 89
23:19:51.770 -> 90
23:19:51.770 -> 91
23:19:51.770 -> 92
23:19:51.770 -> 93
23:19:51.770 -> 94
23:19:51.770 -> 95
23:19:51.770 -> 96
23:19:51.770 -> 97
23:19:51.770 -> 98
23:19:51.770 -> 99
23:19:51.770 -> 100
23:19:51.770 -> 101
23:19:51.770 -> 102
23:19:51.770 -> 103
23:19:51.770 -> 104
23:19:51.770 -> 105
23:19:51.770 -> 106
23:19:51.770 -> 107
23:19:51.770 -> 108
23:19:51.770 -> 109
23:19:51.770 -> 110
23:19:51.770 -> 111
23:19:51.770 -> 112
23:19:51.770 -> 113
23:19:51.770 -> 114
23:19:51.770 -> 115
23:19:51.770 -> 116
23:19:51.770 -> 117
23:19:51.770 -> 118
23:19:51.770 -> 119
23:19:51.770 -> 120
23:19:51.770 -> 121
23:19:51.770 -> 122
23:19:51.770 -> 123
23:19:51.770 -> 124
23:19:51.770 -> 125
23:19:51.770 -> 126
23:19:51.770 -> 127
23:19:51.770 -> 128
23:19:51.770 -> 129
23:19:51.770 -> 130
23:19:51.770 -> 131
23:19:51.770 -> 132
23:19:51.770 -> 133
23:19:51.770 -> 134
23:19:51.770 -> 135
23:19:51.770 -> 136
23:19:51.770 -> 137
23:19:51.770 -> 138
23:19:51.770 -> 139
23:19:51.770 -> 140
23:19:51.770 -> 141
23:19:51.770 -> 142
23:19:51.770 -> 143
23:19:51.770 -> 144
23:19:51.770 -> 145
23:19:51.770 -> 146
23:19:51.770 -> 147
23:19:51.770 -> 148
23:19:51.770 -> 149
23:19:51.770 -> 150
23:19:51.770 -> 151
23:19:51.770 -> 152
23:19:51.770 -> 153
23:19:51.770 -> 154
23:19:51.770 -> 155
23:19:51.770 -> 156
23:19:51.770 -> 157
23:19:51.770 -> 158
23:19:51.770 -> 159
23:19:51.770 -> 160
23:19:51.770 -> 161
23:19:51.770 -> 162
23:19:51.770 -> 163
23:19:51.770 -> 164
23:19:51.770 -> 165
23:19:51.770 -> 166
23:19:51.770 -> 167
23:19:51.770 -> 168
23:19:51.770 -> 169
23:19:51.770 -> 170
23:19:51.770 -> 171
23:19:51.770 -> 172
23:19:51.770 -> 173
23:19:51.770 -> 174
23:19:51.770 -> 175
23:19:51.770 -> 176
23:19:51.770 -> 177
23:19:51.770 -> 178
23:19:51.770 -> 179
23:19:51.770 -> 180
23:19:51.770 -> 181
23:19:51.770 -> 182
23:19:51.770 -> 183
23:19:51.770 -> 184
23:19:51.770 -> 185
23:19:51.770 -> 186
23:19:51.770 -> 187
23:19:51.770 -> 188
23:19:51.770 -> 189
23:19:51.770 -> 190
23:19:51.770 -> 191
23:19:51.770 -> 192
23:19:51.770 -> 193
23:19:51.770 -> 194
23:19:51.770 -> 195
23:19:51.770 -> 196
23:19:51.770 -> 197
23:19:51.770 -> 198
23:19:51.770 -> 199
23:19:51.770 -> 200
23:19:51.770 -> 201
23:19:51.770 -> 202
23:19:51.770 -> 203
23:19:51.770 -> 204
23:19:51.770 -> 205
23:19:51.770 -> 206
23:19:51.770 -> 207
23:19:51.770 -> 208
23:19:51.770 -> 209
23:19:51.770 -> 210
23:19:51.770 -> 211
23:19:51.770 -> 212
23:19:51.770 -> 213
23:19:51.770 -> 214
23:19:51.770 -> 215
23:19:51.770 -> 216
23:19:51.770 -> 217
23:19:51.770 -> 218
23:19:51.770 -> 219
23:19:51.770 -> 220
23:19:51.770 -> 221
23:19:51.770 -> 222
23:19:51.770 -> 223
23:19:51.770 -> 224
23:19:51.770 -> 225
23:19:51.770 -> 226
23:19:51.770 -> 227
23:19:51.770 -> 228
23:19:51.770 -> 229
23:19:51.770 -> 230
23:19:51.770 -> 231
23:19:51.770 -> 232
23:19:51.770 -> 233
23:19:51.770 -> 234
23:19:51.770 -> 235
23:19:51.770 -> 236
23:19:51.770 -> 237
23:19:51.770 -> 238
23:19:51.770 -> 239
23:19:51.770 -> 240
23:19:51.770 -> 241
23:19:51.770 -> 242
23:19:51.770 -> 243
23:19:51.770 -> 244
23:19:51.770 -> 245
23:19:51.770 -> 246
23:19:51.770 -> 247
23:19:51.770 -> 248
23:19:51.770 -> 249
23:19:51.770 -> 250
23:19:51.770 -> 251
23:19:51.770 -> 252
23:19:51.770 -> 253
23:19:51.770 -> 254
23:19:51.770 -> 255
23:19:51.770 -> 256
23:19:51.770 -> 257
23:19:51.770 -> 258
23:19:51.770 -> 259
23:19:51.770 -> 260
23:19:51.770 -> 261
23:19:51.770 -> 262
23:19:51.770 -> 263
23:19:51.770 -> 264
23:19:51.770 -> 265
23:19:51.770 -> 266
23:19:51.770 -> 267
23:19:51.770 -> 268
23:19:51.770 -> 269
23:19:51.770 -> 270
23:19:51.770 -> 271
23:19:51.770 -> 272
23:19:51.770 -> 273
23:19:51.770 -> 274
23:19:51.770 -> 275
23:19:51.770 -> 276
23:19:51.770 -> 277
23:19:51.770 -> 278
23:19:51.770 -> 279
23:19:51.770 -> 280
23:19:51.770 -> 281
23:19:51.770 -> 282
23:19:51.770 -> 283
23:19:51.770 -> 284
23:19:51.770 -> 285
23:19:51.770 -> 286
23:19:51.770 -> 287
23:19:51.770 -> 288
23:19:51.770 -> 289
23:19:51.770 -> 290
23:19:51.770 -> 291
23:19:51.770 -> 292
23:19:51.770 -> 293
23:19:51.770 -> 294
23:19:51.770 -> 295
23:19:51.770 -> 296
23:19:51.770 -> 297
23:19:51.770 -> 298
23:19:51.770 -> 299
23:19:51.770 -> 300
23:19:51.770 -> 301
23:19:51.770 -> 302
23:19:51.770 -> 303
23:19:51.770 -> 304
23:19:51.770 -> 305
23:19:51.770 -> 306
23:19:51.770 -> 307
23:19:51.770 -> 308
23:19:51.770 -> 309
23:19:51.770 -> 310
23:19:51.770 -> 311
23:19:51.770 -> 312
23:19:51.770 -> 313
23:19:51.770 -> 314
23:19:51.770 -> 315
23:19:51.770 -> 316
23:19:51.770 -> 317
23:19:51.770 -> 318
23:19:51.770 -> 319
23:19:51.770 -> 320
23:19:51.770 -> 321
23:19:51.770 -> 322
23:19:51.770 -> 323
23:19:51.770 -> 324
23:19:51.770 -> 325
23:19:51.770 -> 326
23:19:51.770 -> 327
23:19:51.770 -> 328
23:19:51.770 -> 329
23:19:51.770 -> 330
23:19:51.770 -> 331
23:19:51.770 -> 332
23:19:51.770 -> 333
23:19:51.770 -> 334
23:19:51.770 -> 335
23:19:51.770 -> 336
23:19:51.770 -> 337
23:19:51.770 -> 338
23:19:51.770 -> 339
23:19:51.770 -> 340
23:19:51.770 -> 341
23:19:51.770 -> 342
23:19:51.770 -> 343
23:19:51.770 -> 344
23:19:51.770 -> 345
23:19:51.770 -> 346
23:19:51.770 -> 347
23:19:51.770 -> 348
23:19:51.770 -> 349
23:19:51.770 -> 350
23:19:51.770 -> 351
23:19:51.770 -> 352
23:19:51.770 -> 353
23:19:51.770 -> 354
23:19:51.770 -> 355
23:19:51.770 -> 356
23:19:51.770 -> 357
23:19:51.770 -> 358
23:19:51.770 -> 359
23:19:51.770 -> 360
23:19:51.770 -> 361
23:19:51.770 -> 362
23:19:51.770 -> 363
23:19:51.770 -> 364
23:19:51.770 -> 365
23:19:51.770 -> 366
23:19:51.770 -> 367
23:19:51.770 -> 368
23:19:51.770 -> 369
23:19:51.770 -> 370
23:19:51.770 -> 371
23:19:51.770 -> 372
23:19:51.770 -> 373
23:19:51.770 -> 374
23:19:51.770 -> 375
23:19:51.770 -> 376
23:19:51.770 -> 377
23:19:51.770 -> 378
23:19:51.770 -> 379
23:19:51.770 -> 380
23:19:51.770 -> 381
23:19:51.770 -> 382
23:19:51.770 -> 383
23:19:51.770 -> 384
23:19:51.770 -> 385
23:19:51.770 -> 386
23:19:51.770 -> 387
23:19:51.770 -> 388
23:19:51.770 -> 389
23:19:51.770 -> 390
23:19:51.770 -> 391
23:19:51.770 -> 392
23:19:51.770 -> 393
23:19:51.770 -> 394
23:19:51.770 -> 395
23:19:51.770 -> 396
23:19:51.770 -> 397
23:19:51.770 -> 398
23:19:51.770 -> 399
23:19:51.770 -> 400
23:19:51.770 -> 401
23:19:51.770 -> 402
23:19:51.770 -> 403
23:19:51.770 -> 404
23:19:51.770 -> 405
23:19:51.770 -> 406
23:19:51.770 -> 407
23:19:51.770 -> 408
23:19:51.770 -> 409
23:19:51.770 -> 410
23:19:51.770 -> 411
23:19:51.770 -> 412
23:19:51.770 -> 413
23:19:51.770 -> 414
23:19:51.770 -> 415
23:19:51.770 -> 416
23:19:51.770 -> 417
23:19:51.770 -> 418
23:19:51.770 -> 419
23:19:51.770 -> 420
23:19:51.770 -> 421
23:19:51.770 -> 422
23:19:51.770 -> 423
23:19:51.770 -> 424
23:19:51.770 -> 425
23:19:51.770 -> 426
23:19:51.770 -> 427
23:19:51.770 -> 428
23:19:51.770 -> 429
23:19:51.770 -> 430
23:19:51.770 -> 431
23:19:51.770 -> 432
23:19:51.770 -> 433
23:19:51.770 -> 434
23:19:51.770 -> 435
23:19:51.770 -> 436
23:19:51.770 -> 437
23:19:51.770 -> 438
23:19:51.770 -> 439
23:19:51.770 -> 440
23:19:51.770 -> 441
23:19:51.770 -> 442
23:19:51.770 -> 443
23:19:51.770 -> 444
23:19:51.770 -> 445
23:19:51.770 -> 446
23:19:51.770 -> 447
23:19:51.770 -> 448
23:19:51.770 -> 449
23:19:51.770 -> 450
23:19:51.770 -> 451
23:19:51.770 -> 452
23:19:51.770 -> 453
23:19:51.770 -> 454
23:19:51.770 -> 455
23:19:51.770 -> 456
23:19:51.770 -> 457
23:19:51.770 -> 458
23:19:51.770 -> 459
23:19:51.770 -> 460
23:19:51.770 -> 461
23:19:51.770 -> 462
23:19:51.770 -> 463
23:19:51.770 -> 464
23:19:51.770 -> 465
23:19:51.770 -> 466
23:19:51.770 -> 467
23:19:51.770 -> 468
23:19:51.770 -> 469
23:19:51.770 -> 470
23:19:51.770 -> 471
23:19:51.770 -> 472
23:19:51.770 -> 473
23:19:51.770 -> 474
23:19:51.770 -> 475
23:19:51.770 -> 476
23:19:51.770 -> 477
23:19:51.770 -> 478
23:19:51.770 -> 479
23:19:51.770 -> 480
23:19:51.770 -> 481
23:19:51.770 -> 482
23:19:51.770 -> 483
23:19:51.770 -> 484
23:19:51.770 -> 485
23:19:51.770 -> 486
23:19:51.770 -> 487
23:19:51.770 -> 488
23:19:51.770 -> 489
23:19:51.770 -> 490
23:19:51.770 -> 491
23:19:51.770 -> 492
23:19:51.770 -> 493
23:19:51.770 -> 494
23:19:51.770 -> 495
23:19:51.770 -> 496
23:19:51.770 -> 497
23:19:51.770 -> 498
23:19:51.770 -> 499
23:19:51.770 -> 500
23:19:51.770 -> 501
23:19:51.770 -> 502
23:19:51.770 -> 503
23:19:51.770 -> 504
23:19:51.770 -> 505
23:19:51.770 -> 506
23:19:51.770 -> 507
23:19:51.770 -> 508
23:19:51.770 -> 509
23:19:51.770 -> 510
23:19:51.770 -> 511
23:19:51.770 -> 512
23:19:51.770 -> 513
23:19:51.770 -> 514
23:19:51.770 -> 515
23:19:51.770 -> 516
23:19:51.770 -> 517
23:19:51.770 -> 518
23:19:51.770 -> 519
23:19:51.770 -> 520
23:19:51.770 -> 521
23:19:51.770 -> 522
23:19:51.770 -> 523
23:19:51.770 -> 524
23:19:51.770 -> 525
23:19:51.770 -> 526
23:19:51.770 -> 527
23:19:51.770 -> 528
23:19:51.770 -> 529
23:19:51.770 -> 530
23:19:51.770 -> 531
23:19:51.770 -> 532
23:19:51.770 -> 533
23:19:51.770 -> 534
23:19:51.770 -> 535
23:19:51.770 -> 536
23:19:51.770 -> 537
23:19:51.770 -> 538
23:19:51.770 -> 539
23:19:51.770 -> 540
23:19:51.770 -> 541
23:19:51.770 -> 542
23:19:51.770 -> 543
23:19:51.770 -> 544
23:19:51.770 -> 545
23:19:51.770 -> 546
23:19:51.770 -> 547
23:19:51.770 -> 548
23:19:51.770 -> 549
23:19:51.770 -> 550
23:19:51.770 -> 551
23:19:51.770 -> 552
23:19:51.770 -> 553
23:19:51.770 -> 554
23:19:51.770 -> 555
23:19:51.770 -> 556
23:19:51.770 -> 557
23:19:51.770 -> 558
23:19:51.770 -> 559
23:19:51.770 -> 560
23:19:51.770 -> 561
23:19:51.770 -> 562
23:19:51.770 -> 563
23:19:51.770 -> 564
23:19:51.770 -> 565
23:19:51.770 -> 566
23:19:51.770 -> 567
23:19:51.770 -> 568
23:19:51.770 -> 569
23:19:51.770 -> 570
23:19:51.770 -> 571
23:19:51.770 -> 572
23:19:51.770 -> 573
23:19:51.770 -> 574
23:19:51.770 -> 575
23:19:51.770 -> 576
23:19:51.770 -> 577
23:19:51.770 -> 578
23:19:51.770 -> 579
23:19:51.770 -> 580
23:19:51.770 -> 581
23:19:51.770 -> 582
23:19:51.770 -> 583
23:19:51.770 -> 584
23:19:51.770 -> 585
23:19:51.770 -> 586
23:19:51.770 -> 587
23:19:51.770 -> 588
23:19:51.770 -> 589
23:19:51.770 -> 590
23:19:51.770 -> 591
23:19:51.770 -> 592
23:19:51.770 -> 593
23:19:51.770 -> 594
23:19:51.770 -> 595
23:19:51.770 -> 596
23:19:51.770 -> 597
23:19:51.770 -> 598
23:19:51.770 -> 599
23:19:51.770 -> 600
23:19:51.770 -> 601
23:19:51.770 -> 602
23:19:51.770 -> 603
23:19:51.770 -> 604
23:19:51.770 -> 605
23:19:51.770 -> 606
23:19:51.770 -> 607
23:19:51.770 -> 608
23:19:51.770 -> 609
23:19:51.770 -> 610
23:19:51.770 -> 611
23:19:51.770 -> 612
23:19:51.770 -> 613
23:19:51.770 -> 614
23:19:51.770 -> 615
23:19:51.770 -> 616
23:19:51.770 -> 617
23:19:51.770 -> 618
23:19:51.770 -> 619
23:19:51.770 -> 620
23:19:51.770 -> 621
23:19:51.770 -> 622
23:19:51.770 -> 623
23:19:51.770 -> 624
23:19:51.770 -> 625
23:19:51.770 -> 626
23:19:51.770 -> 627
23:19:51.770 -> 628
23:19:51.770 -> 629
23:19:51.770 -> 630
23:19:51.770 -> 631
23:19:51.770 -> 632
23:19:51.770 -> 633
23:19:51.770 -> 634
23:19:51.770 -> 635
23:19:51.770 -> 636
23:19:51.770 -> 637
23:19:51.770 -> 638
23:19:51.770 -> 639
23:19:51.770 -> 640
23:19:51.770 -> 641
23:19:51.770 -> 642
23:19:51.770 -> 643
23:19:51.770 -> 644
23:19:51.770 -> 645
23:19:51.770 -> 646
23:19:51.770 -> 647
23:19:51.770 -> 648
23:19:51.770 -> 649
23:19:51.770 -> 650
23:19:51.770 -> 651
23:19:51.770 -> 652
23:19:51.770 -> 653
23:19:51.770 -> 654
23:19:51.770 -> 655
23:19:51.770 -> 656
23:19:51.770 -> 657
23:19:51.770 -> 658
23:19:51.770 -> 659
23:19:51.770 -> 660
23:19:51.770 -> 661
23:19:51.770 -> 662
23:19:51.770 -> 663
23:19:51.770 -> 664
23:19:51.770 -> 665
23:19:51.770 -> 666
23:19:51.770 -> 667
23:19:51.770 -> 668
23:19:51.770 -> 669
23:19:51.770 -> 670
23:19:51.770 -> 671
23:19:51.770 -> 672
23:19:51.770 -> 673
23:19:51.770 -> 674
23:19:51.770 -> 675
23:19:51.770 -> 676
23:19:51.770 -> 677
23:19:51.770 -> 678
23:19:51.770 -> 679
23:19:51.770 -> 680
23:19:51.770 -> 681
23:19:51.770 -> 682
23:19:51.770 -> 683
23:19:51.770 -> 684
23:19:51.770 -> 685
23:19:51.770 -> 686
23:19:51.770 -> 687
23:19:51.770 -> 688
23:19:51.770 -> 689
23:19:51.770 -> 690
23:19:51.770 -> 691
23:19:51.770 -> 692
23:19:51.770 -> 693
23:19:51.770 -> 694
23:19:51.770 -> 695
23:19:51.770 -> 696
23:19:51.770 -> 697
23:19:51.770 -> 698
23:19:51.770 -> 699
23:19:51.770 -> 700
23:19:51.770 -> 701
23:19:51.770 -> 702
23:19:51.770 -> 703
23:19:51.770 -> 704
23:19:51.770 -> 705
23:19:51.770 -> 706
23:19:51.770 -> 707
23:19:51.770 -> 708
23:19:51.770 -> 709
23:19:51.770 -> 710
23:19:51.770 -> 711
23:19:51.770 -> 712
23:19:51.770 -> 713
23:19:51.770 -> 714
23:19:51.770 -> 715
23:19:51.770 -> 716
23:19:51.770 -> 717
23:19:51.770 -> 718
23:19:51.770 -> 719
23:19:51.770 -> 720
23:19:51.770 -> 721
23:19:51.770 -> 722
23:19:51.770 -> 723
23:19:51.770 -> 724
23:19:51.770 -> 725
23:19:51.770 -> 726
23:19:51.770 -> 727
23:19:51.770 -> 728
23:19:51.770 -> 729
23:19:51.770 -> 730
23:19:51.770 -> 731
23:19:51.770 -> 732
23:19:51.770 -> 733
23:19:51.770 -> 734
23:19:51.770 -> 735
23:19:51.770 -> 736
23:19:51.770 -> 737
23:19:51.770 -> 738
23:19:51.770 -> 739
23:19:51.770 -> 740
23:19:51.770 -> 741
23:19:51.770 -> 742
23:19:51.770 -> 743
23:19:51.770 -> 744
23:19:51.770 -> 745
23:19:51.770 -> 746
23:19:51.770 -> 747
23:19:51.770 -> 748
23:19:51.770 -> 749
23:19:51.770 -> 750
23:19:51.770 -> 751
23:19:51.770 -> 752
23:19:51.770 -> 753
23:19:51.770 -> 754
23:19:51.770 -> 755
23:19:51.770 -> 756
23:19:51.770 -> 757
23:19:51.770 -> 758
23:19:51.770 -> 759
23:19:51.770 -> 760
23:19:51.770 -> 761
23:19:51.770 -> 762
23:19:51.770 -> 763
23:19:51.770 -> 764
23:19:51.770 -> 765
23:19:51.770 -> 766
23:19:51.770 -> 767
23:19:51.770 -> 768
23:19:51.770 -> 769
23:19:51.770 -> 770
23:19:51.770 -> 771
23:19:51.770 -> 772
23:19:51.770 -> 773
23:19:51.770 -> 774
23:19:51.770 -> 775
23:19:51.770 -> 776
23:19:51.770 -> 777
23:19:51.770 -> 778
23:19:51.770 -> 779
23:19:51.770 -> 780
23:19:51.770 -> 781
23:19:51.770 -> 782
23:19:51.770 -> 783
23:19:51.770 -> 784
23:19:51.770 -> 785
23:19:51.770 -> 786
23:19:51.770 -> 787
23:19:51.770 -> 788
23:19:51.770 -> 789
23:19:51.770 -> 790
23:19:51.770 -> 791
23:19:51.770 -> 792
23:19:51.770 -> 793
23:19:51.770 -> 794
23:19:51.770 -> 795
23:19:51.770 -> 796
23:19:51.770 -> 797
23:19:51.770 -> 798
23:19:51.770 -> 799
23:19:51.770 -> 800
23:19:51.770 -> 801
23:19:51.770 -> 802
23:19:51.770 -> 803
23:19:51.770 -> 804
23:19:51.770 -> 805
23:19:51.770 -> 806
23:19:51.770 -> 807
23:19:51.770 -> 808
23:19:51.770 -> 809
23:19:51.770 -> 810
23:19:51.770 -> 811
23:19:51.770 -> 812
23:19:51.770 -> 813
23:19:51.770 -> 814
23:19:51.770 -> 815
23:19:51.770 -> 816
23:19:51.770 -> 817
23:19:51.770 -> 818
23:19:51.770 -> 819
23:19:51.770 -> 820
23:19:51.770 -> 821
23:19:51.770 -> 822
23:19:51.770 -> 823
23:19:51.770 -> 824
23:19:51.770 -> 825
23:19:51.770 -> 826
23:19:51.770 -> 827
23:19:51.770 -> 828
23:19:51.770 -> 829
23:19:51.770 -> 830
23:19:51.770 -> 831
23:19:51.770 -> 832
23:19:51.770 -> 833
23:19:51.770 -> 834
23:19:51.770 -> 835
23:19:51.770 -> 836
23:19:51.770 -> 837
23:19:51.770 -> 838
23:19:51.770 -> 839
23:19:51.770 -> 840
23:19:51.770 -> 841
23:19:51.770 -> 842
23:19:51.770 -> 843
23:19:51.770 -> 844
23:19:51.770 -> 845
23:19:51.770 -> 846
23:19:51.770 -> 847
23:19:51.770 -> 848
23:19:51.770 -> 849
23:19:51.770 -> 850
23:19:51.770 -> 851
23:19:51.770 -> 852
23:19:51.770 -> 853
23:19:51.770 -> 854
23:19:51.770 -> 855
23:19:51.770 -> 856
23:19:51.770 -> 857
23:19:51.770 -> 858
23:19:51.770 -> 859
23:19:51.770 -> 860
23:19:51.770 -> 861
23:19:51.770 -> 862
23:19:51.770 -> 863
23:19:51.770 -> 864
23:19:51.770 -> 865
23:19:51.770 -> 866
23:19:51.770 -> 867
23:19:51.770 -> 868
23:19:51.770 -> 869
23:19:51.770 -> 870
23:19:51.770 -> 871
23:19:51.770 -> 872
23:19:51.770 -> 873
23:19:51.770 -> 874
23:19:51.770 -> 875
23:19:51.770 -> 876
23:19:51.770 -> 877
23:19:51.770 -> 878
23:19:51.770 -> 879
23:19:51.770 -> 880
23:19:51.770 -> 881
23:19:51.770 -> 882
23:19:51.770 -> 883
23:19:51.770 -> 884
23:19:51.770 -> 885
23:19:51.770 -> 886
23:19:51.770 -> 887
23:19:51.770 -> 888
23:19:51.770 -> 889
23:19:51.770 -> 890
23:19:51.770 -> 891
23:19:51.770 -> 892
23:19:51.770 -> 893
23:19:51.770 -> 894
23:19:51.770 -> 895
23:19:51.770 -> 896
23:19:51.770 -> 897
23:19:51.770 -> 898
23:19:51.770 -> 899
23:19:51.770 -> 900
23:19:51.770 -> 901
23:19:51.770 -> 902
23:19:51.770 -> 903
23:19:51.770 -> 904
23:19:51.770 -> 905
23:19:51.770 -> 906
23:19:51.770 -> 907
23:19:51.770 -> 908
23:19:51.770 -> 909
23:19:51.770 -> 910
23:19:51.770 -> 911
23:19:51.770 -> 912
23:19:51.770 -> 913
23:19:51.770 -> 914
23:19:51.770 -> 915
23:19:51.770 -> 916
23:19:51.770 -> 917
23:19:51.770 -> 918
23:19:51.770 -> 919
23:19:51.770 -> 920
23:19:51.770 -> 921
23:19:51.770 -> 922
23:19:51.770 -> 923
23:19:51.770 -> 924
23:19:51.770 -> 925
23:19:51.770 -> 926
23:19:51.770 -> 927
23:19:51.770 -> 928
23:19:51.770 -> 929
23:19:51.770 -> 930
23:19:51.770 -> 931
23:19:51.770 -> 932
23:19:51.770 -> 933
23:19:51.770 -> 934
23:19:51.770 -> 935
23:19:51.770 -> 936
23:19:51.770 -> 937
23:19:51.804 -> 938
23:19:51.804 -> 939
23:19:51.804 -> 940
23:19:51.804 -> 941
23:19:51.804 -> 942
23:19:51.804 -> 943
23:19:51.804 -> 944
23:19:51.804 -> 945
23:19:51.804 -> 946
23:19:51.804 -> 947
23:19:51.804 -> 948
23:19:51.804 -> 949
23:19:51.804 -> 950
23:19:51.804 -> 951
23:19:51.804 -> 952
23:19:51.804 -> 953
23:19:51.804 -> 954
23:19:51.804 -> 955
23:19:51.804 -> 956
23:19:51.804 -> 957
23:19:51.804 -> 958
23:19:51.804 -> 959
23:19:51.804 -> 960
23:19:51.804 -> 961
23:19:51.804 -> 962
23:19:51.804 -> 963
23:19:51.804 -> 964
23:19:51.804 -> 965
23:19:51.804 -> 966
23:19:51.804 -> 967
23:19:51.804 -> 968
23:19:51.804 -> 969
23:19:51.804 -> 970
23:19:51.804 -> 971
23:19:51.804 -> 972
23:19:51.804 -> 973
23:19:51.804 -> 974
23:19:51.804 -> 975
23:19:51.804 -> 976
23:19:51.804 -> 977
23:19:51.804 -> 978
23:19:51.804 -> 979
23:19:51.804 -> 980
23:19:51.804 -> 981
23:19:51.804 -> 982
23:19:51.804 -> 983
23:19:51.804 -> 984
23:19:51.804 -> 985
23:19:51.804 -> 986
23:19:51.804 -> 987
23:19:51.804 -> 988
23:19:51.804 -> 989
23:19:51.804 -> 990
23:19:51.804 -> 991
23:19:51.804 -> 992
23:19:51.804 -> 993
23:19:51.804 -> 994
23:19:51.804 -> 995
23:19:51.804 -> 996
23:19:51.804 -> 997
23:19:51.804 -> 998
23:19:51.804 -> 999
23:19:51.804 -> 1000
23:19:51.804 -> 1001
23:19:51.804 -> 1002
23:19:51.804 -> 1003
23:19:51.804 -> 1004
23:19:51.804 -> 1005
23:19:51.804 -> 1006
23:19:51.804 -> 1007
23:19:51.804 -> 1008
23:19:51.804 -> 1009
23:19:51.804 -> 1010
23:19:51.804 -> 1011
23:19:51.804 -> 1012
23:19:51.804 -> 1013
23:19:51.804 -> 1014
23:19:51.804 -> 1015
23:19:51.804 -> 1016
23:19:51.804 -> 1017
23:19:51.804 -> 1018
23:19:51.804 -> 1019
23:19:51.804 -> 1020
23:19:51.804 -> 1021
23:19:51.804 -> 1022
23:19:51.837 -> Last byte of buffer
23:19:51.837 -> 255

@technoblogy
Copy link
Owner

Sorry, I'm not sure what else to suggest.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 3, 2020

Thank you. I'll keep debugging. Currently trying to produce a minimal saveimage/loadimage and see why it bugs out.
writes.log

writes seem to be fine at least.

@chrysophylax
Copy link
Author

Oh christ, I found the error! Once I cut down the code to being a very small portion everywhere I started staring at FlashReadByte and ... I was sending in the pointer (addr) instead of its value to eeprom_buffered_read_byte so that was exploding somewhere.

Corrected to uint8_t data = eeprom_buffered_read_byte((uint32_t) *addr);

@chrysophylax
Copy link
Author

chrysophylax commented Dec 3, 2020

OK, one small issue. It seems the eeprom does not persist over reboots. I flash the ulisp image with the boot0 jumper set to 1, then set it to 0, reset the board and connect over serial to a ulisp prompt. Here I run

(defvar hello "Hello World from EEPROM!")
(defun hello-world () hello)
(save-image 'hello-world)

which writes a bunch of stuff. If I run (load-image) without resetting the board it works as well.
However, when I reset the board, it runs load-image but it does not seem find anything in the buffer despite having run eeprom_buffer_fill. Weird.

@chrysophylax
Copy link
Author

#include <EEPROM.h>
#define DATA_LENGTH E2END

void setup() {
  Serial.begin(115200);
  while(!Serial) {;;} 
  Serial.write("Old contents of buffer pre-reset are:\n"); 
  eeprom_buffer_fill();
  for (uint16_t i=0; i < E2END; i++){
    uint8_t d = eeprom_buffered_read_byte(i);
    Serial.print("flash-read-from-buffer: 0x");Serial.print(i, HEX); Serial.print("->0x"); Serial.println(d,HEX);
  }
  // Fill the EEPROM buffer in memory with data
  for (uint16_t i = 0; i < DATA_LENGTH; i++) {
    eeprom_buffered_write_byte(i, (uint8_t) 255);
  }

  // Copy the data from the buffer to the flash
  eeprom_buffer_flush();

  // Copy the data from the flash to the buffer
  eeprom_buffer_fill();

  // Print the last byte of the current buffer 
  Serial.println("Wrote 0xFF to all available bytes in memory, last byte was:");
  Serial.println(eeprom_buffered_read_byte(DATA_LENGTH - 1));
}

void loop() {}

works across reboots. Weird.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 4, 2020

It works! Somewhat! I had to add the EEPROM offset that is used for roger's core's eeprom emu as a define so the stm32 eeprom layer picks it up for the API.

  1. Write a hello-world fun and save-image the workspace.
  2. reset occurs
  3. Run (load-image)
01:03:07.357 -> 1471> (load-image)
01:03:11.774 -> 28
01:03:11.774 -> 
01:03:11.774 -> 1454> (hello-world)
01:03:16.953 -> "Hello World from EEPROM!"

The issue seems to be that if we go above a certain size we bug up something and the MCU halts. I guess we only have 1023 bytes as E2END specifies. That doesn't let us save much sadly and I feel it is quite unfair RogerClark's core has 10240 bytes of memory and we have to deal with 1023. I found https:/STMicroelectronics/STM32CubeF1/blob/master/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c and will be reading it to see if we can get something.

I also got STM32CubeProgrammer running so I'll be trying to use that to debug some more.
Screenshot from 2020-12-04 01-26-38

@chrysophylax
Copy link
Author

chrysophylax commented Dec 4, 2020

OK, I think I figured out why I run out of space. It seems the little Blue Pills I got are all 64KB. That sucks.

EDIT: That's... not true. Wow. It presents itself as a 64 KB flash sized unit but looking into the flash memory manager I see an index of 0-127 of 1KB pages ranging from 0x08000000 to 0x0801FC00 and I am indeed able to write to the last page.
0x0801FC00

EDIT2: OK. It turns out FLASH_BASE_ADDRESS and the like are not user-overridable despite words to the contrary in the source so no matter what you do, you always write to the last 1 kB page of flash memory. I will have to hack something together that lets you pick which page to write to using the STM32 HAL. There is a lot of info.

@technoblogy
Copy link
Owner

Well done getting it to work! 1023 bytes of flash is better than nothing. A recent improvement I've made to the forthcoming release of uLisp is to only save the part of SymbolTable[] that's actually used, which will help.

I'd like to be able to update the STM32 version to use the official core, and remove references to Roger Clark's core from the documentation since it's no longer being supported. Do you think that's a good idea?

@chrysophylax
Copy link
Author

chrysophylax commented Dec 8, 2020

I think Roger Clark's core is ("unfortunately") still rather popular and has a lot of support for third-party libraries. Maybe people would still want it to run for that reason. Could be worth asking on the forum

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

Successfully merging this pull request may close these issues.

2 participants