Page 2 of 4

Re: Something strange with timers

Posted: Wed Jun 27, 2012 8:43 pm
by mabl
<OT>
Hi king2,

what I've always been wondering: Why use such processors in the first place? Why not use parts which have free compilers and a strong community? Is it because of power and price consideration in mass products? But then, there are still AVRs in any size, aren't there? Or did some marketing/manager guy just decide: "You have to use it - period!"

</OT>

Re: Something strange with timers

Posted: Thu Jun 28, 2012 1:20 am
by king2
Processor selection was made because of its price, STM8S cheaper than any comparable AVR, for example it has 4 hardware PWMs.
Some time ago I have shifted from AVRs to STM8S for a-little-cheap-things and Cortex for more complex tasks.

But in this project compiler and MCU selection was made without respecting to my opinion, in fact, when I was started to rewrite this project they has boards already. So, I have not so much place to any movement here.. :(

I'm trying now to rewrite project to Raisonance compiler, tomorrow I will try to do this for Cosmic and hope that this will work:)

Re: Something strange with timers

Posted: Thu Jun 28, 2012 1:24 am
by king2
Giovanni, thank you for trying to help me. If my tries to run my project under freeware versions of Cosmic or Raisonance will fail, I will try to port this on IAR again (or switch to atomthreads).

Re: Something strange with timers

Posted: Thu Jun 28, 2012 7:53 am
by Giovanni
I'll give it a try in the weekend.

Anyway 8bit MCUs are starting to make no sense, there are Cortex-M0 devices at about the same price point. And Cortex processors make you save in other areas (peripherals, compilers, time and less trouble in general).

Giovanni

Re: Something strange with timers

Posted: Fri Jun 29, 2012 12:11 am
by king2
I've changed my project to be compatible with Cosmic and tried to run it.
It works fine, so I think it is definitely IAR port issue.

What about MCU, I'm limited with existing design and devices that was made in hardware, so I have no choice.
For a little devices I prefer STM8S, at other side such MCUs (usually) do not needs OS. :)

Anyway, thank you, I'll be waiting for weekend and will try to modify IAR port by myself.

UPDATE: I have added some things to IAR port:
- added push for b8..b15 before and pop b8..b15 after switching stack (_port_switch assembler)
- added unsigned char vreg[8]; to start_ctx structure so it can be popped at first switch
At least on this time it is working a little bit better, but freezes anyway. It switches to empty area of memory, then to __iar_unhandled_exception();
I cannot catch where it brokes. Optimization is off.

So, few questions:
1. What do "popw x" in _port_thread_start?
2. Should I add something to _port_thread_start (pop/push, something else?)
3. How to catch it? Now it just jumps from unknown address to (random?) place and that's all..

Re: Something strange with timers

Posted: Fri Jun 29, 2012 7:14 am
by Giovanni
Hi,

You should post your chcore.h and chcore.c or it would be difficult to give any help.

Giovanni

Re: Something strange with timers

Posted: Fri Jun 29, 2012 2:41 pm
by king2
OK, I attached it here.

ISR asm listing follows:

Code: Select all

   \                                 In section .near_func.text, align 1
    113          __interrupt void TIM2_OVR_UIF(void) {
   \                     TIM2_OVR_UIF:
   \                     _interrupt_15:
   \   000000 8A                    PUSH      CC
   \   000001 84                    POP       A
   \   000002 A4BF                  AND       A, #0xbf
   \   000004 88                    PUSH      A
   \   000005 86                    POP       CC
   \   000006 CD0000                CALL      L:?push_l0
   \   000009 CD0000                CALL      L:?push_l1
    114              CH_IRQ_PROLOGUE();
   \   00000C CD0000                CALL      L:dbg_check_enter_isr
    115              chSysLockFromIsr();
   \   00000F CD0000                CALL      L:dbg_check_lock_from_isr
    116              chSysTimerHandlerI();
   \   000012 CD0000                CALL      L:chSysTimerHandlerI
    117              chSysUnlockFromIsr();
   \   000015 CD0000                CALL      L:dbg_check_unlock_from_isr
    118              TIM2->SR1 = 0;
   \   000018 35005302              MOV       L:0x5302, #0x0
    119              CH_IRQ_EPILOGUE();
   \   00001C CD0000                CALL      L:dbg_check_leave_isr
   \   00001F CD0000                CALL      L:dbg_check_lock
   \   000022 CD0000                CALL      L:chSchIsPreemptionRequired
   \   000025 A100                  CP        A, #0x0
   \   000027 2703                  JREQ      L:??TIM2_OVR_UIF_0
   \   000029 CD0000                CALL      L:chSchDoReschedule
   \                     ??TIM2_OVR_UIF_0:
   \   00002C CD0000                CALL      L:dbg_check_unlock
    120          }
   \   00002F CD0000                CALL      L:?pop_l1
   \   000032 CD0000                CALL      L:?pop_l0
   \   000035 80                    IRET
    121         


?l0 and ?l1 - first 8 bytes of virtual registers, i.e. ?b0..?b7.

Re: Something strange with timers

Posted: Fri Jun 29, 2012 10:30 pm
by king2
I have tried to debug application and found that IAR's compiler inside task functions call ?push_w4, that not simple pop'ed info from stack, it reads and writes stack directly, broking info in start_ctx structure.

After defining task functions with __task prefix (do not save and restore context in this function), all is working perfectly (for now :)).

Thank you for help!

Re: Something strange with timers

Posted: Sat Jun 30, 2012 8:03 am
by Giovanni
I see some more issues in those files, I am going to make a revision but probably I will not be able to test it with the 8K limit.

Giovanni

Re: Something strange with timers

Posted: Sat Jun 30, 2012 9:00 am
by Giovanni
I am hitting problems while compiling, most modules compile but I get this error:

Tool Internal Error:
Internal Error: [`anonymous-namespace'::Base::Validate]: Malformed instruction.
Internal Error: [`anonymous-namespace'::Base::Validate]: Malformed instruction.
Error while running C/C++ Compiler


from chqueues.c and chsem.c. Not sure about the meaning of the above message.

Giovanni