Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions examples/stmicro/stm32/src/stm32f1xx/adc.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const microzig = @import("microzig");

const RCC = microzig.chip.peripherals.RCC;
const stm32 = microzig.hal;
const rcc = stm32.rcc;
const timer = microzig.hal.timer.GPTimer.init(.TIM2).into_counter_mode();

const uart = stm32.uart.UART.init(.USART1);
Expand All @@ -26,26 +26,22 @@ pub const microzig_options = microzig.Options{
};

pub fn main() !void {
RCC.APB1ENR.modify(.{
.TIM2EN = 1,
});
RCC.APB2ENR.modify(.{
.AFIOEN = 1,
.USART1EN = 1,
.GPIOAEN = 1,
.ADC1EN = 1,
});
const counter = timer.counter_device(8_000_000);
rcc.enable_clock(.TIM2);
rcc.enable_clock(.AFIO);
rcc.enable_clock(.USART1);
rcc.enable_clock(.GPIOA);
rcc.enable_clock(.ADC1);
const counter = timer.counter_device(rcc.get_clock(.TIM2));
const adc = ADC.init(.ADC1);
var adc_out_buf: [10]u16 = undefined;

TX.set_output_mode(.alternate_function_push_pull, .max_50MHz);
ADC_pin1.set_input_mode(.analog);
ADC_pin2.set_input_mode(.analog);

uart.apply(.{
try uart.apply_runtime(.{
.baud_rate = 115200,
.clock_speed = 8_000_000,
.clock_speed = rcc.get_clock(.USART1),
});

stm32.uart.init_logger(&uart);
Expand Down
32 changes: 14 additions & 18 deletions examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

const std = @import("std");
const microzig = @import("microzig");

const RCC = microzig.chip.peripherals.RCC;
const DMA = microzig.chip.peripherals.DMA1;
const DMA_t = microzig.chip.types.peripherals.bdma_v1;

const stm32 = microzig.hal;
const rcc = stm32.rcc;

const timer = microzig.hal.timer.GPTimer.init(.TIM2).into_counter_mode();

const uart = stm32.uart.UART.init(.USART1);
Expand Down Expand Up @@ -56,20 +57,15 @@ fn DMA_init(arr_addr: u32, adc_addr: u32) void {
}

pub fn main() !void {
RCC.AHBENR.modify(.{
.DMA1EN = 1,
});
RCC.APB1ENR.modify(.{
.TIM2EN = 1,
});
RCC.APB2ENR.modify(.{
.AFIOEN = 1,
.USART1EN = 1,
.GPIOAEN = 1,
.ADC1EN = 1,
.ADC2EN = 1,
});
const counter = timer.counter_device(8_000_000);
rcc.enable_clock(.DMA1);
rcc.enable_clock(.TIM2);
rcc.enable_clock(.AFIO);
rcc.enable_clock(.USART1);
rcc.enable_clock(.GPIOA);
rcc.enable_clock(.ADC1);
rcc.enable_clock(.ADC2);

const counter = timer.counter_device(rcc.get_clock(.TIM2));
const adc1 = AdvancedADC.init(.ADC1);
const adc2 = AdvancedADC.init(.ADC2);

Expand All @@ -81,9 +77,9 @@ pub fn main() !void {
ADC_pin1.set_input_mode(.analog);
ADC_pin2.set_input_mode(.analog);

uart.apply(.{
try uart.apply_runtime(.{
.baud_rate = 115200,
.clock_speed = 8_000_000,
.clock_speed = rcc.get_clock(.USART1),
});

stm32.uart.init_logger(&uart);
Expand Down
31 changes: 14 additions & 17 deletions examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

const std = @import("std");
const microzig = @import("microzig");
const interrupt = microzig.interrupt;

const RCC = microzig.chip.peripherals.RCC;
const interrupt = microzig.interrupt;
const DMA = microzig.chip.peripherals.DMA1;
const DMA_t = microzig.chip.types.peripherals.bdma_v1;

const stm32 = microzig.hal;
const rcc = stm32.rcc;
const timer = microzig.hal.timer.GPTimer.init(.TIM2).into_counter_mode();

const uart = stm32.uart.UART.init(.USART1);
Expand Down Expand Up @@ -69,20 +70,16 @@ fn DMA_init(arr_addr: u32, adc_addr: u32) void {
}

pub fn main() !void {
RCC.AHBENR.modify(.{
.DMA1EN = 1,
});
RCC.APB1ENR.modify(.{
.TIM2EN = 1,
});
RCC.APB2ENR.modify(.{
.AFIOEN = 1,
.USART1EN = 1,
.GPIOAEN = 1,
.ADC1EN = 1,
});
try rcc.clock_init(.{ .ADCprescaler = .RCC_ADCPCLK2_DIV2 });

rcc.enable_clock(.DMA1);
rcc.enable_clock(.TIM2);
rcc.enable_clock(.AFIO);
rcc.enable_clock(.USART1);
rcc.enable_clock(.GPIOA);
rcc.enable_clock(.ADC1);

const counter = timer.counter_device(8_000_000);
const counter = timer.counter_device(rcc.get_clock(.TIM2));

const adc_data_addr: u32 = @intFromPtr(&adc.regs.DR);
var adc_buf: [10]u16 = .{0} ** 10;
Expand All @@ -92,9 +89,9 @@ pub fn main() !void {
//configure UART log

TX.set_output_mode(.alternate_function_push_pull, .max_50MHz);
uart.apply(.{
try uart.apply_runtime(.{
.baud_rate = 115200,
.clock_speed = 8_000_000,
.clock_speed = rcc.get_clock(.USART1),
});
stm32.uart.init_logger(&uart);

Expand Down
14 changes: 4 additions & 10 deletions examples/stmicro/stm32/src/stm32f1xx/gpio.zig
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
const std = @import("std");
const microzig = @import("microzig");

const RCC = microzig.chip.peripherals.RCC;
const stm32 = microzig.hal;
const rcc = stm32.rcc;
const gpio = stm32.gpio;
const timer = stm32.timer.GPTimer.init(.TIM2).into_counter_mode();

pub fn main() !void {
RCC.APB2ENR.modify(.{
.GPIOCEN = 1,
});

RCC.APB1ENR.modify(.{
.TIM2EN = 1,
});

rcc.enable_clock(.GPIOC);
rcc.enable_clock(.TIM2);
const led = gpio.Pin.from_port(.C, 13);
const counter = timer.counter_device(8_000_000);
const counter = timer.counter_device(rcc.get_clock(.TIM2));

led.set_output_mode(.general_purpose_push_pull, .max_50MHz);
while (true) {
Expand Down
33 changes: 6 additions & 27 deletions examples/stmicro/stm32/src/stm32f1xx/hd44780.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const microzig = @import("microzig");

const RCC = microzig.chip.peripherals.RCC;
const stm32 = microzig.hal;
const rcc = stm32.rcc;
const gpio = stm32.gpio;

const drivers = microzig.drivers;
Expand All @@ -16,9 +16,6 @@ const timer = stm32.timer.GPTimer.init(.TIM2).into_counter_mode();
const I2c = stm32.i2c;
const I2C_Device = stm32.drivers.I2C_Device;

const uart = stm32.uart.UART.init(.USART1);
const TX = gpio.Pin.from_port(.A, 9);

const i2c = I2c.I2C.init(.I2C2);
const SCL = gpio.Pin.from_port(.B, 10);
const SDA = gpio.Pin.from_port(.B, 11);
Expand All @@ -28,10 +25,6 @@ const config = I2c.Config{
.mode = .standard,
};

pub const microzig_options = microzig.Options{
.logFn = stm32.uart.log,
};

var global_counter: stm32.drivers.CounterDevice = undefined;

const i2c_device = I2C_Device.init(i2c, I2c.Address.new(0x27), config, null, null);
Expand All @@ -40,19 +33,11 @@ pub fn delay_us(time_delay: u32) void {
global_counter.sleep_us(time_delay);
}
pub fn main() !void {
RCC.APB2ENR.modify(.{
.GPIOBEN = 1,
.GPIOAEN = 1,
.AFIOEN = 1,
.USART1EN = 1,
});

RCC.APB1ENR.modify(.{
.I2C2EN = 1,
.TIM2EN = 1,
});

TX.set_output_mode(.alternate_function_push_pull, .max_50MHz);
rcc.enable_clock(.GPIOB);
rcc.enable_clock(.GPIOC);
rcc.enable_clock(.USART1);
rcc.enable_clock(.I2C2);
rcc.enable_clock(.TIM2);

//Set internal Pull-ups (not recommended for real applications)
SCL.set_input_mode(.pull);
Expand All @@ -69,12 +54,6 @@ pub fn main() !void {

i2c.apply(config);

uart.apply(.{
.baud_rate = 115200,
.clock_speed = 8_000_000,
});

stm32.uart.init_logger(&uart);
var expander = PCF8574(.{}).init(i2c_device.datagram_device());
const pins_config = lcd(.{}).pins_struct{
.high_pins = .{
Expand Down
24 changes: 9 additions & 15 deletions examples/stmicro/stm32/src/stm32f1xx/i2c.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const microzig = @import("microzig");

const RCC = microzig.chip.peripherals.RCC;
const stm32 = microzig.hal;
const rcc = stm32.rcc;
const gpio = stm32.gpio;

const timer = stm32.timer.GPTimer.init(.TIM2).into_counter_mode();
Expand All @@ -27,19 +27,13 @@ pub const microzig_options = microzig.Options{
};

pub fn main() !void {
RCC.APB2ENR.modify(.{
.GPIOBEN = 1,
.GPIOAEN = 1,
.AFIOEN = 1,
.USART1EN = 1,
});

RCC.APB1ENR.modify(.{
.I2C2EN = 1,
.TIM2EN = 1,
});
rcc.enable_clock(.GPIOB);
rcc.enable_clock(.GPIOA);
rcc.enable_clock(.USART1);
rcc.enable_clock(.I2C2);
rcc.enable_clock(.TIM2);

const counter = timer.counter_device(8_000_000);
const counter = timer.counter_device(rcc.get_clock(.TIM2));

TX.set_output_mode(.alternate_function_push_pull, .max_50MHz);

Expand All @@ -55,9 +49,9 @@ pub fn main() !void {

i2c2.apply(config);

uart.apply(.{
try uart.apply_runtime(.{
.baud_rate = 115200,
.clock_speed = 8_000_000,
.clock_speed = rcc.get_clock(.USART1),
});

stm32.uart.init_logger(&uart);
Expand Down
25 changes: 10 additions & 15 deletions examples/stmicro/stm32/src/stm32f1xx/i2c_bus_scan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const microzig = @import("microzig");

const RCC = microzig.chip.peripherals.RCC;
const stm32 = microzig.hal;
const rcc = stm32.rcc;
const gpio = stm32.gpio;

const timer = stm32.timer.GPTimer.init(.TIM2).into_counter_mode();
Expand All @@ -26,19 +27,11 @@ pub const microzig_options = microzig.Options{
};

pub fn main() !void {
RCC.APB2ENR.modify(.{
.GPIOBEN = 1,
.GPIOAEN = 1,
.AFIOEN = 1,
.USART1EN = 1,
});

RCC.APB1ENR.modify(.{
.I2C2EN = 1,
.TIM2EN = 1,
});

const counter = timer.counter_device(8_000_000);
rcc.enable_clock(.GPIOB);
rcc.enable_clock(.GPIOA);
rcc.enable_clock(.USART1);
rcc.enable_clock(.I2C2);
rcc.enable_clock(.TIM2);

TX.set_output_mode(.alternate_function_push_pull, .max_50MHz);

Expand All @@ -52,11 +45,13 @@ pub fn main() !void {
SCL.set_output_mode(.alternate_function_open_drain, .max_50MHz);
SDA.set_output_mode(.alternate_function_open_drain, .max_50MHz);

const counter = timer.counter_device(rcc.get_clock(.TIM2));

i2c.apply(config);

uart.apply(.{
try uart.apply_runtime(.{
.baud_rate = 115200,
.clock_speed = 8_000_000,
.clock_speed = rcc.get_clock(.USART1),
});

stm32.uart.init_logger(&uart);
Expand Down
Loading
Loading