{"id":187,"date":"2021-08-21T19:21:10","date_gmt":"2021-08-21T19:21:10","guid":{"rendered":"https:\/\/www.jeskevic.info\/?p=187"},"modified":"2021-08-21T19:21:10","modified_gmt":"2021-08-21T19:21:10","slug":"add-and-mix-flatiron-dma-notes-super-mario-python-tkinter","status":"publish","type":"post","link":"https:\/\/www.jeskevic.info\/?p=187","title":{"rendered":"Add and mix Flatiron, DMA, notes, Super Mario, Python, Tkinter&#8230;"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">My flat-iron soldering device works, the temperature can be precisely regulated, the profile can be changed, and the device follows it precisely enough.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But it was not enough&#8230; I needed sound! I wanted a simple piezo, but I couldn&#8217;t find one in my boxes. But I&#8217;ve found some small laptop speakers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Speakers need sinus (okay, okay, square signal also good enough, but sinus is much better). STM32F103C8T6 has no DAC, so I need to use the PWM. For high frequencies and good enough time resolution, it should be very frequently updated. (For ~5kHz sinus and 7-bit amplitude resolution, with core clock 48MHz I need to update the PWM&#8230; let&#8217;s calculate: 48 000 000 \/ 2^7 \/ 5 000 ~ every 75 clocks. This is really time-consuming, for example, each <strong>for<\/strong> needs about 12 clocks. It is almost impossible to do it with a CPU. DMA comes to the rescue! <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need just to say where to take the data and where to put this data, increment the pointer or not, how many times to do this, and should it automatically cycle, or not. Oh yes, and turn the DMA trigger too, so it automatically updates DMA when it is ready to do so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Turned it on&#8230; nothing. Changed channel&#8230; nothing. Cleaned build, recompiled&#8230; nothing. Enabled with debugger registers &#8211; works! Two days clicking here and there &#8211; nothing&#8230;  Disabled in CubeMX everything and turned it on again &#8211; yes, now it works. Oh, it was simply wrong order,   CubeMX tried to init the DMA registers and only then to enable the DMA&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, now I can put the sinus and even play some notes, but it was not enough. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My colleague gave me an excellent idea &#8211; Mario sounds! Some more days learning about notes, pauses, sharps, and flats, watching some youtube videos &#8220;how to play Mario level complete&#8221;, and now it plays &#8220;coin&#8221; sound then goes to next reflow step, &#8220;level complete&#8221; at cooldown and &#8220;lose a life&#8221; in case of error. Nice!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now I&#8217;m programming py program to automatically read the data, display it and save it&#8230; My first interface with Tkinter! Sooo proud!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"653\" data-src=\"https:\/\/www.jeskevic.info\/wp-content\/uploads\/2021\/08\/image-19-1024x653.png\" alt=\"\" class=\"wp-image-188 lazyload\" data-srcset=\"https:\/\/www.jeskevic.info\/wp-content\/uploads\/2021\/08\/image-19-1024x653.png 1024w, https:\/\/www.jeskevic.info\/wp-content\/uploads\/2021\/08\/image-19-300x191.png 300w, https:\/\/www.jeskevic.info\/wp-content\/uploads\/2021\/08\/image-19-768x489.png 768w, https:\/\/www.jeskevic.info\/wp-content\/uploads\/2021\/08\/image-19.png 1202w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/653;\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>My flat-iron soldering device works, the temperature can be precisely regulated, the profile can be changed, and the device follows it precisely enough. But it was not enough&#8230; I needed sound! I wanted a simple piezo, but I couldn&#8217;t find one in my boxes. But I&#8217;ve found some small laptop speakers. Speakers need sinus (okay, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.jeskevic.info\/?p=187\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Add and mix Flatiron, DMA, notes, Super Mario, Python, Tkinter&#8230;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[46,39,50,47,49,48,45],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-etc","tag-dma","tag-flatiron","tag-hotiron","tag-pwm","tag-python","tag-super-mario","tag-tkinter","entry"],"_links":{"self":[{"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187"}],"version-history":[{"count":1,"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":189,"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions\/189"}],"wp:attachment":[{"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jeskevic.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}