Page 2 of 5
Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 9:56 pm
by Giovanni
Is the USB connected to an host?
Giovanni
Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 10:09 pm
by dash
yes, the USB connected to host.
I just checked, without connection (power only), the system works for a long time
Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 10:20 pm
by Giovanni
Then it is likely related to USB, probably the simple code you shown is not relevant to the problem.
Giovanni
Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 10:58 pm
by dash
yes, it seems to USB-related, but the chThdSleepMillisecond() also has an impact
for example, this code works fine
Code: Select all
while (true)
{
uint8_t rxbyte = streamGet(&SDU1);
}
moreover, commands are correctly received and sent over USB-serial.
more complex code works fine (with SPI and PWM blocks enabled)
but as soon as I insert chThdSleepMillisecond(), I get a system crash

Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 11:20 pm
by faisal
Please post the version output from your compiler.
Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 11:35 pm
by dash
arm-none-eabi-gcc.exe (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
btw, with disabled optimizations (-O0) it works

Now I will find a module that is incorrectly compiled
Re: strange behavior of the scheduler on STM32F070
Posted: Sun Nov 11, 2018 11:43 pm
by faisal
I haven't looked at this issue in detail sorry. But have you considered placing a hardware memory watchpoint in a strategic location to catch the culprit in action?
Re: strange behavior of the scheduler on STM32F070
Posted: Mon Nov 12, 2018 12:50 am
by dash
disabling of optimization for the os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.c seems to have completely solved the problem.
hmm... faisal, I don't know where is this strategic location. empty readylist is normal situation, but chSchDoReschedule() call should be blocked by chSchIsPreemptionRequired()
in this case chSchDoReschedule() is in some fantastic way called bypassing conditions
besides, I don't really understand how context switching happens
in addition, the cortex-m0 has very limited debugging facilities. I could not even set a memory breakpoint with write condition

Re: strange behavior of the scheduler on STM32F070
Posted: Mon Nov 12, 2018 6:57 pm
by dash
as I expected, the function ST_HANDLER is incorrectly optimized. Unfortunately, gcc does not allow switching the optimization inside the function.
going to deeply learn ARM assembler

Re: strange behavior of the scheduler on STM32F070
Posted: Mon Nov 12, 2018 7:04 pm
by Giovanni
Yes, GCC allows to optimize the single function, look into the manual, it is one of the __attribute__ of functions.
Strange anyway, I never experienced it, you could return to one of the 6.x versions, it would also be a good idea to report it.
Could you explain the problem? just to make sure it is not a problem in OUR code.
Giovanni