Skip to content

Commit 492a002

Browse files
committed
Original Release
1 parent 6c82140 commit 492a002

38 files changed

+2197
-2
lines changed

README.md

Lines changed: 190 additions & 2 deletions
Large diffs are not rendered by default.

src/ch_3/bare-metal-blink/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2025 David Such
2+
#
3+
# This software is released under the MIT License.
4+
# https://opensource.org/licenses/MIT
5+
6+
# Microcontroller & Serial Port Configuration
7+
MCU=atmega328p
8+
F_CPU=16000000UL
9+
PORT=$(shell ls /dev/cu.usbmodem* | head -n 1) # Auto-detect Arduino port
10+
BAUD=115200
11+
12+
# Toolchain Configuration
13+
CC=avr-gcc
14+
OBJCOPY=avr-objcopy
15+
AVRDUDE=avrdude
16+
CFLAGS=-mmcu=$(MCU) -Os -DF_CPU=$(F_CPU)
17+
18+
# Targets
19+
all: blink.hex
20+
21+
blink.elf: blink.c
22+
$(CC) $(CFLAGS) -o blink.elf blink.c
23+
24+
blink.hex: blink.elf
25+
$(OBJCOPY) -O ihex blink.elf blink.hex
26+
27+
upload: blink.hex
28+
$(AVRDUDE) -c arduino -p $(MCU) -P $(PORT) -b $(BAUD) -U flash:w:blink.hex:i
29+
30+
clean:
31+
rm -f blink.elf blink.hex

src/ch_3/bare-metal-blink/blink.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2025 David Such
3+
*
4+
* This software is released under the MIT License.
5+
* https://opensource.org/licenses/MIT
6+
*/
7+
8+
#define F_CPU 16000000UL // 16 MHz Clock
9+
#include <avr/io.h> // AVR Register Definitions
10+
11+
void timer1_delay_ms(uint16_t ms) {
12+
TCCR1B |= (1 << WGM12) | (1 << CS12) | (1 << CS10); // CTC mode, Prescaler 1024
13+
OCR1A = (F_CPU / 1024 / 1000) * ms; // Compare match value for the delay
14+
TCNT1 = 0; // Reset Timer1 counter
15+
TIFR1 |= (1 << OCF1A); // Clear previous interrupt flag
16+
while (!(TIFR1 & (1 << OCF1A))); // Wait for timer to reach match value
17+
}
18+
19+
int main(void) {
20+
DDRB |= (1 << DDB5); // Set PB5 (pin 13) as output
21+
22+
while (1) {
23+
PORTB ^= (1 << PORTB5); // Toggle PB5 (LED ON/OFF)
24+
timer1_delay_ms(500); // 500ms delay using Timer1
25+
}
26+
}
9.15 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
:100000000C9434000C943E000C943E000C943E0082
2+
:100010000C943E000C943E000C943E000C943E0068
3+
:100020000C943E000C943E000C943E000C943E0058
4+
:100030000C943E000C943E000C943E000C943E0048
5+
:100040000C943E000C943E000C943E000C943E0038
6+
:100050000C943E000C943E000C943E000C943E0028
7+
:100060000C943E000C943E0011241FBECFEFD8E04C
8+
:10007000DEBFCDBF0E9458000C9462000C940000BB
9+
:10008000AC01909181009D60909381008FE0849FEE
10+
:100090009001859F300D11243093890020938800B2
11+
:1000A0001092850010928400B19AB19BFECF089502
12+
:1000B000259AC0E285B18C2785B984EF91E00E9432
13+
:0800C0004000F8CFF894FFCFD7
14+
:00000001FF

src/ch_3/pico-awg-dma/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Pico",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"${userHome}/.pico-sdk/sdk/2.1.1/**"
8+
],
9+
"forcedInclude": [
10+
"${userHome}/.pico-sdk/sdk/2.1.1/src/common/pico_base_headers/include/pico.h",
11+
"${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h"
12+
],
13+
"defines": [],
14+
"compilerPath": "${userHome}/.pico-sdk/toolchain/14_2_Rel1/bin/arm-none-eabi-gcc",
15+
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
16+
"cStandard": "c17",
17+
"cppStandard": "c++14",
18+
"intelliSenseMode": "linux-gcc-arm"
19+
}
20+
],
21+
"version": 4
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"name": "Pico",
4+
"compilers": {
5+
"C": "${command:raspberry-pi-pico.getCompilerPath}",
6+
"CXX": "${command:raspberry-pi-pico.getCxxCompilerPath}"
7+
},
8+
"environmentVariables": {
9+
"PATH": "${command:raspberry-pi-pico.getEnvPath};${env:PATH}"
10+
},
11+
"cmakeSettings": {
12+
"Python3_EXECUTABLE": "${command:raspberry-pi-pico.getPythonPath}"
13+
}
14+
}
15+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"marus25.cortex-debug",
4+
"ms-vscode.cpptools",
5+
"ms-vscode.cpptools-extension-pack",
6+
"ms-vscode.vscode-serial-monitor",
7+
"raspberry-pi.raspberry-pi-pico"
8+
]
9+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Pico Debug (Cortex-Debug)",
6+
"cwd": "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
7+
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
8+
"request": "launch",
9+
"type": "cortex-debug",
10+
"servertype": "openocd",
11+
"serverpath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
12+
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
13+
"device": "${command:raspberry-pi-pico.getChipUppercase}",
14+
"configFiles": [
15+
"interface/cmsis-dap.cfg",
16+
"target/${command:raspberry-pi-pico.getTarget}.cfg"
17+
],
18+
"svdFile": "${userHome}/.pico-sdk/sdk/2.1.1/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
19+
"runToEntryPoint": "main",
20+
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
21+
// Also works fine for flash binaries
22+
"overrideLaunchCommands": [
23+
"monitor reset init",
24+
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
25+
],
26+
"openOCDLaunchCommands": [
27+
"adapter speed 5000"
28+
]
29+
},
30+
{
31+
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
32+
"cwd": "${workspaceRoot}",
33+
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
34+
"request": "launch",
35+
"type": "cortex-debug",
36+
"servertype": "external",
37+
"gdbTarget": "localhost:3333",
38+
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
39+
"device": "${command:raspberry-pi-pico.getChipUppercase}",
40+
"svdFile": "${userHome}/.pico-sdk/sdk/2.1.1/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
41+
"runToEntryPoint": "main",
42+
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
43+
// Also works fine for flash binaries
44+
"overrideLaunchCommands": [
45+
"monitor reset init",
46+
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
47+
]
48+
},
49+
{
50+
"name": "Pico Debug (C++ Debugger)",
51+
"type": "cppdbg",
52+
"request": "launch",
53+
"cwd": "${workspaceRoot}",
54+
"program": "${command:raspberry-pi-pico.launchTargetPath}",
55+
"MIMode": "gdb",
56+
"miDebuggerPath": "${command:raspberry-pi-pico.getGDBPath}",
57+
"miDebuggerServerAddress": "localhost:3333",
58+
"debugServerPath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
59+
"debugServerArgs": "-f interface/cmsis-dap.cfg -f target/${command:raspberry-pi-pico.getTarget}.cfg -c \"adapter speed 5000\"",
60+
"serverStarted": "Listening on port .* for gdb connections",
61+
"filterStderr": true,
62+
"hardwareBreakpoints": {
63+
"require": true,
64+
"limit": 4
65+
},
66+
"preLaunchTask": "Flash",
67+
"svdPath": "${userHome}/.pico-sdk/sdk/2.1.1/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd"
68+
},
69+
]
70+
}

0 commit comments

Comments
 (0)