AtmelStudio 7 atmega128 ChibiosHAL compile error

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

Bogdan
Posts: 21
Joined: Fri Apr 08, 2016 4:33 pm
Location: Ukraine Lviv
Has thanked: 2 times
Been thanked: 3 times
Contact:

AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby Bogdan » Fri Apr 08, 2016 8:39 pm

Hello everybody.

Chibios version stable 16.1 from git repo.
I use chibiosRT and ChibiosHAL in my project and I have some problems compiling ChibiosHAL in Atmelstudio 7 for atmega128.
I fix them localy.
But I wanted to ask whether you can make fixes to the repository if it really bugs
And maybe get some clarification.

Below list of issues:
1. Upsent defines (TIFR1, TIMSK1) for atmel128 i have (TIFR, TIMSK).

2. Uncorect prescaler register init for atmega128
Old version:
#define AVR_TIMER_PRESCALER 64
#define AVR_TIMER_PRESCALER_BITS (0<<CS02)|(1<<CS01)|(1<<CS00); /* CLK/64 */

#define AVR_TIMER_PRESCALER 256
#define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(0<<CS01)|(0<<CS00); /* CLK/256 */

#define AVR_TIMER_PRESCALER 1024
#define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(0<<CS01)|(1<<CS00); /* CLK/1024 */

Fix version:
#define AVR_TIMER_PRESCALER 64
#define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(0<<CS01)|(0<<CS00); /* CLK/64 */

#define AVR_TIMER_PRESCALER 256
#define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(1<<CS01)|(0<<CS00); /* CLK/256 */

#define AVR_TIMER_PRESCALER 1024
#define AVR_TIMER_PRESCALER_BITS (1<<CS02)|(1<<CS01)|(1<<CS00); /* CLK/1024 */

3. Can't compile received error: impossible constraint in 'asm'
Old version
#define pal_lld_setpad(port, pad) \
__asm__ __volatile__( \
"sbi %0,%1\n\t" :: "I" (_SFR_IO_ADDR(port->out)), "I" (pad) \
)
Fix version
#define pal_lld_setpad(port, pad) \
port->out |= (1 << pad)

4. Can't compile received error: impossible constraint in 'asm'
Old version
#define pal_lld_clearpad(port, pad) \
__asm__ __volatile__( \
"cbi %0,%1\n\t" :: "I" (_SFR_IO_ADDR(port->out)), "I" (pad) \
)
Fix version
#define pal_lld_clearpad(port, pad) \
port->out &= ~(1 << pad)

Thanks!

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby utzig » Sat Apr 09, 2016 3:04 pm

Hi Bogdan,

I applied the timer register and prescaler changes to both stable-16.x and trunk. As soon as the git mirror is updated please double check them because I don't have a ATmega128 (I only assured 328p and 1280 still work).

Regarding the port access I'll think about it because those old routines are highly optimized and I'm not sure why they are not working for this specific model. Maybe I could add also checks for ATmega128 like I did for timers and use standard C bit shift like you suggested but it looks somewhat less good.

Fabio Utzig

Bogdan
Posts: 21
Joined: Fri Apr 08, 2016 4:33 pm
Location: Ukraine Lviv
Has thanked: 2 times
Been thanked: 3 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby Bogdan » Sat Apr 09, 2016 6:09 pm

Hi Fabio,

I am very grateful to you for your response.

I will wait for update and will check them immediately.

I agree with you in terms of access to the port, that is not good. But at thet moment I have not found another solution to get around the compiler error.

Thank you for your support!

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby utzig » Sat Apr 09, 2016 8:42 pm

Bogdan wrote:But at thet moment I have not found another solution to get around the compiler error.

Could you paste the error here? Also please check what's the GCC version that is bundled, please. I was looking into this and it seems that your suggestion should be turned to single bit instruction (set/reset) by the compiler so that would be great and I would update the code. Still need to verify.

Btw, the github mirror (if that's what you're using) was updated already. The commit is here:

https://github.com/ChibiOS/ChibiOS/comm ... c0fc40b3c0

PS: There is also an ATmega128A which might be similar (and would need to be #ifdef checked too) but I haven't looked into that.

Cheers,
Fabio Utzig

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby utzig » Sat Apr 09, 2016 10:36 pm

Just for the curiosity of I made a small program which sets a bit and tried building using both the current asm implementation and typical C access.

The code is simply those two functions below which use the two methods of access:

Code: Select all

#include <avr/sfr_defs.h>
#include <avr/io.h>

void port_set_1(void) {
  __asm__ __volatile__("sbi %0,%1\n\t" :: "I" (_SFR_IO_ADDR(PORTA)), "I" (0));
}

void port_set_2(void) {
  PORTA |= _BV(0);
}


Building with optimizations off (avr-gcc -mmcu=atmega128 -O0 -S test.c):

Code: Select all

port_set_1:
   push r28
   push r29
   in r28,__SP_L__
   in r29,__SP_H__
   sbi 27,0
   pop r29
   pop r28
   ret
port_set_2:
   push r28
   push r29
   in r28,__SP_L__
   in r29,__SP_H__
   ldi r24,lo8(59)
   ldi r25,0
   ldi r18,lo8(59)
   ldi r19,0
   movw r30,r18
   ld r18,Z
   ori r18,lo8(1)
   movw r30,r24
   st Z,r18
   pop r29
   pop r28
   ret


Building with optimizations on (avr-gcc -mmcu=atmega128 -O2 -S test.c):

Code: Select all

port_set_1:
   sbi 27,0
   ret
port_set_2:
   sbi 0x1b,0
   ret


So, I will update the repo later!

Cheers,
Fabio Utzig

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby utzig » Sat Apr 09, 2016 10:47 pm

Done, commited!

Thanks for all the suggestions!

Bogdan
Posts: 21
Joined: Fri Apr 08, 2016 4:33 pm
Location: Ukraine Lviv
Has thanked: 2 times
Been thanked: 3 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby Bogdan » Sat Apr 09, 2016 11:34 pm

Hi Fabio,

Could you paste the error here?
I found that error "error: impossible constraint in 'asm'" occurs when i used for arguments not constant when call palSetPad().
When I used variable in pin or port i got this error.
I use in my project variables when call palSetPad().

("sbi %0,%1\n\t" :: "I" (_SFR_IO_ADDR(port->out)), "I" (pad)) solution is good for different optimisation lavel, but in my case it not compiled.

(port->out |= (1 << pad) ) work in both cases with constant and with variables. But without optimisation it not compiled in sbi instruction
palSetPad(IOPORT1, 3);
84d6: 89 e3 ldi r24, 0x39 ; 57
84d8: 90 e0 ldi r25, 0x00 ; 0
84da: 29 e3 ldi r18, 0x39 ; 57
84dc: 30 e0 ldi r19, 0x00 ; 0
84de: f9 01 movw r30, r18
84e0: 22 81 ldd r18, Z+2 ; 0x02
84e2: 28 60 ori r18, 0x08 ; 8
84e4: fc 01 movw r30, r24
84e6: 22 83 std Z+2, r18 ; 0x02
And with optimisation
palSetPad(IOPORT1, 3);
572c: db 9a sbi 0x1b, 3 ; 27

Bogdan
Posts: 21
Joined: Fri Apr 08, 2016 4:33 pm
Location: Ukraine Lviv
Has thanked: 2 times
Been thanked: 3 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby Bogdan » Sat Apr 09, 2016 11:36 pm

I see you got the same results )

Bogdan
Posts: 21
Joined: Fri Apr 08, 2016 4:33 pm
Location: Ukraine Lviv
Has thanked: 2 times
Been thanked: 3 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby Bogdan » Sat Apr 09, 2016 11:59 pm

Hi Fabio,

I pull updates in st_lld.c, st_lld.h from git repo and get set/clear fix from svn repo.
it compiles and runs well! Thank you very much!

One more modification in my local files in adc_lld.h.
I change CH_USE_SEMAPHORES to CH_CFG_USE_SEMAPHORES
And CH_USE_MUTEXES to CH_CFG_USE_MUTEXES.
Because i can't find in sources CH_USE_SEMAPHORES and CH_USE_MUTEXES.

And in adc_lld.c ADCSRB register are upsent in atmega128 so i comment "ADCSRB = 0; //single shot".

Please clarify what i must do.

Thanks!
Bogdan.

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: AtmelStudio 7 atmega128 ChibiosHAL compile error

Postby utzig » Sun Apr 10, 2016 12:18 am

Hi Bogdan,

Bogdan wrote:I change CH_USE_SEMAPHORES to CH_CFG_USE_SEMAPHORES
And CH_USE_MUTEXES to CH_CFG_USE_MUTEXES.
Because i can't find in sources CH_USE_SEMAPHORES and CH_USE_MUTEXES.

This was changed sometime ago. Seems like something was left behind! I updated the adc driver and checked other drivers and now all looks good.

The fixes were already commited.

Bogdan wrote:And in adc_lld.c ADCSRB register are upsent in atmega128 so i comment "ADCSRB = 0; //single shot".

Not sure you need this but I'll try to check tomorrow.

Cheers,
Fabio Utzig


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 2 guests