Created
March 30, 2026 09:12
-
-
Save gquere/1abd248d8643bb61898d3ec91e19b5e3 to your computer and use it in GitHub Desktop.
IDA script to map STM32H5 peripherals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import idaapi | |
| import idc | |
| import ida_segment | |
| peripherals = [ | |
| (0x08FFF800, 0x08FFF8FF, "MCUID"), | |
| (0x47001400, 0x470017FF, "OCTOSPI1"), | |
| (0x47000400, 0x470007FF, "FMC"), | |
| (0x4600F000, 0x4600F3FF, "DLYBOS1"), | |
| (0x46008C00, 0x46008FFF, "SDMMC2"), | |
| (0x46008800, 0x46008BFF, "DLYBSD2"), | |
| (0x46008400, 0x460087FF, "DLYBSD1"), | |
| (0x46008000, 0x460083FF, "SDMMC1"), | |
| (0x46005000, 0x460053FF, "OTFDEC1"), | |
| (0x44024000, 0x440243FF, "DEBUG"), | |
| (0x44022000, 0x440223FF, "EXTI"), | |
| (0x44020C00, 0x44020FFF, "RCC"), | |
| (0x44020800, 0x44020BFF, "PWR"), | |
| (0x44007C00, 0x44007FFF, "TAMP"), | |
| (0x44007800, 0x44007BFF, "RTC"), | |
| (0x44007400, 0x440077FF, "VREFBUF"), | |
| (0x44005400, 0x440057FF, "LPTIM6"), | |
| (0x44005000, 0x440053FF, "LPTIM5"), | |
| (0x44004C00, 0x44004FFF, "LPTIM4"), | |
| (0x44004800, 0x44004BFF, "LPTIM3"), | |
| (0x44004400, 0x440047FF, "LPTIM1"), | |
| (0x44002C00, 0x44002FFF, "I2C4"), | |
| (0x44002800, 0x44002BFF, "I2C3"), | |
| (0x44002400, 0x440027FF, "LPUART1"), | |
| (0x44002000, 0x440023FF, "SPI5"), | |
| (0x44000400, 0x440007FF, "SBS"), | |
| (0x420C2000, 0x420C3FFF, "PKA"), | |
| (0x420C0C00, 0x420C0FFF, "SAES"), | |
| (0x420C0800, 0x420C0BFF, "RNG"), | |
| (0x420C0400, 0x420C07FF, "HASH"), | |
| (0x420C0000, 0x420C03FF, "AES"), | |
| (0x4202C400, 0x4202C7FF, "PSSI"), | |
| (0x4202C000, 0x4202C3FF, "DCMI"), | |
| (0x42028400, 0x420287FF, "DAC1"), | |
| (0x42028000, 0x420283FF, "ADC1"), | |
| (0x42022000, 0x420223FF, "GPIOI"), | |
| (0x42021C00, 0x42021FFF, "GPIOH"), | |
| (0x42021800, 0x42021BFF, "GPIOG"), | |
| (0x42021400, 0x420217FF, "GPIOF"), | |
| (0x42021000, 0x420213FF, "GPIOE"), | |
| (0x42020C00, 0x42020FFF, "GPIOD"), | |
| (0x42020800, 0x42020BFF, "GPIOC"), | |
| (0x42020400, 0x420207FF, "GPIOB"), | |
| (0x42020000, 0x420203FF, "GPIOA"), | |
| (0x40023000, 0x400233FF, "CRC"), | |
| (0x40016400, 0x40016BFF, "USB_FS"), | |
| (0x40016000, 0x400163FF, "USB_FS2"), | |
| (0x40014C00, 0x40014FFF, "SPI4"), | |
| (0x40014000, 0x400143FF, "TIM15"), | |
| (0x40013800, 0x40013BFF, "USART1"), | |
| (0x40013400, 0x400137FF, "TIM8"), | |
| (0x40013000, 0x400133FF, "SPI1"), | |
| (0x40012C00, 0x40012FFF, "TIM1"), | |
| (0x4000DC00, 0x4000DFFF, "UCPD1"), | |
| (0x4000AC00, 0x4000B3FF, "FDCAN"), | |
| (0x4000A800, 0x4000ABFF, "FDCAN2"), | |
| (0x4000A400, 0x4000A7FF, "FDCAN1"), | |
| (0x40009400, 0x400097FF, "LPTIM2"), | |
| (0x40008C00, 0x40008FFF, "DTS"), | |
| (0x40007000, 0x400073FF, "HDMI-CEC"), | |
| (0x40006400, 0x400067FF, "USART6"), | |
| (0x40006000, 0x400063FF, "CRS"), | |
| (0x40005C00, 0x40005FFF, "I3C1"), | |
| (0x40005800, 0x40005BFF, "I2C2"), | |
| (0x40005400, 0x400057FF, "I2C1"), | |
| (0x40005000, 0x400053FF, "UART5"), | |
| (0x40004C00, 0x40004FFF, "UART4"), | |
| (0x40004800, 0x40004BFF, "USART3"), | |
| (0x40004400, 0x400047FF, "USART2"), | |
| (0x40003C00, 0x40003FFF, "SPI3"), | |
| (0x40003800, 0x40003BFF, "SPI2"), | |
| (0x40003000, 0x400033FF, "IWDG"), | |
| (0x40002C00, 0x40002FFF, "WWDG"), | |
| (0x40001800, 0x40001BFF, "TIM12"), | |
| (0x40001400, 0x400017FF, "TIM7"), | |
| (0x40001000, 0x400013FF, "TIM6"), | |
| (0x40000C00, 0x40000FFF, "TIM5"), | |
| (0x40000800, 0x40000BFF, "TIM4"), | |
| (0x40000400, 0x400007FF, "TIM3"), | |
| (0x40000000, 0x400003FF, "TIM2"), | |
| ] | |
| def create_peripheral_segment(name, start_ea, size, bitness=32): | |
| """ | |
| Create a segment for a peripheral: | |
| - name: e.g. "TIM2", "GPIOA", "RCC" | |
| - start_ea: base address | |
| - size: usually 0x400, 0x1000, etc. | |
| """ | |
| end_ea = start_ea + size - 1 | |
| # Create the segment | |
| seg = ida_segment.segment_t() | |
| seg.start_ea = start_ea | |
| seg.end_ea = end_ea + 1 # IDA segments are [start, end) | |
| seg.perm = ida_segment.SEGPERM_READ | ida_segment.SEGPERM_WRITE | |
| #seg.bitness = bitness // 16 # 0=16, 1=32, 2=64 | |
| seg.align = ida_segment.saRelByte | |
| seg.comb = ida_segment.scPub | |
| seg.type = ida_segment.SEG_DATA # or SEG_XTRN / SEG_CODE if needed | |
| if ida_segment.add_segm_ex(seg, name, "PERIPH", ida_segment.ADDSEG_NOAA): | |
| print(f"Created segment: {name} [{start_ea:08X} - {end_ea:08X}]") | |
| else: | |
| print(f"Failed to create segment: {name}") | |
| for base, end, name in peripherals: | |
| if idc.get_segm_start(base) != idaapi.BADADDR: | |
| print(f"Warning: segment already exists at {base:08X} → skipping {name}") | |
| continue | |
| create_peripheral_segment(name, base, end - base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment