Skip to content

Commit 89b1a7f

Browse files
committed
Add stm32f103 testcase
1 parent 2a582f7 commit 89b1a7f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/test_mcu.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from qiling.core import Qiling
1111
from qiling.const import QL_VERBOSE
1212
from qiling.extensions.mcu.stm32f4 import stm32f407, stm32f411
13+
from qiling.extensions.mcu.stm32f1 import stm32f103
1314
from qiling.extensions.mcu.gd32vf1 import gd32vf103
1415

1516
class MCUTest(unittest.TestCase):
@@ -347,6 +348,34 @@ def indicator(ql):
347348

348349
del ql
349350

351+
def test_mcu_usart_stm32f103(self):
352+
ql = Qiling(["../examples/rootfs/mcu/stm32f103/sctf2020-password-lock-plus.hex"],
353+
archtype="cortex_m", env=stm32f103, verbose=QL_VERBOSE.DEFAULT)
354+
355+
ql.hw.create('rcc')
356+
ql.hw.create('flash interface')
357+
ql.hw.create('exti')
358+
ql.hw.create('usart1')
359+
ql.hw.create('gpioa')
360+
ql.hw.create('afio')
361+
ql.hw.create('dma1').watch()
362+
363+
data = []
364+
def gpio_set_cb(pin):
365+
data.append(pin)
366+
367+
ql.hw.gpioa.hook_set(1, gpio_set_cb, '1')
368+
ql.hw.gpioa.hook_set(2, gpio_set_cb, '2')
369+
ql.hw.gpioa.hook_set(3, gpio_set_cb, '3')
370+
ql.hw.gpioa.hook_set(4, gpio_set_cb, '4')
371+
372+
ql.run(count=400000)
373+
374+
self.assertTrue((''.join(data)).find('1442413') != -1)
375+
self.assertTrue(ql.hw.usart1.recv()[:23] == b'SCTF{that1s___r1ghtflag')
376+
377+
del ql
378+
350379

351380
if __name__ == "__main__":
352381
unittest.main()

0 commit comments

Comments
 (0)