STM32F4: new RCC device
Subsystems (2)
PATCH 1/4 STM32F4: new RCC device
Generic RCC class for STM32 devices. It can be used for most of STM32 chips. Note that it only implements enable and reset capabilities.
--- hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/stm32_rcc.c | 162 ++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 6 ++ include/hw/misc/stm32_rcc.h | 91 ++++++++++++++++++++ 5 files changed, 263 insertions(+) create mode 100644 hw/misc/stm32_rcc.c create mode 100644 include/hw/misc/stm32_rcc.h
hw/misc/Kconfig +3 -0
@@ -82,6 +82,9 @@ config IMX select SSI select USB_EHCI_SYSBUS +config STM32_RCC + bool + config STM32F2XX_SYSCFG bool
hw/misc/meson.build +1 -0
@@ -106,6 +106,7 @@ system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files( system_ss.add(when: 'CONFIG_XLNX_VERSAL_TRNG', if_true: files( 'xlnx-versal-trng.c', )) +system_ss.add(when: 'CONFIG_STM32_RCC', if_true: files('stm32_rcc.c')) system_ss.add(when: 'CONFIG_STM32F2XX_SYSCFG', if_true: files('stm32f2xx_syscfg.c')) system_ss.add(when: 'CONFIG_STM32F4XX_SYSCFG', if_true: files('stm32f4xx_syscfg.c')) system_ss.add(when: 'CONFIG_STM32F4XX_EXTI', if_true: files('stm32f4xx_exti.c'))
hw/misc/stm32_rcc.c new file +162 -0
162 lines not on this page · raw message
hw/misc/trace-events +6 -0
@@ -156,6 +156,12 @@ npcm7xx_pwm_write(const char *id, uint64_t offset, uint32_t value) "%s offset: 0 npcm7xx_pwm_update_freq(const char *id, uint8_t index, uint32_t old_value, uint32_t new_value) "%s pwm[%u] Update Freq: old_freq: %u, new_freq: %u" npcm7xx_pwm_update_duty(const char *id, uint8_t index, uint32_t old_value, uint32_t new_value) "%s pwm[%u] Update Duty: old_duty: %u, new_duty: %u" +# stm32_rcc.c +stm32_rcc_read(uint64_t addr, uint64_t data) "reg read: addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" +stm32_rcc_write(uint64_t addr, uint64_t data) "reg write: addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" +stm32_rcc_pulse_enable(int line, int level) "Enable: %d to %d" +stm32_rcc_pulse_reset(int line, int level) "Reset: %d to %d" + # stm32f4xx_syscfg.c stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interrupt: GPIO: %d, Line: %d; Level: %d" stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
include/hw/misc/stm32_rcc.h new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.39.3 (Apple Git-146)
PATCH 2/4 Add RCC device to stm32f405 SoC
--- docs/system/arm/stm32.rst | 3 ++- hw/arm/Kconfig | 1 + hw/arm/stm32f405_soc.c | 12 +++++++++++- include/hw/arm/stm32f405_soc.h | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-)
docs/system/arm/stm32.rst +2 -1
@@ -36,6 +36,7 @@ Supported devices * SPI controller * System configuration (SYSCFG) * Timer controller (TIMER) + * Reset and Clock Controller (RCC) (STM32F4 only, reset and enable only) Missing devices ---------------
@@ -53,7 +54,7 @@ Missing devices * Power supply configuration (PWR) * Random Number Generator (RNG) * Real-Time Clock (RTC) controller - * Reset and Clock Controller (RCC) + * Reset and Clock Controller (RCC) (other features than reset and enable) * Secure Digital Input/Output (SDIO) interface * USB OTG * Watchdog controller (IWDG, WWDG)
hw/arm/Kconfig +1 -0
@@ -466,6 +466,7 @@ config STM32F405_SOC bool select ARM_V7M select OR_IRQ + select STM32_RCC select STM32F4XX_SYSCFG select STM32F4XX_EXTI
hw/arm/stm32f405_soc.c +11 -1
@@ -30,6 +30,7 @@#include "hw/qdev-clock.h" #include "hw/misc/unimp.h" +#define RCC_ADDR 0x40023800#define SYSCFG_ADD 0x40013800static const uint32_t usart_addr[] = {0x40011000 ,0x40004400 ,0x40004800 ,0x40004C00 ,0x40005000 ,0x40011400 ,
@@ -59,6 +60,8 @@ static void stm32f405_soc_initfn(Object *obj)object_initialize_child (obj,"armv7m" , &s->armv7m,TYPE_ARMV7M ); +object_initialize_child (obj,"rcc" , &s->rcc,TYPE_STM32_RCC ); +object_initialize_child (obj,"syscfg" , &s->syscfg,TYPE_STM32F4XX_SYSCFG );for (i =0 ; i <STM_NUM_USARTS ; i++) {
@@ -160,6 +163,14 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)return ; } +/* Reset and clock controller */ + dev =DEVICE (&s->rcc); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->rcc), errp)) { +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 ,RCC_ADDR ); +/* System configuration controller */ dev =DEVICE (&s->syscfg);if (!sysbus_realize (SYS_BUS_DEVICE (&s->syscfg), errp)) {
@@ -276,7 +287,6 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("GPIOH" ,0x40021C00 ,0x400 );create_unimplemented_device ("GPIOI" ,0x40022000 ,0x400 );create_unimplemented_device ("CRC" ,0x40023000 ,0x400 ); -create_unimplemented_device ("RCC" ,0x40023800 ,0x400 );create_unimplemented_device ("Flash Int" ,0x40023C00 ,0x400 );create_unimplemented_device ("BKPSRAM" ,0x40024000 ,0x400 );create_unimplemented_device ("DMA1" ,0x40026000 ,0x400 );
include/hw/arm/stm32f405_soc.h +2 -0
@@ -25,6 +25,7 @@#ifndef HW_ARM_STM32F405_SOC_H #define HW_ARM_STM32F405_SOC_H +#include "hw/misc/stm32_rcc.h" #include "hw/misc/stm32f4xx_syscfg.h" #include "hw/timer/stm32f2xx_timer.h" #include "hw/char/stm32f2xx_usart.h"
@@ -55,6 +56,7 @@ struct STM32F405State {ARMv7MState armv7m; +STM32RccState rcc;STM32F4xxSyscfgState syscfg;STM32F4xxExtiState exti;STM32F2XXUsartState usart[STM_NUM_USARTS ];
Signature · 1 line
2.39.3 (Apple Git-146)
PATCH 3/4 STM32: new GPIO device
In reply to Román Cárdenas RodríguezGeneric GPIO class for STM32 devices. It can be used for most of STM32 chips. Note that it does not implement configuration locking mechanisms.
--- hw/gpio/Kconfig | 3 + hw/gpio/meson.build | 1 + hw/gpio/stm32_gpio.c | 386 +++++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 8 + include/hw/arm/stm32.h | 41 ++++ include/hw/gpio/stm32_gpio.h | 109 ++++++++++ 6 files changed, 548 insertions(+) create mode 100644 hw/gpio/stm32_gpio.c create mode 100644 include/hw/arm/stm32.h create mode 100644 include/hw/gpio/stm32_gpio.h
hw/gpio/Kconfig +3 -0
@@ -17,6 +17,9 @@ config GPIO_PWR config SIFIVE_GPIO bool +config STM32_GPIO + bool + config STM32L4X5_GPIO bool
hw/gpio/meson.build +1 -0
@@ -15,6 +15,7 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2835_gpio.c', 'bcm2838_gpio.c' )) +system_ss.add(when: 'CONFIG_STM32_GPIO', if_true: files('stm32_gpio.c')) system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c'))
hw/gpio/stm32_gpio.c new file +386 -0
386 lines not on this page · raw message
hw/gpio/trace-events +8 -0
@@ -36,6 +36,14 @@ sifive_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " val aspeed_gpio_read(uint64_t offset, uint64_t value) "offset: 0x%" PRIx64 " value 0x%" PRIx64 aspeed_gpio_write(uint64_t offset, uint64_t value) "offset: 0x%" PRIx64 " value 0x%" PRIx64 +# stm32_gpio.c +stm32_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 +stm32_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 +stm32_gpio_irq_enable(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 +stm32_gpio_irq_reset(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 +stm32_gpio_irq_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 +stm32_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 + # stm32l4x5_gpio.c stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""
include/hw/arm/stm32.h new file +41 -0
41 lines not on this page · raw message
include/hw/gpio/stm32_gpio.h new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.39.3 (Apple Git-146)
Re: [PATCH 3/4] STM32: new GPIO device
Quoted 3 lines · Román Cárdenas Rodríguez
Generic GPIO class for STM32 devices. It can be used for most of STM32 chips. Note that it does not implement configuration locking mechanisms.
So we already have an stm32l4x5 GPIO device. How different is that one from these ones? Should we be sharing implementation, or are they too different?
When adding a new file, could you please add lines to the MAINTAINERS file putting it in an appropriate subsection?
hw/gpio/stm32_gpio.c line 107
Quoted 7 lines
hw/gpio/stm32_gpio.c new file +7
-0+static void stm32_gpio_irq_reset (void *opaque,int line,int value) +{ +STM32GPIOState *s =STM32_GPIO (opaque); + +trace_stm32_gpio_irq_reset (line, value); + +bool prev_reset = s->reset;
QEMU's coding style says that variable declarations should always be at the start of a code block, never in the middle. (There are some other cases of this here and in patch 4, I think.)
hw/gpio/stm32_gpio.c
Quoted 12 lines
hw/gpio/stm32_gpio.c new file +11
-0+ s->reset = value !=0 ; +if (prev_reset != s->reset) { +if (s->reset) { +stm32_gpio_reset (DEVICE (s)); + }else { +stm32_gpio_update_state (s); + } + } +} +static Property stm32_gpio_properties[] = { +DEFINE_PROP_UINT32 ("family" , STM32GPIOState, family,STM32_F2 ),
For this sort of situation where we have a set of devices that are very similar but have some slight model-to-model variation, rather than using a device property to tell the device which variation it is, we generally use a parent class with the implementation and a set of child classes which tweak fields controlling the parent class behaviour. For an example, look at hw/gpio/aspeed_gpio.c -- TYPE_ASPEED_GPIO is marked ".abstract = true", and it has most of the implementation. Then the various subtypes inherit from it, and their class init functions set fields in the class struct to define the behaviour. hw/char/stm32l4x5_usart.c is another example.
hw/gpio/stm32_gpio.c line 370
Quoted 8 lines
hw/gpio/stm32_gpio.c new file +8
-0+static void stm32_gpio_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + +device_class_set_props (dc, stm32_gpio_properties); + dc->vmsd = &vmstate_stm32_gpio; + dc->realize = stm32_gpio_realize; +device_class_set_legacy_reset (dc, stm32_gpio_reset);
Could you use the non-legacy reset instead? It's not much of a change, instead of calling this you set the ResettableClass phases.hold, and the reset function has a slightly different function signature. hw/char/stm32l4x5_usart.c has an example.
thanks
-- PMM
Re: [PATCH 3/4] STM32: new GPIO device
Looks like the stm32l4x5 is quite similar to my implementation. It didn’t exist when I started with my implementation . I will take a closer look and work on improving/extending the stm32l4x5 GPIO with my proposal. Is it OK if I rename it to stm32_gpio? so it is clearer that the implementation is generic and can fit almost any STM32 target.
Sorry about the issues with the patches, I am not familiar with this methodology of working with git. Could you guide me on how to send with you a revised version of patches 3 and 4?
Quoted 69 lines · Peter Maydell
Quoted 3 lines · Román Cárdenas Rodríguez
Generic GPIO class for STM32 devices. It can be used for most of STM32 chips. Note that it does not implement configuration locking mechanisms.
So we already have an stm32l4x5 GPIO device. How different is that one from these ones? Should we be sharing implementation, or are they too different?
When adding a new file, could you please add lines to the
MAINTAINERSfile putting it in an appropriate subsection?hw/gpio/stm32_gpio.c line 107
Quoted 7 lines
hw/gpio/stm32_gpio.c new file +7
-0+static void stm32_gpio_irq_reset (void *opaque,int line,int value) +{ +STM32GPIOState *s =STM32_GPIO (opaque); + +trace_stm32_gpio_irq_reset (line, value); + +bool prev_reset = s->reset;QEMU's coding style says that variable declarations should always be at the start of a code block, never in the middle. (There are some other cases of this here and in patch 4, I think.)
hw/gpio/stm32_gpio.c
Quoted 12 lines
hw/gpio/stm32_gpio.c new file +11
-0+ s->reset = value !=0 ; +if (prev_reset != s->reset) { +if (s->reset) { +stm32_gpio_reset (DEVICE (s)); + }else { +stm32_gpio_update_state (s); + } + } +} +static Property stm32_gpio_properties[] = { +DEFINE_PROP_UINT32 ("family" , STM32GPIOState, family,STM32_F2 ),For this sort of situation where we have a set of devices that are very similar but have some slight model-to-model variation, rather than using a device property to tell the device which variation it is, we generally use a parent class with the implementation and a set of child classes which tweak fields controlling the parent class behaviour. For an example, look at
hw/gpio/aspeed_gpio.c--TYPE_ASPEED_GPIOis marked ".abstract = true", and it has most of the implementation. Then the various subtypes inherit from it, and their class init functions set fields in the class struct to define the behaviour.hw/char/stm32l4x5_usart.cis another example.hw/gpio/stm32_gpio.c line 370
Quoted 8 lines
hw/gpio/stm32_gpio.c new file +8
-0+static void stm32_gpio_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + +device_class_set_props (dc, stm32_gpio_properties); + dc->vmsd = &vmstate_stm32_gpio; + dc->realize = stm32_gpio_realize; +device_class_set_legacy_reset (dc, stm32_gpio_reset);Could you use the non-legacy reset instead? It's not much of a change, instead of calling this you set the ResettableClass phases.hold, and the reset function has a slightly different function signature.
hw/char/stm32l4x5_usart.chas an example.thanks
-- PMM
Re: [PATCH 3/4] STM32: new GPIO device
Quoted 2 lines · Román Cárdenas Rodríguez
Looks like the stm32l4x5 is quite similar to my implementation. It didn’t exist when I started with my implementation . I will take a closer look and work on improving/extending the stm32l4x5 GPIO with my proposal. Is it OK if I rename it to
stm32_gpio? so it is clearer that the implementation is generic and can fit almost any STM32 target.
Yes, renaming would be OK. (Do that in a patch of its own that does the rename and nothing else.)
Quoted 2 lines
Sorry about the issues with the patches, I am not familiar with this methodology of working with git. Could you guide me on how to send with you a revised version of patches 3 and 4?
So I've taken your patches 1 and 2 into my git tree; they will appear upstream probably either end of this week or beginning of next week. If that happens before you're ready to send out a version 2 of this series, you can rebase your patches on head-of-git and then send out a new series with patches 3 and 4 in it. If you're ready to send v2 before the other patches land in upstream git, just send out v2 with the whole 4-patch set in it.
thanks
-- PMM
Re: [PATCH 3/4] STM32: new GPIO device
In reply to Román Cárdenas RodríguezQuoted 5 lines · Román Cárdenas Rodríguez
Generic GPIO class for STM32 devices. It can be used for most of STM32 chips. Note that it does not implement configuration locking mechanisms.
Signed-off-by Roman Cardenas Rodriguez <[email protected]>
Quoted 11 lines
--- hw/gpio/Kconfig | 3 + hw/gpio/meson.build | 1 + hw/gpio/stm32_gpio.c | 386 +++++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 8 + include/hw/arm/stm32.h | 41 ++++ include/hw/gpio/stm32_gpio.h | 109 ++++++++++ 6 files changed, 548 insertions(+) create mode 100644 hw/gpio/stm32_gpio.c create mode 100644 include/hw/arm/stm32.h create mode 100644 include/hw/gpio/stm32_gpio.h
Oh, I forgot -- could you consider adding some tests for the new device? We have tests already for stm32l4x5_gpio in tests/qtest/stm32l4x5_gpio-test.c which you can probably use as a pattern. You can add the test cases as an extra patch on the end of the series.
thanks
-- PMM
PATCH 4/4 Add GPIO device to stm32f405 SoC
In reply to Román Cárdenas Rodríguez--- hw/arm/Kconfig | 1 + hw/arm/stm32f405_soc.c | 40 ++++++++++++++++++++++++++-------- hw/misc/stm32f4xx_syscfg.c | 24 ++++++++++++-------- include/hw/arm/stm32f405_soc.h | 3 +++ 4 files changed, 50 insertions(+), 18 deletions(-)
hw/arm/Kconfig +1 -0
@@ -467,6 +467,7 @@ config STM32F405_SOC select ARM_V7M select OR_IRQ select STM32_RCC + select STM32_GPIO select STM32F4XX_SYSCFG select STM32F4XX_EXTI
hw/arm/stm32f405_soc.c +31 -9
@@ -26,6 +26,7 @@#include "qapi/error.h" #include "exec/address-spaces.h" #include "sysemu/sysemu.h" +#include "hw/arm/stm32.h" #include "hw/arm/stm32f405_soc.h" #include "hw/qdev-clock.h" #include "hw/misc/unimp.h"
@@ -43,6 +44,7 @@ static const uint32_t adc_addr[] = { 0x40012000, 0x40012100, 0x40012200,static const uint32_t spi_addr[] = {0x40013000 ,0x40003800 ,0x40003C00 ,0x40013400 ,0x40015000 ,0x40015400 };#define EXTI_ADDR 0x40013C00 +#define GPIO_ADDR 0x40020000#define SYSCFG_IRQ 71static const int usart_irq[] = {37 ,38 ,39 ,52 ,53 ,71 ,82 ,83 };
@@ -82,6 +84,10 @@ static void stm32f405_soc_initfn(Object *obj)object_initialize_child (obj,"spi[*]" , &s->spi[i],TYPE_STM32F2XX_SPI ); } +for (i =STM32_GPIO_PORT_A ; i <=STM32_GPIO_PORT_I ; i++) { +object_initialize_child (obj,"gpio[*]" , &s->gpio[i],TYPE_STM32_GPIO ); + } +object_initialize_child (obj,"exti" , &s->exti,TYPE_STM32F4XX_EXTI ); s->sysclk =qdev_init_clock_in (DEVICE (s),"sysclk" ,NULL ,NULL ,0 );
@@ -240,6 +246,31 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (armv7m, spi_irq[i])); } +/* GPIO devices */ +for (i =STM32_GPIO_PORT_A ; i <=STM32_GPIO_PORT_I ; i++) { + dev =DEVICE (&(s->gpio[i])); +qdev_prop_set_uint32 (dev,"family" ,STM32_F4 ); +qdev_prop_set_uint32 (dev,"port" , i); +qdev_prop_set_uint32 (dev,"ngpio" ,STM32_GPIO_NPINS ); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio[i]), errp)) { +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 , +GPIO_ADDR + (i *STM32_GPIO_PERIPHERAL_SIZE )); + +qdev_connect_gpio_out (DEVICE (&s->rcc),STM32_RCC_GPIO_IRQ_OFFSET + i, +qdev_get_gpio_in_named (dev,"reset-in" ,0 )); +qdev_connect_gpio_out (DEVICE (&s->rcc), +STM32_RCC_GPIO_IRQ_OFFSET + i +STM32_RCC_NIRQS , +qdev_get_gpio_in_named (dev,"enable-in" ,0 )); +for (int j =0 ; j <STM32_GPIO_NPINS ; j++) { +qdev_connect_gpio_out_named (dev,"input-out" , j, +qdev_get_gpio_in (DEVICE (&s->syscfg), + i *STM32_GPIO_NPINS + j)); + } + } +/* EXTI device */ dev =DEVICE (&s->exti);if (!sysbus_realize (SYS_BUS_DEVICE (&s->exti), errp)) {
@@ -277,15 +308,6 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("timer[9]" ,0x40014000 ,0x400 );create_unimplemented_device ("timer[10]" ,0x40014400 ,0x400 );create_unimplemented_device ("timer[11]" ,0x40014800 ,0x400 ); -create_unimplemented_device ("GPIOA" ,0x40020000 ,0x400 ); -create_unimplemented_device ("GPIOB" ,0x40020400 ,0x400 ); -create_unimplemented_device ("GPIOC" ,0x40020800 ,0x400 ); -create_unimplemented_device ("GPIOD" ,0x40020C00 ,0x400 ); -create_unimplemented_device ("GPIOE" ,0x40021000 ,0x400 ); -create_unimplemented_device ("GPIOF" ,0x40021400 ,0x400 ); -create_unimplemented_device ("GPIOG" ,0x40021800 ,0x400 ); -create_unimplemented_device ("GPIOH" ,0x40021C00 ,0x400 ); -create_unimplemented_device ("GPIOI" ,0x40022000 ,0x400 );create_unimplemented_device ("CRC" ,0x40023000 ,0x400 );create_unimplemented_device ("Flash Int" ,0x40023C00 ,0x400 );create_unimplemented_device ("BKPSRAM" ,0x40024000 ,0x400 );
hw/misc/stm32f4xx_syscfg.c +15 -9
@@ -27,6 +27,7 @@#include "trace.h" #include "hw/irq.h" #include "migration/vmstate.h" +#include "hw/gpio/stm32_gpio.h" #include "hw/misc/stm32f4xx_syscfg.h" static void stm32f4xx_syscfg_reset (DeviceState *dev)
@@ -45,17 +46,21 @@ static void stm32f4xx_syscfg_reset(DeviceState *dev)static void stm32f4xx_syscfg_set_irq (void *opaque,int irq,int level) {STM32F4xxSyscfgState *s = opaque; -int icrreg = irq /4 ; -int startbit = (irq &3 ) *4 ; -uint8_t config = irq /16 ; +uint8_t pin = irq &0xF ;/* first 4 bits encode the pin number */ +uint8_t port = irq >>4 ;/* the rest encode the port number */ -trace_stm32f4xx_syscfg_set_irq (irq /16 , irq %16 , level); +g_assert (port <=STM32_GPIO_PORT_I );/* stm32f4 only has ports A-I */ + +int icrreg = pin /4 ; +int startbit = (pin %4 ) *4 ; + +trace_stm32f4xx_syscfg_set_irq (port, pin, level);g_assert (icrreg <SYSCFG_NUM_EXTICR ); -if (extract32 (s->syscfg_exticr[icrreg], startbit,4 ) == config) { -qemu_set_irq (s->gpio_out[irq], level); -trace_stm32f4xx_pulse_exti (irq); +if (extract32 (s->syscfg_exticr[icrreg], startbit,4 ) == port) { +qemu_set_irq (s->gpio_out[pin], level); +trace_stm32f4xx_pulse_exti (pin); } }
@@ -129,8 +134,9 @@ static void stm32f4xx_syscfg_init(Object *obj) TYPE_STM32F4XX_SYSCFG, 0x400);sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); -qdev_init_gpio_in (DEVICE (obj), stm32f4xx_syscfg_set_irq,16 *9 ); -qdev_init_gpio_out (DEVICE (obj), s->gpio_out,16 ); +qdev_init_gpio_in (DEVICE (obj), stm32f4xx_syscfg_set_irq, +STM32_GPIO_NPINS * (STM32_GPIO_PORT_I +1 )); +qdev_init_gpio_out (DEVICE (obj), s->gpio_out,STM32_GPIO_NPINS ); }static const VMStateDescription vmstate_stm32f4xx_syscfg = {
include/hw/arm/stm32f405_soc.h +3 -0
@@ -26,6 +26,7 @@#define HW_ARM_STM32F405_SOC_H #include "hw/misc/stm32_rcc.h" +#include "hw/gpio/stm32_gpio.h" #include "hw/misc/stm32f4xx_syscfg.h" #include "hw/timer/stm32f2xx_timer.h" #include "hw/char/stm32f2xx_usart.h"
@@ -43,6 +44,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(STM32F405State, STM32F405_SOC)#define STM_NUM_TIMERS 4#define STM_NUM_ADCS 6#define STM_NUM_SPIS 6 +#define STM_NUM_GPIOS (STM32_GPIO_PORT_I - STM32_GPIO_PORT_A + 1)#define FLASH_BASE_ADDRESS 0x08000000#define FLASH_SIZE (1024 * 1024)
@@ -64,6 +66,7 @@ struct STM32F405State {OrIRQState adc_irqs;STM32F2XXADCState adc[STM_NUM_ADCS ];STM32F2XXSPIState spi[STM_NUM_SPIS ]; +STM32GPIOState gpio[STM_NUM_GPIOS ];MemoryRegion ccm;MemoryRegion sram;
Signature · 1 line
2.39.3 (Apple Git-146)
Quoted 5 lines · Román Cárdenas Rodríguez
Generic RCC class for STM32 devices. It can be used for most of STM32 chips. Note that it only implements enable and reset capabilities.
Signed-off-by Roman Cardenas Rodriguez <[email protected]>
Patches 1 and 2 looked OK to me, so I've applied them to target-arm.next. Thanks!
PS: for future submissions, if you send a multi-patch series could you send it with a cover letter, please (of the kind that "git format-patch --cover-letter" produces)? Our automatic tooling expects multi-patch threads to have a cover letter, so having one makes the process a bit smoother.
-- PMM