KeyboardInterrupt Ctrl+c does not work

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
stmfresser
Posts: 22
Joined: Sat Jun 20, 2015 11:48 am

KeyboardInterrupt Ctrl+c does not work

Post by stmfresser » Tue Aug 16, 2016 1:44 am

Hello,

i have tested recent build of micropython on STM32F407 Discovery Board, Unfortunately the KeyboardInterrupt 'ctrl+c' does not work, no effect. The build about 3 weeks ago, it worked well. I've using minicom on OSX10.5

Does anyone know, how to solve it.

Thanks in advance.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: KeyboardInterrupt Ctrl+c does not work

Post by dhylands » Tue Aug 16, 2016 4:25 am

I flashed using the latest from the repository and both raising a KeyboardInterrupt and pressing Control-C both seem to be working fine.

Here's the program I tested:

Code: Select all

import pyb

sw = pyb.Switch()

while True:
    pyb.LED(1).on()
    pyb.delay(100)
    pyb.LED(2).on()
    pyb.delay(100)
    pyb.LED(1).off()
    pyb.delay(100)
    pyb.LED(2).off()
    pyb.delay(700)
    if sw():
        raise KeyboardInterrupt
and this is the output from pressing the blue pushbutton:

Code: Select all

MicroPython v1.8.3-24-g095e43a-dirty on 2016-08-15; F4DISC with STM32F407
Type "help()" for more information.
>>> 
>>> import ctrlc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ctrlc.py", line 15, in <module>
KeyboardInterrupt: 
>>> 
and this is the output of pressing Control-C:

Code: Select all

MicroPython v1.8.3-24-g095e43a-dirty on 2016-08-15; F4DISC with STM32F407
Type "help()" for more information.
>>> import ctrlc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ctrlc.py", line 14, in <module>
KeyboardInterrupt: 
>>>  

stmfresser
Posts: 22
Joined: Sat Jun 20, 2015 11:48 am

Re: KeyboardInterrupt Ctrl+c does not work

Post by stmfresser » Tue Aug 16, 2016 5:04 am

what happened if you don't use Switch Button. I'm using STM32F407 on my modified Board similar to Discovery Board without Switch.

Before built, i've disabled has_switch to 0 on mpconfig, I think, it would nothing happen if you press ctrl +c during while loop without using switch button there.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: KeyboardInterrupt Ctrl+c does not work

Post by dhylands » Tue Aug 16, 2016 5:23 am

Control-C also worked for me without using the switch code. I even compiled with MICROPY_HW_HAS_SWITCH set to zero.

Control-C doesn't work if your REPL is on a UART but it should be working fine if your REPL is on the USB-serial.

2 reasons why Control-C might not be getting processed:
1 - Interrupts have been disabled
2 - Some interrupt is firing continuously.

stmfresser
Posts: 22
Joined: Sat Jun 20, 2015 11:48 am

Re: KeyboardInterrupt Ctrl+c does not work

Post by stmfresser » Tue Aug 16, 2016 5:38 am

It works fine, when i switched to the old commit 27.07.2016 with same mpconfig and same code. I think it's a bug. Strange

the code ist simple

Code: Select all

while 1:
      print('hello')
      pyb.delay(100)

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: KeyboardInterrupt Ctrl+c does not work

Post by dhylands » Tue Aug 16, 2016 5:53 am

That seems to work fine for me as well:

Code: Select all

MicroPython v1.8.3-24-g095e43a on 2016-08-15; F4DISC with STM32F407
Type "help()" for more information.
>>> 
>>> import ctrlc
hello
hello
hello
hello
hello
hello
hello
hello
hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ctrlc.py", line 5, in <module>
KeyboardInterrupt: 
>>> 
Have you tried building with the latest tree?

stmfresser
Posts: 22
Joined: Sat Jun 20, 2015 11:48 am

Re: KeyboardInterrupt Ctrl+c does not work

Post by stmfresser » Tue Aug 16, 2016 3:29 pm

recent built of micropython did not work as always, then converted again same firmware.elf to prog.bin. After flashing, ctrl+c does work.
I'm confused, Is it something wrong with objcopy?

Code: Select all

arm-none-eabi-objcopy -O binary firmware.elf prog.bin
st-flash write prog.bin 0x8000000
Screen Shot 2016-08-16 at 17.28.02.png
Screen Shot 2016-08-16 at 17.28.02.png (64.2 KiB) Viewed 9109 times
Screen Shot 2016-08-16 at 16.58.27.png
Screen Shot 2016-08-16 at 16.58.27.png (90.66 KiB) Viewed 9109 times

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: KeyboardInterrupt Ctrl+c does not work

Post by dhylands » Tue Aug 16, 2016 4:50 pm

I don't understand the difference between your working and non-working scenarios. Were they both flashed the same way?

stmfresser
Posts: 22
Joined: Sat Jun 20, 2015 11:48 am

Re: KeyboardInterrupt Ctrl+c does not work

Post by stmfresser » Tue Aug 16, 2016 5:32 pm

dhylands wrote:I don't understand the difference between your working and non-working scenarios. Were they both flashed the same way?
Yes they were both flashed same way,

Post Reply