Something strange with timers

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Something strange with timers

Post by Giovanni »

Apparently it is this thing upsetting it:

Code: Select all

  if (notempty(&iqp->q_waiting))
    chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK;


Something that works perfectly in all other compilers, including IAR for ARM. I am using the compiler version 1.30.1,the latest.

Turning optimizations off makes the error disappear.

This confirms my tradition of finding bugs in proprietary compilers within the first 30 minutes...

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Something strange with timers

Post by Giovanni »

Hi,

I committed the IAR port and a demo for the STM8S-Discovery. I adjusted the intctx and extcts structures and I think those are now correct.

The following points remain open:
1) The port is untested because the test suite cannot run in 8K, the LED flashes, that is all the testing done...
2) Compiler problems, there is no way I can make this port "official" until the problem is well understood and fixed.
3) The demo runs on compiler 1.30.1 only with optimizations disabled.

It could stay this way but it will never be present in any stable release until the above points are addressed.

About credits, how do you want to appear? "king2" or your full name? you did a good work despite all the problems :-)

Giovanni
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Something strange with timers

Post by king2 »

Giovanni wrote:Apparently it is this thing upsetting it:

Code: Select all

  if (notempty(&iqp->q_waiting))
    chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK;

Something that works perfectly in all other compilers, including IAR for ARM. I am using the compiler version 1.30.1,the latest.

I had those errors, but made it disappeared (end do not remember how :))
I will try to fetch fresh version from SVN and compile it later. I'm using IAR 1.30.1 and now no erros at any level of optimization..
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Something strange with timers

Post by king2 »

Giovanni wrote:Hi,
I committed the IAR port and a demo for the STM8S-Discovery. I adjusted the intctx and extcts and I think those are now correct.

The following points remain open:
1) The port is untested because the test suite cannot run in 8K, the LED flashes, that is all the testing done...
2) Compiler problems, there is no way I can make this port "official" until the problem is well understood and fixed.
3) The demo runs on compiler 1.30.1 only with optimizations disabled.

It could stay this way but it will never be present in any stable release until the above points are addressed.

About credits, how do you want to appear? "king2" or your full name? you did a good work despite all the problems :-)

Giovanni


I tried to compile fresh sources from GIT.

0. in stm8s.h struct CLK_struct have no field named CANCCR, so it is needed to place __IO uint8_t CANCCR; instead of REERVED2.
1. I have tested port (not demos, just my app) with port received from GIT and it works perfectly with many threads. My solution (declare task functions with __task worked and your solution - make place in ctx'es for IAR - works too).
2. I have no errors you discovered with fresh fetched port.
3. I do not have theese messages at any level of optimization.

So, for now I have at least two solutuions that makes ChibiOS works, now I have fetched fresh port and working with it (except I have added my i2c implementation - 2 files - to hal/platforms/STM8S).
If I will meet any problems, I will let you know. Now it works perfectly, but I will test it more.

What about credits, I have done this work not for credits, but yes, 'king2' is my stable :) nickname.
Big thanks for help!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Something strange with timers

Post by Giovanni »

CANCCR has already been addressed you should updated also hal_lld.c.

Giovanni
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Something strange with timers

Post by king2 »

Giovanni wrote:CANCCR has already been addressed you should updated also hal_lld.c.

Giovanni

I have updated entire OS path.
hal_lld.c contains CLK->CANCCR = STM8S_CAN_DIVIDER_VALUE line (for STM8S208 only), but structure CLK does not contain CANCCR in CLK_struct, it contains RESERVED1 instead.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Something strange with timers

Post by Giovanni »

Apparently that register disappeared entirely from the reference manual, tomorrow I will look into it.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Something strange with timers

Post by Giovanni »

I removed that setting entirely, it disappeared from the documentation.

Giovanni
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

IAR port

Post by king2 »

I have tried to compile IAR port with different data and code models and it works for small code model only.
Meduim and large code models does not works; same as large data model.

I have found that all models was supported in 1.5, so something was broken or this is IAR issue?
Now it working with Small/Medium only, so something different happens when using Medium/Medium or Medium/Large, or Large/Large..

Can you give me advice how to make it working with at least Large Data Model and Medium Code Model (I cannot understand how large data model can make port not working)?

Thank you in advance!

update: As I understand, if Medium code model is used, we should use RETF in _port_switch instead of just RET.
With Large data model parameters of _port_switch given not in X MCU register, but in ?e0 virtual register (because it is 24-bit variable), that cannot fit into 16-bit register.

So, as I understand, it is needed to make #ifdef switch inside chcore_stm8.s. Can you give me edvice how to make this (i.e how to add code that works with ?e0 to existing code)?

update2: I have found solution. Despite of solution was found, I will do not remove previous lines, may be somebody will found it useful.

1. It is needed to add __near to declaration of _port_switch:

Code: Select all

void _port_switch(Thread __near * otp);

This will force compiler to use 16-bit pointer (not so bad, because all thread structs placed in RAM, i.e. below 0xFFFF), so parameter will be passed in X register in all cases (Small, Medium and Large models). We can use X register as parameter always.

2. In Medium and Large models it is needed to change RET instruction in _port_switch to RETF.

3. In Large model it is needed to add one asm("POP A") in _port_thread_start, because we need to remove 3 bytes of pointer from stack, not only 16.

I have attached changed files, I have checked in (Code-Data) SM/SL/MM/MKL/LM/LL models and found that it is working for a first look, but I will test it more.

p.s. what about adding STM8S i2c_hal driver?
Attachments
iar_port.zip
(5.07 KiB) Downloaded 516 times
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Something strange with timers

Post by Giovanni »

Hi,

I will look into it but you understand that until the problem with the compiler is solved I have not much interest in this.

Giovanni
Post Reply