Skip to content

Commit a7ad0c2

Browse files
committed
mod,added: READMEs
1 parent ac5bcaf commit a7ad0c2

6 files changed

Lines changed: 883 additions & 99 deletions

File tree

README.html

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
2+
<html><head>
3+
<meta https-equiv="Content-Type" content="text/html; charset=utf-8">
4+
<link
5+
href="https://unpkg.com/@primer/css@^16.0.0/dist/primer.css"
6+
rel="stylesheet"
7+
/>
8+
<link rel="stylesheet alternate"
9+
href="https://cdn.jsdelivr.net/gh/primer/github-syntax-light@master/lib/github-light.css" id="light-hl">
10+
<link rel="stylesheet alternate"
11+
href="https://cdn.jsdelivr.net/gh/primer/github-syntax-dark@master/lib/github-dark.css" id="dark-hl">
12+
13+
<title>PCM Wave Player Super Lite with Nim language on STM32 MCUs</title>
14+
</head>
15+
16+
<body id="markdown-body" data-color-mode="light" data-dark-theme="light">
17+
<div
18+
class="
19+
Box
20+
md
21+
js-code-block-container
22+
Box--responsive
23+
container-xl
24+
px-3 px-md-4 px-lg-5
25+
mt-5
26+
"
27+
id="content"
28+
>
29+
<div class="Box-body px-5 pb-5">
30+
<div class="d-flex flex-column flex-sm-row-reverse">
31+
<div>
32+
<button id="theme-button" class="btn" type="button">
33+
<span
34+
id="theme-icon"
35+
class="iconify"
36+
data-icon="octicon:sun-16"
37+
></span>
38+
</button>
39+
</div>
40+
</div>
41+
<article class="markdown-body entry-content container-lg" itemprop="text">
42+
43+
44+
<ul>
45+
<li>
46+
<a href="#user-content-pcm-wave-player-super-lite-with-nim-language-on-stm32-mcus">PCM Wave Player Super Lite with Nim language on STM32 MCUs</a>
47+
<ul>
48+
<li><a href="#user-content-supported-boardmcu">Supported Board/MCU</a></li>
49+
<li><a href="#user-content-supported-sd-card">Supported SD card</a></li>
50+
<li><a href="#user-content-supported-pcm-format">Supported PCM Format</a></li>
51+
<li><a href="#user-content-defalut-action">Defalut action</a></li>
52+
<li><a href="#user-content-hardware-settingschematic-16bit-sound-resolution">Hardware setting/Schematic: (16bit sound resolution)</a></li>
53+
<li><a href="#user-content-sd-card-connection">SD Card connection</a></li>
54+
<li><a href="#user-content-pwm-output-port">PWM output port</a></li>
55+
<li><a href="#user-content-led-indicator">LED indicator</a></li>
56+
<li><a href="#user-content-nim-compiler">Nim compiler</a></li>
57+
<li><a href="#user-content-c-compiler-arm-none-eabi-gcc">C compiler: arm-none-eabi-gcc</a></li>
58+
<li><a href="#user-content-compiling-source-code">Compiling source code</a></li>
59+
<li><a href="#user-content-generated-files-are">Generated files are</a></li>
60+
<li><a href="#user-content-output-music-filename--through-uart-port">Output music filename through UART port</a></li>
61+
<li><a href="#user-content-simple-less-bits-mode">Simple less bits mode</a></li>
62+
<li><a href="#user-content-pursue-small-code-size">Pursue small code size</a></li>
63+
<li><a href="#user-content-other-links">Other links</a></li>
64+
</ul>
65+
</li>
66+
</ul>
67+
68+
<h3>
69+
<a id="user-content-pcm-wave-player-super-lite-with-nim-language-on-stm32-mcus" class="anchor" href="#pcm-wave-player-super-lite-with-nim-language-on-stm32-mcus" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>PCM Wave Player Super Lite with Nim language on STM32 MCUs</h3>
70+
<p>16bit resolution PWM wave player with SD card, super lite version.</p>
71+
<h4>
72+
<a id="user-content-supported-boardmcu" class="anchor" href="#supported-boardmcu" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Supported Board/MCU</h4>
73+
<ul>
74+
<li><a href="https://os.mbed.com/platforms/ST-Nucleo-F030R8/" rel="nofollow">NULCEO-F030R8</a></li>
75+
</ul>
76+
<ul>
77+
<li><a href="https://os.mbed.com/platforms/ST-Nucleo-L152RE/" rel="nofollow">NUCLEO-L152RE</a></li>
78+
<li><a href="https://os.mbed.com/platforms/ST-Nucleo-F401RE/" rel="nofollow">NULCEO-F401RE</a></li>
79+
<li><a href="https://os.mbed.com/platforms/ST-Nucleo-F411RE/" rel="nofollow">NULCEO-F411RE</a></li>
80+
<li><a href="https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-discovery-kits/stm32f0discovery.html" rel="nofollow">STM32F0Discovery</a></li>
81+
<li><a href="https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-discovery-kits/stm32f3discovery.html" rel="nofollow">STM32F3Discovery</a></li>
82+
<li><a href="https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-discovery-kits/stm32f4discovery.html" rel="nofollow">STM32F4Discovery</a></li>
83+
</ul>
84+
<h4>
85+
<a id="user-content-supported-sd-card" class="anchor" href="#supported-sd-card" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Supported SD card</h4>
86+
<ul>
87+
<li>SDSC/SDHC card, FAT16 and FAT32.
88+
<ol>
89+
<li>At first, format SD card with <a href="https://www.sdcard.org/downloads/formatter_4/index.html" rel="nofollow">SD Card Formatter</a>
90+
</li>
91+
<li>Copy PCM wav files to the SD card on the root directory.</li>
92+
</ol>
93+
</li>
94+
</ul>
95+
<h4>
96+
<a id="user-content-supported-pcm-format" class="anchor" href="#supported-pcm-format" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Supported PCM Format</h4>
97+
<ul>
98+
<li>PCM wav file that have file extension ".wav" on root directory.</li>
99+
</ul>
100+
<ul>
101+
<li>16bit/8bit, fs(sampling rate)=32kHz,44.1kHz,48kHz.</li>
102+
<li>Stereo/Mono.</li>
103+
</ul>
104+
<h4>
105+
<a id="user-content-defalut-action" class="anchor" href="#defalut-action" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Defalut action</h4>
106+
<ul>
107+
<li>Afer power on, loop playback automatically and infinitly.</li>
108+
<li>
109+
<strong>USER_BUTTON on board operation</strong>: (PC_13 or PA0)
110+
<ul>
111+
<li>
112+
<em>Next song</em>: One click in Play mode.</li>
113+
<li>
114+
<em>Pause</em> : Push long time .</li>
115+
<li>
116+
<em>Play</em> : One click from Pause.</li>
117+
</ul>
118+
</li>
119+
</ul>
120+
<h4>
121+
<a id="user-content-hardware-settingschematic-16bit-sound-resolution" class="anchor" href="#hardware-settingschematic-16bit-sound-resolution" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Hardware setting/Schematic: (16bit sound resolution)</h4>
122+
<ul>
123+
<li>Refer to the file, <a href="https://github.com/dinau/stm32-wave-player-pwm-super-lite-nim/blob/main/port_setting.txt">port_setting.txt</a>.</li>
124+
</ul>
125+
<ul>
126+
<li>See folder doc/*<br>
127+
<p><img src="http://mpu.up.seesaa.net/image/16bit-wave-player-output-schema.png"></p></li>
128+
</ul>
129+
<h4>
130+
<a id="user-content-sd-card-connection" class="anchor" href="#sd-card-connection" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>SD Card connection</h4>
131+
<div class="highlight highlight-text-shell-session"><pre><span class="pl-c1">Pin side</span>
132+
<span class="pl-c1"> --------------.</span>
133+
<span class="pl-c1"> 9 = \ DAT2/NC</span>
134+
<span class="pl-c1"> 1 ===| CS/DAT3 [CS]</span>
135+
<span class="pl-c1"> 2 ===| CMD/DI [DI]</span>
136+
<span class="pl-c1"> 3 ===| VSS1</span>
137+
<span class="pl-c1"> Bottom 4 ===| VDD</span>
138+
<span class="pl-c1"> View 5 ===| CLK [CLK]</span>
139+
<span class="pl-c1"> 6 ===| VSS2</span>
140+
<span class="pl-c1"> 7 ===| DO/DAT0 [DO]</span>
141+
<span class="pl-c1"> 8 =| DAT1/IRQ</span>
142+
<span class="pl-c1"> -----------------'</span>
143+
144+
<span class="pl-c1"> Arduino NUCLEO-F411 NUCLEO-F030R8</span>
145+
<span class="pl-c1"> Logo side</span>
146+
<span class="pl-c1"> -----------------.</span>
147+
<span class="pl-c1"> 8 =| DAT1/IRQ</span>
148+
<span class="pl-c1"> 7 ===| DO/DAT0 [DO] D12 D12/PA_6 D12/PA_6</span>
149+
<span class="pl-c1"> 6 ===| VSS2</span>
150+
<span class="pl-c1"> Top 5 ===| CLK [CLK] D13 D13/PA_5 D13/PA_5</span>
151+
<span class="pl-c1"> View 4 ===| VDD</span>
152+
<span class="pl-c1"> 3 ===| VSS1</span>
153+
<span class="pl-c1"> 2 ===| CMD/DI [DI] D11 D11/PA_7 D11/PA_7</span>
154+
<span class="pl-c1"> 1 ===| CS/DAT3 [CS] D8 D10/PB_6 D10/PB_6</span>
155+
<span class="pl-c1"> 9 = / DAT2/NC</span>
156+
<span class="pl-c1"> ---------------'</span></pre></div>
157+
<h4>
158+
<a id="user-content-pwm-output-port" class="anchor" href="#pwm-output-port" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>PWM output port</h4>
159+
<ul>
160+
<li>Left upper(Hi) PWM 8bit out: PB_5 (TM3_CH2)</li>
161+
</ul>
162+
<ul>
163+
<li>Right upper(Hi) PWM 8bit out: PB4 (TM3_CH1)</li>
164+
<li>Left lower(Low) PWM 8bit out: PC_9 (TM3_CH4)</li>
165+
<li>Right lower(Low) PWM 8bit out: PC_8 (TM3_CH3)</li>
166+
</ul>
167+
<h4>
168+
<a id="user-content-led-indicator" class="anchor" href="#led-indicator" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>LED indicator</h4>
169+
<ul>
170+
<li>See <a href="https://github.com/dinau/stm32-wave-player-pwm-super-lite-nim/blob/main/port_setting.txt">port_setting.txt</a>.</li>
171+
</ul>
172+
<ul>
173+
<li>If set up LED device to "LED indicator port", it will be dimmer during play mode (regular speed) and pause mode (fast speed).</li>
174+
</ul>
175+
<h4>
176+
<a id="user-content-nim-compiler" class="anchor" href="#nim-compiler" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Nim compiler</h4>
177+
<ul>
178+
<li>Recomended nim compiler version is nim-1.6.0 at this time.</li>
179+
</ul>
180+
<h4>
181+
<a id="user-content-c-compiler-arm-none-eabi-gcc" class="anchor" href="#c-compiler-arm-none-eabi-gcc" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>C compiler: arm-none-eabi-gcc</h4>
182+
<ul>
183+
<li>v4.8.3 or later.</li>
184+
</ul>
185+
<ul>
186+
<li>Recomend <a href="https://developer.arm.com/open-source/gnu-toolchain/gnu-rm" rel="nofollow">GNU Arm Embedded Toolchain</a>
187+
</li>
188+
</ul>
189+
<h4>
190+
<a id="user-content-compiling-source-code" class="anchor" href="#compiling-source-code" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Compiling source code</h4>
191+
<ul>
192+
<li>
193+
<p>Example: (NUCLEO-L152RE board)</p>
194+
<div class="highlight highlight-source-shell"><pre>$ <span class="pl-c1">cd</span> src/L1/l152re/nucleo_l152re
195+
$ make
196+
.........................................................
197+
CC: xprintf
198+
CC: startup_stm32l152xe
199+
CC: stdlib_system.nim
200+
CC: ../stm32l152xe.nim
201+
CC: ../../../lib/reginfo.nim
202+
CC: ../uart.nim
203+
CC: ../pwm.nim
204+
CC: board.nim
205+
CC: ../spi.nim
206+
CC: ../../../lib/systick.nim
207+
CC: ../../../lib/sd_card.nim
208+
CC: ../../../lib/fat_lib.nim
209+
CC: ../../../wave_player_main.nim
210+
CC: ../../../main.nim
211+
CC: start.nim
212+
Hint: [Link]
213+
Hint: gc: none<span class="pl-k">;</span> opt: speed<span class="pl-k">;</span> options: -d:danger
214+
79440 lines<span class="pl-k">;</span> 4.460s<span class="pl-k">;</span> 77.398MiB peakmem<span class="pl-k">;</span> proj: .<span class="pl-cce">\s</span>tart<span class="pl-k">;</span> out:
215+
text data bss dec hex filename
216+
5656 1096 124 6876 1adc BINHEX<span class="pl-cce">\n</span>ucleo_l152re.elf</pre></div>
217+
</li>
218+
</ul>
219+
<h4>
220+
<a id="user-content-generated-files-are" class="anchor" href="#generated-files-are" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Generated files are</h4>
221+
<pre><code>BINHEX/nucleo_l152re.bin
222+
BINHEX/nucleo_l152re.hex
223+
...
224+
</code></pre>
225+
<p>You can just copy the <strong>bin</strong> file to mbed drive,
226+
or can flash the <strong>hex</strong> file with ST-Link utility.</p>
227+
<p>If you don't like to compile from source code, you can immediately upload <a href="https://github.com/dinau/stm32-wave-player-pwm-super-lite-nim/tree/main/doc/hex">doc/hex/*.hex or *.bin files</a> to flash.</p>
228+
<h4>
229+
<a id="user-content-output-music-filename--through-uart-port" class="anchor" href="#output-music-filename--through-uart-port" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Output music filename through UART port</h4>
230+
<p>By default music filename is send through default UART(USB-CDC(Nucleo boards)) port.
231+
Baudrate is <strong>115200bps</strong>.<br>
232+
<p><img src="http://mpu.up.seesaa.net/image/filename-to-uart-port.png"></p>If you don't need UART output feature, set <strong>UART_INFO* = false</strong> in <a href="https://github.com/dinau/stm32-wave-player-pwm-super-lite-nim/blob/main/src/conf_sys.nim">src/conf_sys.nim</a> and<br>
233+
recompile the project.</p>
234+
<h4>
235+
<a id="user-content-simple-less-bits-mode" class="anchor" href="#simple-less-bits-mode" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Simple less bits mode</h4>
236+
<p>If set <strong>PWM16BIT* = false</strong> in src/conf_sys.nim and recompile the project, <strong>simple less bits mode</strong> is enabled.<br>
237+
In spite of less parts, wirings and PCM bit length, it has fairly sound quality.
238+
<p><img src="http://mpu.up.seesaa.net/image/less-bits-wave-player-output-schema.png"></p><p><strong>Table 1.</strong> Sound resolution in <strong>simple less bits mode</strong></p>
239+
<table>
240+
<thead>
241+
<tr>
242+
<th align="left">Board</th>
243+
<th align="right">Sound resolution</th>
244+
<th align="right">TIM_PWM_BASE_CLOCK</th>
245+
</tr>
246+
</thead>
247+
<tbody>
248+
<tr>
249+
<td align="left">nulceo_f030r8</td>
250+
<td align="right">10bit</td>
251+
<td align="right">48MHz</td>
252+
</tr>
253+
<tr>
254+
<td align="left">nucleo_l152re</td>
255+
<td align="right">9bit</td>
256+
<td align="right">32MHz</td>
257+
</tr>
258+
<tr>
259+
<td align="left">nulceo_f401re</td>
260+
<td align="right">10bit</td>
261+
<td align="right">84MHz</td>
262+
</tr>
263+
<tr>
264+
<td align="left">nulceo_f411re</td>
265+
<td align="right"><strong>11bit</strong></td>
266+
<td align="right">96MHz</td>
267+
</tr>
268+
<tr>
269+
<td align="left">STM32F0Discovery</td>
270+
<td align="right">10bit</td>
271+
<td align="right">48MHz</td>
272+
</tr>
273+
<tr>
274+
<td align="left">STM32F3Discovery</td>
275+
<td align="right">10bit</td>
276+
<td align="right">64MHz</td>
277+
</tr>
278+
<tr>
279+
<td align="left">STM32F4Discovery</td>
280+
<td align="right">10bit</td>
281+
<td align="right">84MHz</td>
282+
</tr>
283+
</tbody>
284+
</table>
285+
<h4>
286+
<a id="user-content-pursue-small-code-size" class="anchor" href="#pursue-small-code-size" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Pursue small code size</h4>
287+
<p>In src/conf_sys.nim,by eliminating some functionalities, the code size can be further reduced.
288+
For instance, set as follows:<br>
289+
<strong>UART_INFO* = false</strong>
290+
<strong>PWM16BIT* = false</strong> ( set simple less bits mode)<br>
291+
<strong>DATA_8BIT_SUPPORT* = false</strong> ( only support PCM16bit format,neglect PCM8bit format)
292+
<strong>HAVE_LED_IND_PWM* = false</strong> ( eliminate LED indicator function)<br>
293+
<strong>FS_48KHZ_QUP* = false</strong> ( only supoort less than fs=48KHz)<br>
294+
will result in about:</p>
295+
<pre><code>text data bss dec hex filename
296+
2964 0 104 3068 bfc BUILD/nucleo_l152re.elf
297+
</code></pre>
298+
<p>In src/config.nims, uncomment and enable below option,</p>
299+
<pre><code>--passC:"-flto"
300+
--passL:"-flto"
301+
</code></pre>
302+
<p>and recompile project,</p>
303+
<pre><code>make clean
304+
make
305+
</code></pre>
306+
<p>will result in about:</p>
307+
<pre><code>text data bss dec hex filename
308+
2916 0 136 3052 bec BUILD/nucleo_l152re.elf
309+
</code></pre>
310+
<p>Now it can do auto playback after power on,<br>
311+
can operate play,pause and next song with push button,<br>
312+
be able to play fairly quality sound according to Table 1,
313+
can recognize PCM 16bit wav file(but output quality is reduced accoding to Table 1. and supports stereo/mono, fs=32KHz,44.1KHz.</p>
314+
<h4>
315+
<a id="user-content-other-links" class="anchor" href="#other-links" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Other links</h4>
316+
<ul>
317+
<li>Wave player projectm, Super lite series
318+
<ul>
319+
<li>Nim language
320+
<ul>
321+
<li>
322+
<a href="https://github.com/dinau/arduino-wave-player-pwm-super-lite-nim">Arduino Wave Player PWM Super Lite Nim / Nim</a> Completed.</li>
323+
</ul>
324+
</li>
325+
<li>Mbed2 C/C++ language
326+
<ul>
327+
<li>
328+
<a href="https://os.mbed.com/users/mimi3/code/wave_player_super_lite" rel="nofollow">Wave Player Super Lite / STM32(F0,L1,F4) / Mbed2 / C++</a> Completed.</li>
329+
</ul>
330+
</li>
331+
<li>Jal language
332+
<ul>
333+
<li><a href="https://github.com/dinau/16f-wave-player-pwm-super-lite-jalv2">Pwm Wave Player Jalv2 / PIC16F1xxx / Jal</a></li>
334+
</ul>
335+
</li>
336+
</ul>
337+
</li>
338+
</ul>
339+
340+
</article>
341+
</div>
342+
</div>
343+
<script src="https://cdn.jsdelivr.net/gh/calganaygun/MDcat@main/theme.js"></script>
344+
<script src="https://code.iconify.design/2/2.0.3/iconify.min.js"></script>
345+
</body>
346+
</html>

0 commit comments

Comments
 (0)