Skip to content

Commit e9f167d

Browse files
authored
Misc Mk3.5 fixes (#149)
* Fix bug in GPIO initialization sequence. Fixes #146 * Adjust failing unit tests
1 parent 0fbb201 commit e9f167d

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

hw/arm/prusa/prusa-mk4.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ typedef struct mk4_cfg_t {
114114
temp_cfg_t temps;
115115
uint8_t motor;
116116
uint8_t e_t_mass;
117+
bool e_loopback;
117118
char m_label[AXIS_MAX];
118119
stm_pin m_step[AXIS_MAX];
119120
stm_pin m_dir[AXIS_MAX];
@@ -258,6 +259,7 @@ static const mk4_cfg_t mk3v5_cfg = {
258259
.table = { [T_NOZ] = 2005, [T_BED] = 2004, [T_BRK] = 5, [T_BRD] = 2000, [T_CASE] = 2000 }
259260
},
260261
.e_t_mass = 30,
262+
.e_loopback = true,
261263
.motor = TMC2130,
262264
.m_label = {'X','Y','Z','E'},
263265
.m_step = { STM_PIN(GPIOD,7), STM_PIN(GPIOD,5), STM_PIN(GPIOD,3), STM_PIN(GPIOD,1)},
@@ -341,6 +343,9 @@ static void mk4_init(MachineState *machine)
341343
qdev_prop_set_uint32(dev,"sram-size", machine->ram_size);
342344
uint64_t flash_size = stm32_soc_get_flash_size(dev);
343345
arghelper_setargs(machine->kernel_cmdline);
346+
347+
// We (ab)use the kernel command line to piggyback custom arguments into QEMU.
348+
// Parse those now.
344349
bool args_continue_running = arghelper_parseargs();
345350
if (arghelper_is_arg("4x_flash"))
346351
{
@@ -361,14 +366,21 @@ static void mk4_init(MachineState *machine)
361366
qdev_prop_set_uint32(otp,"otp-data[7]", otp_raw[7]);
362367
qdev_prop_set_uint32(otp,"otp-data[8]", otp_raw[8]);
363368

364-
sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
365369
DeviceState* dev_soc = dev;
366-
// We (ab)use the kernel command line to piggyback custom arguments into QEMU.
367-
// Parse those now.
368-
// ugly hack... FIXME.
369370
if (arghelper_is_arg("appendix")) {
370371
qdev_prop_set_uint32(stm32_soc_get_periph(dev_soc, STM32_P_GPIOA),"idr-mask", 0x2000);
371372
}
373+
if (cfg.e_loopback) {
374+
qdev_prop_set_uint32(stm32_soc_get_periph(dev_soc, STM32_P_GPIOE),"idr-mask", 0x80);
375+
}
376+
377+
sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
378+
379+
if(cfg.e_loopback)
380+
{
381+
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));
382+
}
383+
372384

373385
char* kfn = machine->kernel_filename;
374386
int kernel_len = kfn ? strlen(kfn) : 0;

hw/arm/prusa/stm32_common/stm32_gpio.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ stm32_common_gpio_read(void *arg, hwaddr addr, unsigned int size)
8989
uint32_t r;
9090

9191
addr >>= 2;
92-
r = s->regs[addr];
9392
CHECK_BOUNDS_R(addr, RI_END, s->reginfo[s->parent.periph - STM32_P_GPIOA], "STM32 GPIO");
93+
r = s->regs[addr];
9494
//printf("GPIO unit %d reg %x return 0x%x\n", s->periph, (int)offset << 2, r);
9595
return r;
9696
}
@@ -221,6 +221,10 @@ stm32_common_gpio_reset(DeviceState *dev)
221221
{
222222
s->regs[i] = s->reginfo[s->parent.periph - STM32_P_GPIOA][i].reset_val;
223223
}
224+
for (int i=0; i<STM32_GPIO_PIN_COUNT; i++)
225+
{
226+
qemu_set_irq(s->pin[i], s->regs[RI_ODR] & (1<<i));
227+
}
224228
/* Mask out the IDR bits as specified */
225229
s->regs[RI_IDR] = 0x0000ffff & ~(s->idr_mask);
226230
}

hw/arm/prusa/stm32_tests/mini404_sn74hc4052_test.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ static void test_sn74hc4052_reset(void)
5656
}
5757
}
5858

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

6464
}

hw/arm/prusa/stm32_tests/mini404_ws281x_test.c

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static void test_reset(void)
4444
{
4545
QTestState *ts = qtest_init("-machine " MACHINE);
4646
qtest_irq_intercept_out_named(ts, QOM_PATH, "colour");
47+
qtest_clock_step(ts, RESET_NS);
4748

4849
// Toggle GPIO input to send color value
4950
uint32_t colour = 0xBEEF05;
@@ -72,6 +73,7 @@ static void test_ws281x_color(void)
7273
{
7374
QTestState *ts = qtest_init("-machine " MACHINE);
7475
qtest_irq_intercept_out_named(ts, QOM_PATH, "colour");
76+
qtest_clock_step(ts, RESET_NS);
7577

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

97100
// Toggle GPIO input to send color value
98101
uint32_t colour = 0xBEEF05;

0 commit comments

Comments
 (0)