Deep Dive w/Scott: Raspberry Pi TinyUSB #adafruit
Channel: Adafruit Industries
Date: 17/09/2021

Join Scott as he explores bare metal programming a Raspberry Pi to try and get TinyUSB going on one. He'll also answer any questions folks have.

Chat with Scott and lot of others on the Adafruit Discord at https://adafru.it/discord.
Deep Dive happens every week. Normally Fridays at 2pm Pacific but occasionally shifted to Thursday at 2pm. Typically goes for two hours or more. Questions are welcome. Next week will be on Friday.

0:00 Getting started & mic trouble
0:07:27 Hello
0:08:32 housekeeping
0:11:30 Diving in to Tiny USB and CP on raspberry Pi ( see show and tell )
0:13:40 desktop setup CM-4 compute module setup
0:15:00 Jeff Geerling (sp)for examples of GPU(s) on pcie header
0:15:50 Macropad shortcuts
0:16:40 Development workflow, serial, gdb, source code
0:17:47 what about peripherals
0:19:50 Biggest advantage - HDMI
0:21:32 CrowdSupply Piunora https://www.crowdsupply.com/diodes-delight/piunora
0:24:25 sometimes / rpi4-osdev bare metal github documentation https://github.com/isometimes/rpi4-osdev
0:26:35 boochow micropython-raspberrypi - https://github.com/boochow/micropython-raspberrypi
0:27:40 hathach/tinyusb
0:28:00 could you have 4 instances of CP across the 4 cores run independent of each other?
0:28:30 CP on virtualized HW. wow... that's going in a new direction!

0:28:40 other links / useful tabs ( maybe @tannewt can save all his tabs :-) )
https://github.com/s-matyukevich/raspberry-pi-os/blob/master/docs/lesson03/rpi-os.md

https://github.com/isometimes/rpi4-osdev
https://pinout.xyz/pinout/jtag#

https://github.com/torvalds/linux/blob/1d597682d3e669ec7021aa33d088ed3d136a5149/drivers/usb/dwc2/params.c
https://www.raspberrypi.org/documentation/computers/config_txt.html#enable_jtag_gpio

https://github.com/hathach/tinyusb/blob/master/docs/contributing/porting.rst

https://github.com/raspberrypi/linux/blob/rpi-5.10.y/arch/arm/boot/dts/bcm2711.dtsi

0:20:00 interrupts
0:31:15 code startup ( multi core start up )
0:31:41 stack pointer
0:32:40 code from tinyusb
0:33:40 shrinking the code to get it all building
0:34:49 rPi USB licensed from synopsys
0:36:05 board_init in family.c from tiny usb / blink LED
0:36:53 uart prints / debugging
0:38:00 rebuild to get to “hello to gdb” / OpenOCD
0:39:49 it takes 7 seconds for the gpu to boot
0:41:02 start with jlink - since uart output didn’t work
0:41:49 set breakpoint at board_init
0:42:35 now there is garbage on the stack
0:44:23 exception vector table base address
0:46:00 set more of the system registers
0:48:12 two different rpi interrupt controllers
0:51:30 gdb jump start
0:52:30 read about Exception classed (D1.10.4) 
0:54:20 Decode the ESR ESR_EL2 0x200_0000
1:03:10 check if there is interrupt pending *0xf300b20b
1:05:19 // print() and add an infinite loop
1:05:55 don’t trust the debugger yet
1:06:45 link to https://github.com/rsta2/circle ( while waiting for rebuild )
1:09:00 blink and hello to gdb2 print worked
1:09:30 look at Circle ( from rsta2 ) initialization armstub/armstub8.S - from u-boot
1:12:30 concern about taking GPL code
1:13:25 tweek NOP and print
1:16:45 how is the stack backtrace initialized?
1:21:55 Stack overflow -  what is the current execution mode 
1:23:24 try qemu simulation 
1:24:20 there isn’t a pi4 board definition, maybe a similar pi3 - see stackexchange type=raspi3
1:25:40 cpu kicks on with qemu
1:26:15 Is there a virtual jlink for qemu?
1:27:17 QEMU Raspberry Pi 3 support ( github )
1:27:44 debug linux kernel with gdb and qemu ( stackoverflow )
1:26:10 same place in qemu / gdb emulation ( in board init )
1:30:19 qemu uart ( stackoverflow )
1:30:40 The Arm Docs are quite handy sometimes like https://developer.arm.com/documentation/den0013/d/Boot-Code/Booting-a-bare-metal-system?lang=en
1:37:42 - how to reset qemu ?
1:40:00 qemu pc log ( stackexchange ) QEMU/Monitor
1:46:45 qemu’s documentation ( gitlab.io/qemu )
1:56:52 quit qemu ( mon stop ? )
Found Ctrl-A X when running with -nographic https://superuser.com/questions/1087859/how-to-quit-the-qemu-monitor-when-not-using-a-gui
2:00:00 stackoverflow documentation on tracing / profiling in qemu
2:07:10 tracing QEMU guest execution ( wordpress )
2:10:00 what does qemu trace ( stackoverflow )
2:15:15 wrap up
2:16:33 does the STM32 circuit python work?
2:17:18 cat cam 

See Deep Dive Repo for an index archive of previous deep dives: https://github.com/adafruit/deep-dive-notes

Visit the Adafruit shop online - http://www.adafruit.com

-----------------------------------------
LIVE CHAT IS HERE! http://adafru.it/discord

Adafruit on Instagram: https://www.instagram.com/adafruit

Subscribe to Adafruit on YouTube: http://adafru.it/subscribe

New tutorials on the Adafruit Learning System: http://learn.adafruit.com/
-----------------------------------------