Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Mk3.5 fixes #149

Merged
merged 2 commits into from
Mar 3, 2024
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
20 changes: 16 additions & 4 deletions hw/arm/prusa/prusa-mk4.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ typedef struct mk4_cfg_t {
temp_cfg_t temps;
uint8_t motor;
uint8_t e_t_mass;
bool e_loopback;
char m_label[AXIS_MAX];
stm_pin m_step[AXIS_MAX];
stm_pin m_dir[AXIS_MAX];
Expand Down Expand Up @@ -258,6 +259,7 @@ static const mk4_cfg_t mk3v5_cfg = {
.table = { [T_NOZ] = 2005, [T_BED] = 2004, [T_BRK] = 5, [T_BRD] = 2000, [T_CASE] = 2000 }
},
.e_t_mass = 30,
.e_loopback = true,
.motor = TMC2130,
.m_label = {'X','Y','Z','E'},
.m_step = { STM_PIN(GPIOD,7), STM_PIN(GPIOD,5), STM_PIN(GPIOD,3), STM_PIN(GPIOD,1)},
Expand Down Expand Up @@ -341,6 +343,9 @@ static void mk4_init(MachineState *machine)
qdev_prop_set_uint32(dev,"sram-size", machine->ram_size);
uint64_t flash_size = stm32_soc_get_flash_size(dev);
arghelper_setargs(machine->kernel_cmdline);

// We (ab)use the kernel command line to piggyback custom arguments into QEMU.
// Parse those now.
bool args_continue_running = arghelper_parseargs();
if (arghelper_is_arg("4x_flash"))
{
Expand All @@ -361,14 +366,21 @@ static void mk4_init(MachineState *machine)
qdev_prop_set_uint32(otp,"otp-data[7]", otp_raw[7]);
qdev_prop_set_uint32(otp,"otp-data[8]", otp_raw[8]);

sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
DeviceState* dev_soc = dev;
// We (ab)use the kernel command line to piggyback custom arguments into QEMU.
// Parse those now.
// ugly hack... FIXME.
if (arghelper_is_arg("appendix")) {
qdev_prop_set_uint32(stm32_soc_get_periph(dev_soc, STM32_P_GPIOA),"idr-mask", 0x2000);
}
if (cfg.e_loopback) {
qdev_prop_set_uint32(stm32_soc_get_periph(dev_soc, STM32_P_GPIOE),"idr-mask", 0x80);
}

sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);

if(cfg.e_loopback)
{
qdev_connect_gpio_out(stm32_soc_get_periph(dev_soc, STM32_P_GPIOG), 1, qdev_get_gpio_in(stm32_soc_get_periph(dev_soc, STM32_P_GPIOE), 7));
}


char* kfn = machine->kernel_filename;
int kernel_len = kfn ? strlen(kfn) : 0;
Expand Down
6 changes: 5 additions & 1 deletion hw/arm/prusa/stm32_common/stm32_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ stm32_common_gpio_read(void *arg, hwaddr addr, unsigned int size)
uint32_t r;

addr >>= 2;
r = s->regs[addr];
CHECK_BOUNDS_R(addr, RI_END, s->reginfo[s->parent.periph - STM32_P_GPIOA], "STM32 GPIO");
r = s->regs[addr];
//printf("GPIO unit %d reg %x return 0x%x\n", s->periph, (int)offset << 2, r);
return r;
}
Expand Down Expand Up @@ -221,6 +221,10 @@ stm32_common_gpio_reset(DeviceState *dev)
{
s->regs[i] = s->reginfo[s->parent.periph - STM32_P_GPIOA][i].reset_val;
}
for (int i=0; i<STM32_GPIO_PIN_COUNT; i++)
{
qemu_set_irq(s->pin[i], s->regs[RI_ODR] & (1<<i));
}
/* Mask out the IDR bits as specified */
s->regs[RI_IDR] = 0x0000ffff & ~(s->idr_mask);
}
Expand Down
6 changes: 3 additions & 3 deletions hw/arm/prusa/stm32_tests/mini404_sn74hc4052_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ static void test_sn74hc4052_reset(void)
}
}

// Reset should set the channel to start channel - for this machine, it's 1.
g_assert_cmpint(qtest_get_irq_level(ts, 0), ==, 101);
g_assert_cmpint(qtest_get_irq_level(ts, 1), ==, 301);
// Reset should set the channel to start channel - for this machine, it's 1, but the GPIO reset returns it to 0...
g_assert_cmpint(qtest_get_irq_level(ts, 0), ==, 100);
g_assert_cmpint(qtest_get_irq_level(ts, 1), ==, 300);
qtest_quit(ts);

}
Expand Down
3 changes: 3 additions & 0 deletions hw/arm/prusa/stm32_tests/mini404_ws281x_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static void test_reset(void)
{
QTestState *ts = qtest_init("-machine " MACHINE);
qtest_irq_intercept_out_named(ts, QOM_PATH, "colour");
qtest_clock_step(ts, RESET_NS);

// Toggle GPIO input to send color value
uint32_t colour = 0xBEEF05;
Expand Down Expand Up @@ -72,6 +73,7 @@ static void test_ws281x_color(void)
{
QTestState *ts = qtest_init("-machine " MACHINE);
qtest_irq_intercept_out_named(ts, QOM_PATH, "colour");
qtest_clock_step(ts, RESET_NS);

// Toggle GPIO input to send color value
uint32_t colour = 0xBEEF05;
Expand All @@ -93,6 +95,7 @@ static void test_ws281x_passthru(void)
{
QTestState *ts = qtest_init("-machine " MACHINE);
qtest_irq_intercept_out(ts, QOM_PATH);
qtest_clock_step(ts, RESET_NS);

// Toggle GPIO input to send color value
uint32_t colour = 0xBEEF05;
Expand Down
Loading