featured.jpg

Week 4: Embedded Programming

Table of Contents

This week we got introduced to embedded programming.

  • how to program?
  • already have some prog experience

This Week’s Tasks

  • Group assignment:
    • Demonstrate and compare the toolchains and development workflows for available embedded architectures
    • Document your work to the group work page and reflect on your individual page what you learned
  • Individual assignment:
    • Browse through the datasheet for your microcontroller
    • Write a program for a microcontroller, and simulate its operation, to interact (with local input &/or output devices) and communicate (with remote wired or wireless connection)

Introduction to Embedded Programming

  • recall recitation, lecture

from assignment book:

  • Implement programming protocols.

  • Described the programming process(es) you used

  • Included your source code

  • group: physically program devices from at least two different mcu families

  • vergleichen

    • mit ram, pins, on-board memory
    • prozessorarchitektur etc
    • prozessorfamilie
    • toolchains & development workflows
      • was brauche ich um das zu programmieren?
      • früher alles mit: SPI protokoll. die programmerproduktfamilie heißt avrISP
        • da hast du dann
          • einen programmer (usb interface + pins + μC)
          • das verbindest du dann mit den 6 pins an das board wo der chip drauf ist
        • prtokoll wie programmer und μC miteinander reden heißt SPI
        • es gibt aber andere protokolle dafür
          • ???
          • was sind gängige protokolle?
        • ISP: in system programmierung. ICSP: in circuit serial programming (name englisch/deutsch)
      • bei neuen μCs die kann man nicht mehr mit SPI kommunizieren.
        • SPDI: 1-pin-programmierung (eigentlich 3 pins aber egal)
      • ich bin etwas verwirrt von der ganzen terminologie. wichtig: es gibt 3 standards:
        • spi
        • spdi
        • jtag (was ist das?)
        • updi
    • which programming protocol can be used for which processors?
  • good practices

  • connect all grounds ever!

    • due to thermal abführung
  • which dev workflow is there?

    • arduino ide
    • platformio
    • command line over avrdude
    • one of thousand other programming environment. however they are based on avrdude or a commercial variant of it.
    • machen alle das gleiche
    • avrdude macht hexfile aus deinem code
    • und lädt das dann auf deinen μC
    • den programmer brauche ich nur für die übersetzung von usb zu programmer protocol
  • es gibt 2 varianten:

    • man beschreibt die μCs extern das wäre dann das mit dem programmer
    • ein μC hat einen bootloader der irgendwie es möglich macht ohne programmer code auf den μC zu packen. ich weiß aber nicht, inwieweit das funktioniert.
  • which workflows / protocols can be used for what controller? (multiple possible?)

  • alle programmierer die wir zur verfügung haben hinpacken (ferdi)

  • matthias:

    • welche von denen mit was programmiert werden?
  • joshua:

    • welche dev workflows gibt es? avrdude? etc.
  • produkt

  • gute dokus:

  • arbeitsteilung:

  • μC kann analoge und digitale pins haben

  • fast alle pins können als digital verwendet werden

  • für analoge pins die haben einen adc drin. die können das z.B. integriert sein

  • alle pins können inputs und outputs sein (input).

  • die neuen tinys haben analogoutput aber das ist nicht die regel (wichtig dafür ist: DAC)

  • vergleichen: produktfamilien:

    • rp2040 ist eine produktfamilie
    • esp32xx
    • samd21 etc.
    • samd11 etc.
    • attinyxx
    • avr128

programmierprotokolle:

  • spi

  • hersteller
    • PIC, ATMEL und STM sind die großen chiphersteller
    • neil hat sich eher für die atmel schiene entschieden
    • pic hat nur funktioniert mit proprietärer software. genauso stm. ändert sich jetzt
    • alles was wir haben ist von atmel außer von die samd and die esp32

what is a xiao?

what elese do we have?

  • kondensatoren
  • widerstnde
  • diode mosfets
  • LEDs
  • infrarotleds
  • sehr helle weiße led
  • neopixel
  • voltage regulatoren
  • switches
  • taster
  • terminal blocks, connection stuff
  • flachbandkabelsockets
  • other connectors…
  • mit ohne zugentlastung
  • handle tool?
  • usb c breakout board
  • batteriehalter
  • pinzetten

Choosing a Controller

  • for further development

decide for a microcontroller

  • choose for one.
  • maybe choose so it fits to your final project
  • something with audio
  • so an analog out would be nice
  • something fast
  • check for dma. feature so that hardware subsystems dcanddirectly access memory. cpu can do something else
  • check how other audio assignments did it
  • check for output week

other projects doing synthesis:

fragen an ferdis kumpel: michael kraft (audiodevel)
- bastler: teensy
- kommerzielle synths: fpgas, asics
- was nimmt man jetzt, wenn man bastler ist aber das ganze möglichst "richtig" machen will
- siehe 
Monophon:

Arm cortex 7 oder 5


Modular:
Monophon cortex m 4 und  stm

Herangehensweise ist eichtig. 

Problem: wenn du nahe 0 kommst schaltet das auf 64 bits. Das will ich nicht. Arm cortex haben dsp intrjnsics. Nahe 0 wird gleich 0.

Eichtig: ganze entwicklung muss extern stattfinden.

Ktieg software erstmal auf computer zum laufen. Möglichst auf nem 32 bit computer. Setz vm auf mit 32 bit

Dann entwicklungsumgebung entspricht arm cortex.

Bei Mcus hast du möglichkeit zu optimieten. Kann man nicht debuggen. Du musst auf n system entwickeln wo ich debugge und dann lass ich das laufen

Klangsynthesemögliche 


Teensy sagt ihm nichts


Reine dsps lohnen sich nicht mehr. Arm kann das auch. C intrinsics. Prozessoren haben assembler befehle für dsps. Um da ranzukommen definirst du ein c intrinsic. In c wie funrion. Ruft in wirklichkeit n bestimmtes code in aseembler auf das das macht was du beauchst. 

Bsp saturation. Normal: if else. Wirklichtkeit: sat intrinsic. 

Arm selbst verkauft keine chips. Wichtig wo du den kaufst

Kleinste arm cortex m0
M2 m3 etc

Ab cortex m4 fpu. Muss für audio. Immer mit fp in plus minus 1 berechnen. Voteil: multiplikation ist in eimem cycle gemacht. Division ist 80 cyc. Mit floating points in m1 1, kann man alles mit mult machen
11m

Du brauchst nen floating point prozessor.

Hersteller: lass finger von atmel arm. Nxp auch.

Stm sehr gute entwicklungsumgebung. Mausr.com elektronikvertrieb. Guck unter stm32 für dwv boards. Haben riesenliste an dmv boards . nucleo boards. Hardware codecs. Evaluation boards. Wichtig. Brauch ich wenn ich in hardware reingehen will.

Rp2040 ist ein eval board. Stm hat komplettes system dafür. Site ist st.com.

Mausr kannst du dinger kaufen.

Ansonsten alles andere was fpu etc hat. Auf github gibts viele projekte für audio auf raspi.


Mcu ist ne ecke billiger

Kommerziell nimmt man

Hängt davon ab was du machen willst. In entwicklungsprozess v elektrobik. Erstes ist sys engineering. Was rechenleistung was hardwaremäßig etc. Bürokratischer aufwande dwn ich brauch. Wird oft geschlampt. Das ist wichtig. Musst swhen wo dinge ihre limits haben wo nicht.

Wenn du rausfinden willst was du entwickeln willst nimm dafür ein größeres system. Dann weißt du was du brauchst. Wenn du das direkt auf hardware machst schwierig. 


Speziell jm audio willst du viel experimemtieren. Tu das auf nem computer.
-> esp32 dinger haben fpu und dsp:
- https://github.com/espressif/esp-dsp

Links
ferdi
:
5:39 PM







Und ein paar links für audio/DSP (von michael kraft)
Theory:
https://www.dspguide.com/pdfbook.htm - That's the heavy stuff!
https://sengpielaudio.com/ - gut zum Nachschauen von basics
http://www.musicdsp.com/ - loads of source code for audio algorithms!
Hardware:
https://www.mouser.de/c/embedded-solutions/engineering-tools/embedded-processor-development-kits/development-boards-kits-arm/?q=stm32f7 - ARM Cortex M7 evaluation boards (not audio specific, but quite powerful for an MCU)
https://www.mouser.de/ProductDetail/Espressif-Systems/ESP32-LyraT-Mini?qs=Cb2nCFKsA8pQPMrYjINZiw%3D%3D - Audio development board with ESP32
https://www.espressif.com/en/products/devkits - more low cost ESP32 kits, incl. audio specific
https://github.com/GuitarML/NeuralPi -…
Ich denke am einfachsten ist es mit dem ESP32 Lyra board anzufangen.
https://docs.espressif.com/projects/esp-adf/en/latest/design-guide/dev-boards/get-started-esp32-lyrat-mini.html

major:

https://kleinembedded.com/stm32-without-cubeide-part-1-the-bare-necessities/

https://www.reddit.com/media?url=https%3A%2F%2Fpreview.redd.it%2F1fl5yi6bbpzz.png%3Fauto%3Dwebp%26s%3D4725af1ae2d179026c412d45d3a57c88cfc15d3f&rdt=61159

https://faust.grame.fr/

https://github.com/thestk/stk?tab=readme-ov-file

https://github.com/mgetka/fptc-lib

https://github.com/maltman23/ArduTouch/tree/master/Arduino/libraries/ArduTouch

possible audio

  • there is fixpoint arithmetic
  • there is floating point arithmetic
  • i did not understand how to use it when

do i really need fpu? https://www.analog.com/en/resources/technical-articles/fixedpoint-vs-floatingpoint-dsp.html

  • fpu:

    • much larger dynamic range
    • higher precision due to less quantization error
    • easier development -> lower production cost
  • con:

    • processor cost
  • i did not know what exactly would it mean to differ between fix point and floating point

  • since i did not have that much experience, i went with choosing a processor with an fpu. i dont know what exactly would be easier for the development, but i will see. the only processor that has one is the esp32 s3.

faust

  • functional programming interface that lets you define your stuff

how to generate c code from it?

good to go

https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf

other projects https://fab.cba.mit.edu/classes/863.24/people/AntonisChristou/posts/week12/ http://archive.fabacademy.org/fabacademy2016/fablabkamplintfort/students/125/project_result.html http://fab.cba.mit.edu/classes/863.08/people/Tomas/review/index.html https://fab.cba.mit.edu/classes/863.22/Harvard/people/Selin/final.html

what is platformio? https://docs.platformio.org/en/latest/what-is-platformio.html

https://github.com/pschatzmann/arduino-audio-tools/wiki/Faust

https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf

you can compile faust code without fpu

for now: use esp32s3, later (if time) reprogram everything for another microcontroller/do the next project with another microcontroller

  • because i learn faust newly

https://fabacademy.org/2024/labs/waag/students/leo-kuipers/final-project/07_electronics/ https://fabacademy.org/2024/labs/waag/students/edwin-dertien/project/presentation/

https://www.allaboutcircuits.com/technical-articles/how-to-choose-a-microcontroller-for-digital-signal-processing-applications/

  • at least 16bit. want good sound quality
  • 8bit is also aesthetic, but i like crisp sounds
  • clock frequency? floating oint vs fixed point?

pieter did play with music http://fabacademy.org/2023/labs/waag/students/pieter-hijma/week-11/index.html

Reading the Manual

Datasheet

Hardware Design Guidelines

Technical Reference Manual

Setting Up

Arduino

  • looking forward to do advanced audio stuff. however, for that i need more time
  • now, just for assignment fulfillment

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(2, OUTPUT);
  Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
  int ms = millis();
  int d = sin(ms / 100);
  Serial.println(d);
  digitalWrite(2, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(d);                      // wait for a second
  digitalWrite(2, LOW);   // turn the LED off by making the voltage LOW
  delay(d);                      // wait for a second
}
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(2, OUTPUT);
  Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
  float s = millis() / 100;
  float sinarg = fmod(s, TWO_PI);
  Serial.println(sinarg);
  float d = 127*(sin(sinarg) + 1);
  Serial.println(d);
  digitalWrite(2, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(d);                      // wait for a second
  digitalWrite(2, LOW);   // turn the LED off by making the voltage LOW
  delay(d);                      // wait for a second
}

changed setup to connect led to pwm (analog) port.

was a bit too wonky.

void setup() {
  pinMode(A3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  float t = millis();
  float sinarg = fmod(t/1000, TWO_PI);

  float level = 100;//127*sin(sinarg) + ;
  Serial.println(level);
  
  analogWrite(A3, level);                          
}

220ohm resistor min: 128 value for led

led seemed not to change luminance with varying pwm frequency

[[[work process detail in past tense]]]

ESP32-S3

void setup() {
  Serial.begin(115200);
  pinMode(D2, OUTPUT);
}

void loop() {
  Serial.println("on");
  digitalWrite(D2, HIGH);
  delay(1000);
  Serial.println("off");
  digitalWrite(D2, LOW);
}

Preparing the ESP32-S3

FAUST

import("stdfaust.lib");
ctFreq = 500;
q = 1;
gain = 1;
process = no.noise : fi.resonlp(ctFreq,q,gain);

Reflections

What I Learned

  • programming / taxonomy / toolchain of programming microcontroller. was black magic to me earlier. nice that we had this introduction and this thorough group assignment!
  • hardware for audio programming and what to beachten

What Went Wrong

  • due to 2 exams i had, i was not able to get to having the esp programmed and i did not get to run code on it especially the synth code.

What Went Well

  • group assignment. was thorough and nice
  • ferdi connected me with a friend of his. greatful for that!

What I Would Do Differently

  • i did the best i could given the bedingungen

Digitial Files

  • todo

Use of Language Models

During writing this report, I used the following prompts asking ChatGPT 4o mini to …