-
Notifications
You must be signed in to change notification settings - Fork 16
/
openware-notes.txt
445 lines (326 loc) · 13.6 KB
/
openware-notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
-----------------------------------------------------------------
todo:
- refactor build files
- common top level build file
- make sure all output files end up in project Build directory
- refactor device.h files
-----------------------------------------------------------------
STM32F756ZG
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
STM32F439ZG
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
STM32F407ZGT6
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112k
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64k
NVRAM (xrw) : ORIGIN = 0x40024000, LENGTH = 4K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1M
-----------------------------------------------------------------
WM8731: I2S_MCLK not needed for Codec Master mode
OpenWare:
main.c:
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 168;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
PeriphClkInitStruct.PLLI2S.PLLI2SN = 50;
PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
__HAL_RCC_SPI2_CLK_ENABLE();
HAL_NVIC_SetPriority(SPI2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(SPI2_IRQn);
OwlWare:
#define PLL_M 8
#define PLL_N 336
#define PLL_P 2
#define PLL_Q 7
#define PLLI2S_N 258
#define PLLI2S_R 3
* I2S input clock(Hz) | 86000000
* To achieve the following I2S config: |
* - Master clock output (MCKO): ON |
* - Frame wide : 16bit |
* - Audio sampling freq (KHz) : 48 |
* - Error % : 0.0186 |
* - Prescaler Odd factor (ODD): 1 |
* - Linear prescaler (DIV) : 3 |
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
/* Configures the I2S clock source (I2SCLK). */
/* This function must be called before enabling the I2S APB clock. */
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
RCC_PLLI2SCmd(ENABLE);
/* Enable the CODEC_I2S peripheral clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
blocking TransmitReceive seems to work on RX (strange values)
HAL_I2S_Receive_DMA: no callbacks on RX
Transmit: time-outs
TransmitReceive_IT: underrun in TX
DACLRC / ADCLRC / LRCK 48khz
BCLK / SCLK 3.08MHz
ADCDAT / SDI data
DACDAT / SDO flat
Problems fixed by removing __HAL_I2S_ENABLE(&hi2s2) in Codec::reset()
-----------------------------------------------------------------
OwlPedal SRAM memory
OwlWare:
p.FSMC_AddressSetupTime = 3;
p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 6;
p.FSMC_BusTurnAroundDuration = 1;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_A;
OpenWare:
Timing.AddressSetupTime = 3;
Timing.AddressHoldTime = 1; // > 0, <= 15
Timing.DataSetupTime = 6;
Timing.BusTurnAroundDuration = 1;
Timing.CLKDivision = 2; // > 1, <= 16
Timing.DataLatency = 2; // > 1, <= 17
Timing.AccessMode = FSMC_ACCESS_MODE_A;
/* Set FSMC_NORSRAM device timing parameters */
tmpr |= (uint32_t)(Timing->AddressSetupTime |\
((Timing->AddressHoldTime) << 4U) |\
((Timing->DataSetupTime) << 8U) |\
((Timing->BusTurnAroundDuration) << 16U) |\
(((Timing->CLKDivision)-1U) << 20U) |\
(((Timing->DataLatency)-2U) << 24U) |\
(Timing->AccessMode));
__HAL_RCC_FSMC_CLK_ENABLE():
__IO uint32_t tmpreg = 0x00U; \
SET_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FSMCEN);\
/* Delay after an RCC peripheral clock enabling */ \
tmpreg = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FSMCEN);\
UNUSED(tmpreg); \
-----------------------------------------------------------------
todo:
/ pass in sample format in PV: 16/24bit, 24bit
/ change audio_bitdepth to audio_format
/ refactor OwlProgram/PatchProgram/SampleBuffer to allow different conversions depending on format
- pass in stack as available heap memory (for CCM / non-F7 platforms)
- check OWL2 sample format and conversion
- owl1 sram
- replace float div with mul in SampleBuffer conversions - check accuracy
-----------------------------------------------------------------
OWL2 80kHz 500mV on AINA
-----------------------------------------------------------------
Bootloader STM32F42x/3x
Bootloader activation Pattern 5:
Boot0(pin) = 1, Boot1(pin) = 0 and BFB2(bit) = 0
Boot0(pin) = 1, Boot1(pin) = 0 and BFB2 (bit) = 1
Boot0(pin) = 0, BFB2(bit) = 1 and both banks don’t contain valid code
BFB2: boot from bank 2
-----------------------------------------------------------------
note:
for all projects, check main.c and stm32xyz_it.c for common blocks, e.g.
SRAM / SDRAM initialisation
I2S / SAI initialisation and interrupts
uart / bus IDLE interrupts
USB stuff
-----------------------------------------------------------------
Alchemist / Wizard Reset loop
presets:
Fascination I to V
Granular Delay
Granular Delay
Granular Delay
FmDronePoly
DroneBox
Granular Delay and DroneBox both cause reset cycle when stored in patch slot 1
flash erase not working? needs unlocking?
-----------------------------------------------------------------
# reset
amidi -p hw:2 -S f07d527df7
# reset to bootloader
amidi -p hw:2 -S f07d527ef7
# erase flash storage
amidi -p hw:2 -S f07d5214f7
# erase resource 40
amidi -p hw:2 -S f07d52140000000028f7
# request resource 41
amidi -p hw:2 -S f07d52180000000029f7
# flash Wizard firmware
amidi -p hw:2 -s Wizard.syx
# set parameter A to value 63 on channel 0
amidi -p hw:1 -S b0143f
# request firmware configuration
amidi -p hw:1 -S b04303
# request firmware version
amidi -p hw:1 -S b04320
# request program message
amidi -p hw:1 -S b04322
# request device stats
amidi -p hw:1 -S b04323
# request program stats
amidi -p hw:1 -S b04324
# request bootloader version
amidi -p hw:1 -S b04325
# unlock bootloader
amidi -p hw:1 -S f07d5203424c30f7
# lock bootloader
amidi -p hw:1 -S f07d5203424c31f7
# request button status
amidi -p hw:1 -S b04319
# set button B1 on
amidi -p hw:1 -S b01b04
# set button B1 off
amidi -p hw:1 -S b01c04
# dump all messages received
amidi -p hw:1 -d -a
# send patch and run
amidi -p $OWLPORT -i 1 -s Ping_Pong_Lich.syx
amidi -p $OWLPORT -S f07d5212f7
# or store in slot 1
amidi -p $OWLPORT -S f07d52110000000001f7
OWLPORT=`amidi -l|grep OWL|sed 's/.*\(hw:.*\),.*/\1/g'`
-----------------------------------------------------------------
Record 2 seconds 48k 16bit stereo
arecord -D hw:1 -c 2 -r 48000 -f S16_LE out.wav
AUDIODEV=hw:1 rec out.wav
Playback
aplay -D hw:1 out.wav
AUDIODEV=hw:1 play out.wav
-----------------------------------------------------------------
#define VECT_TAB_OFFSET 0x00008000
cd MidiBoot
make PLATFORM=Alchemist CONFIG=Release clean all
-----------------------------------------------------------------
FirmwareSender -in Build/Alchemist.bin -flash `crc32 Build/Alchemist.bin` -save Alchemist.syx
FirmwareSender -in Build/Wizard.bin -flash `crc32 Build/Wizard.bin` -save Wizard.syx
-----------------------------------------------------------------
USB AUDIO + MIDI device descriptor
https://eleccelerator.com/usbdescreqparser/
4ch BioSignals w/o MIDI:
09026400020100803209040000000101000009240100011e0001010c2402010102000700000000092403020101000100090401000001020000090401010101020000072401020001000b24020107042001401f0009058101e00001000007250100000000
Focusrite Scarlett
0902600106010980fa080b00030100200009040000000101200309240100020865000008240a290307000a08240b2801290308112402020101002804000000000e0000060c240314010300022800000011240201010200280200000000120000001224060b01000000000000000000000000000c2403160101000b280000070904010000010220040904010102010220041024010200010100000004000000000e0624020104180705010d9001010825010000020800070581110400040904020000010220050904020101010220051024011600010100000002000000001206240201041807058225c8000108250100000208000904030000010100000924010001090001010904040002010300000724010001410006240201010006240202020c09240301030102010009240302040101010b090502020002000000052501010109058302000200000005250101030904050001ff01100d07058403400008
WireShark
[Expert Info (Error/Malformed): Malformed Packet (Exception occurred)]
https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/how-to-retrieve-information-about-a-usb-device
MS USB hardware verifier
https://www.usb.org/usb2tools
http://www.testusb.com/Ch8ck.html
-----------------------------------------------------------------
enable semihosting:
* remove C_SRC += libnosys_gnu.c in sources.mk
* add `end` symbol to linker
* add in main.c:
int main(void)
{
/* USER CODE BEGIN 1 */
initialise_monitor_handles(); // remove when not semi-hosting
Makefile owl2.mk:
-CPPFLAGS += --specs=nano.specs
+LDLIBS += -lc -lm
+LDLIBS += -lrdimon
+# CPPFLAGS += -specs=rdimon.specs
+LDFLAGS += --specs=nano.specs
-CPPFLAGS += -nostdlib -nostartfiles -fno-builtin -ffreestanding
* use openocd
* enable semi hosting in gdb:
debug: $(ELF)
@$(GDB) -ex "target extended-remote localhost:3333" -ex "monitor reset hard" -ex "monitor arm semihosting enable" -ex "load" $(ELF)
-----------------------------------------------------------------
To catch reset cycles due to buggy default patches
#define USE_BKPSRAM
in Cube, enable Timers/RTC clock source
define armex
printf "EXEC_RETURN (LR):\n",
info registers $lr
if ($lr & (0x4 == 0x4))
printf "Uses MSP 0x%x return.\n", $msp
set $armex_base = (uint32_t)$msp
else
printf "Uses PSP 0x%x return.\n", $psp
set $armex_base = (uint32_t)$psp
end
printf "xPSR 0x%x\n", *($armex_base+28)
printf "ReturnAddress 0x%x\n", *($armex_base+24)
printf "LR (R14) 0x%x\n", *($armex_base+20)
printf "R12 0x%x\n", *($armex_base+16)
printf "R3 0x%x\n", *($armex_base+12)
printf "R2 0x%x\n", *($armex_base+8)
printf "R1 0x%x\n", *($armex_base+4)
printf "R0 0x%x\n", *($armex_base)
printf "Return instruction:\n"
x/i *($armex_base+24)
printf "LR instruction:\n"
x/i *($armex_base+20)
end
-----------------------------------------------------------------
Wizard pin compatible devices:
STM32F777ZITx
STM32F767ZITx
STM32F767ZGTx
STM32F756ZGTx
STM32F746ZGTx
STM32F765ZGTx
...
Noctua pin compatible devices:
STM32F427VITx 256k SRAM, 2Mb FLASH, $6.70 @1k
STM32F446VETx 128k SRAM, 512k FLASH, $3.98 @1k
PE12 / pin 43 :
-----------------------------------------------------------------
Compiling with C++14 support with -std=gnu++14 can cause `operator delete(void*, size_t) undefined` errors.
-----------------------------------------------------------------
DC Offset removed with normalising filter
10Vpp sine input: -9.24dB, No signal: -80.9dB, SNR: 70.86dB
DC Offset removed with 48dB 10Hz hpf
10Vpp sine input: -9.23dB, No signal: -83.2dB, SNR: 73.97dB
20Vpp triangle not clipping
20Vpp sine -3.24dB
-----------------------------------------------------------------
todo:
- bootloader verify
- send and receive error messages
- send error messages without polling
- bootloader message with reason for bootloader mode (watchdog, magic, no/invalid firmware)
- disable all: sysex rule
- IWDG->KR = 0xaaaa only if watchog is enabled, otherwise it hangs
- fix Noctua bootloader
-----------------------------------------------------------------
Multi channel support
- fw initialises pv with 2 channels
- patch code checks how many channels the patch supports (requires static channel count in Patch)
- calls registerPatch() with max number of supported channels
- if possible and requested, fw changes pv to add more channels
- patch code calls patch ctor
-----------------------------------------------------------------
Create and upload resource from wav:
sox sample.wav -r 48k -c 1 -t f32 sample.raw
play -c 1 -r 48k -t f32 sample.raw
FirmwareSender -in sample.raw -out "OWL*" -name "sample.wav"
-----------------------------------------------------------------
H7 ADC:
set Scan enable, Continuous enable, Conversion End of sequence, and ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR
-----------------------------------------------------------------
ABFSR 0x04: AHBP busfault
-----------------------------------------------------------------
Dynamic module / code loading with Position Independent Code / Executables PIC / PIE
https://github.com/rgujju/STM32-projects/tree/master/got_plt
https://community.arm.com/support-forums/f/architectures-and-processors-forum/45919/gcc-does-not-generate-correct-code-while-building-pic
https://systemoverlord.com/2017/03/19/got-and-plt-for-pwning.html
https://reverseengineering.stackexchange.com/questions/1992/what-is-plt-got
-----------------------------------------------------------------
CPPFLAGS += -fdata-sections -ffunction-sections
Required to compile without missing (unused) symbols
-----------------------------------------------------------------
USB audio:
- pre fx
- post fx
- interlace
[usb] -| |- [usb]
+- fx -+
[adc] -| |- [dac]
e.g. 4ch adc/dac, 4ch usb tx/rx, 8 ch fx
-----------------------------------------------------------------
todo:
- use (if possible) HAL_UARTEx_ReceiveToIdle_DMA
- make USB Audio interface optional / configurable
-----------------------------------------------------------------
DFU bootloader start address:
STM32F40x/41x: 0x1FFF0000
STM32F42x/43x: 0x1FFF0000
STM32H74/5x: 0x1FF09800
-----------------------------------------------------------------