Hi Guys,
I'm trying to use GCC-AVR to set up the clock prescale on an ATmega32U4,
using the clock_prescale_set() function as outlined in the "avr/power.h
" header file.
If I call:
clock_prescale_set(clock_div_1)
or
clock_prescale_set(0);
where clock_prescale_set is defined in "avr/power.h" as follows:
typedef enum
{
clock_div_1 = 0,
clock_div_2 = 1,
clock_div_4 = 2,
clock_div_8 = 3,
clock_div_16 = 4,
clock_div_32 = 5,
clock_div_64 = 6,
clock_div_128 = 7,
clock_div_256 = 8
#if defined(__AVR_ATmega128RFA1__) \
|| defined(__AVR_ATmega256RFR2__) \
|| defined(__AVR_ATmega2564RFR2__) \
|| defined(__AVR_ATmega128RFR2__) \
|| defined(__AVR_ATmega1284RFR2__) \
|| defined(__AVR_ATmega64RFR2__) \
|| defined(__AVR_ATmega644RFR2__)
, clock_div_1_rc = 15
#endif
} clock_div_t;
void clock_prescale_set(clock_div_t __x)
{
uint8_t __tmp = _BV(CLKPCE);
__asm__ __volatile__ (
"in __tmp_reg__,__SREG__" "\n\t"
"cli" "\n\t"
"sts %1, %0" "\n\t"
"sts %1, %2" "\n\t"
"out __SREG__, __tmp_reg__"
: /* no outputs */
: "d" (__tmp),
"M" (_SFR_MEM_ADDR(CLKPR)),
"d" (__x)
: "r0");
}
I get the following in-line assembler generated (.lss file extract):
void clock_prescale_set(clock_div_t __x)
{
uint8_t __tmp = _BV(CLKPCE);
__asm__ __volatile__ (
12a: 90 e0 ldi r25, 0x00 ; 0
12c: 80 e8 ldi r24, 0x80 ; 128
12e: 0f b6 in r0, 0x3f ; 63
130: f8 94 cli
132: 80 93 61 00 sts 0x0061, r24
136: 90 93 61 00 sts 0x0061, r25
13a: 0f be out 0x3f, r0 ; 63
which I can understand, but if I call:
clock_prescale_set(clock_div_4);
or:
clock_prescale_set(2);
I get exactly the same code generated, in other words:
void clock_prescale_set(clock_div_t __x)
{
uint8_t __tmp = _BV(CLKPCE);
__asm__ __volatile__ (
12a: 90 e0 ldi r25, *0x00* ; 0
12c: 80 e8 ldi r24, 0x80 ; 128
12e: 0f b6 in r0, 0x3f ; 63
130: f8 94 cli
132: 80 93 61 00 sts 0x0061, r24
136: 90 93 61 00 sts 0x0061, r25
13a: 0f be out 0x3f, r0 ; 63
where I would expect to get this:
void clock_prescale_set(clock_div_t __x)
{
uint8_t __tmp = _BV(CLKPCE);
__asm__ __volatile__ (
12a: 90 e0 ldi r25, *0x02* ; 0
12c: 80 e8 ldi r24, 0x80 ; 128
12e: 0f b6 in r0, 0x3f ; 63
130: f8 94 cli
132: 80 93 61 00 sts 0x0061, r24
136: 90 93 61 00 sts 0x0061, r25
13a: 0f be out 0x3f, r0 ; 63
I don't get any compilation errors, so I think it sees the enum okay and
the assembly listing is fresh each time I try. I'm sure I must be doing
something simplisticly crazy, but I think I need help, because this is
driving me nuts and it's been a long day. I'm used to using separate
assembler files and I'm not a great boffin on using in-line assembly,
but I really think I need to get a collar on it.
Many thanks to whoever can help, best regards,
Alistair.
PS: My tool set versions are as follows::
Atmel Studio 6 (Version: 6.2.1153 - )
© 2014 Atmel Corp.
All rights reserved.
OS Version: Microsoft Windows NT 5.2.3790 Service Pack 2
Platform: Win32NT
Installed Packages: Shell VSIX manifest - 6.2
Shell VSIX manifest
Version: 6.2
Package GUID: 5aa6ea3e-da7b-48c1-9b2a-cab2329d32ac
Company: Atmel Corporation
Installed Packages: Atmel ARM GNU Toolchain - 4.8.3.1429
ARM Toolchain
Version: ARM_Toolchain_Version:4.8.3.277 GCC_VERSION:4.8.3
Package GUID: D83C9208-1D2D-4665-9760-EB9EE264CF8F
Company: Atmel
HelpUrl:
Release Description: ARM Toolchain
CMSIS
Version: 3.20
Package GUID: D83C9208-1D2D-4665-9760-EB9EE264CF8F
Company: Atmel
HelpUrl:
Release Description: ARM Support File Version
Installed Packages: AVR macro Assembler - 2.1.39.1117
AVR Assembler
Version: 2.1.39.232
Package GUID: 03CB4AE1-80EA-40C7-B561-98CC87EA539C
Company: Atmel
HelpUrl:
Release Description: AVR Assembler For 8-Bit Devices
Installed Packages: Atmel AVR (32 bit) GNU Toolchain - 3.4.2.1057
AVR Toolchain 32
Version: AVR32_Toolchain_Version:3.4.2.435 GCC_VERSION:4.4.7
Package GUID: DB6D383F-C5D9-4E7E-BBF9-F37C6EEB59FD
Company: Atmel
HelpUrl:
Release Description: AVR Toolchain For 32-Bit Devices
Installed Packages: Atmel AVR (8 bit) GNU Toolchain - 3.4.4.1056
AVR Toolchain 8 Bit
Version: AVR8_Toolchain_Version:3.4.4.1229 GCC_VERSION:4.8.1
Package GUID: 2C7AA7CF-94C6-463C-81DA-4AA03B613C3B
Company: Atmel
HelpUrl:
Release Description: AVR Toolchain For 8-Bit Devices
Installed Packages: Atmel Gallery - 1.3.1
Atmel Gallery
Version: 1.3.1
Package GUID: AtmelStudioExtensionManager
Company: Atmel
Installed Packages: Atmel Software Framework - 3.21.0.1353
ASF
Version: 3.21.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.21.0
Release Description: ASF - 3.21.0 Release
ASF
Version: 3.20.1
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.20.1
Release Description: ASF - 3.20.1 Release
ASF
Version: 3.19.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.19.0
Release Description: ASF - 3.19.0 Release
ASF
Version: 3.18.1
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.18.1
Release Description: ASF - 3.18.1 Release
ASF
Version: 3.18.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.18.0
Release Description: ASF - 3.18.0 Release
ASF
Version: 3.17.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.17.0
Release Description: ASF - 3.17.0 Release
ASF
Version: 3.16.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.16.0
Release Description: ASF - 3.16.0 Release
ASF
Version: 3.15.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.15.0
Release Description: ASF - 3.15.0 Release
ASF
Version: 3.14.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.14.0
Release Description: ASF - 3.14.0 Release
ASF
Version: 3.13.1
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.13.1
Release Description: ASF - 3.13.1 Release
ASF
Version: 3.12.1
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.12.1
Release Description: ASF - 3.12.1 Release
ASF
Version: 3.11.0
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.11.0
Release Description: ASF - 3.11.0 Release
ASF
Version: 3.10.1
Package GUID: 1E567EA3-6E83-4C11-8734-684F4581B25D
Company: Atmel
HelpUrl: http://asf.atmel.com/3.10.1
Release Description: ASF - 3.10.1 Release
Installed Packages: Atmel Kits - 1.7.291
Atmel Kits
Version: 1.7.291
Package GUID: B624D6C6-CB86-4887-A57F-327D248085A9
Company: Atmel
Installed Packages: AtmelToolchainProvider - 6.2.666
AtmelToolchainProvider
Version: 6.2.666
Package GUID:
AtmelToolchainProvider.Atmel.0780A430-065B-4EFD-B0D1-FC957262E6DF
Company: Atmel
Installed Packages: LiveWatch - 1.4.306
LiveWatch
Version: 1.4.306
Package GUID: 07290e21-75bd-4363-8d07-a5fa8e32876e
Company: Atmel
Installed Packages: MemoryLogger - 6.2.167
MemoryLogger
Version: 6.2.167
Package GUID: 99A2A244-8218-4868-A0D1-A1683E6FCC53
Company: Atmel
Installed Packages: Percepio Trace for Atmel Studio - 1.0
Percepio Trace for Atmel Studio
Version: 1.0
Package GUID: fe274744-c496-42fc-9e52-f77b92d669b1
Company: Percepio AB
Installed Packages: Visual Assist for Atmel Studio - 10.8.2023.3
Visual Assist for Atmel Studio
Version: 10.8.2023.3
Package GUID: 7997A33C-B154-4b75-B2AC658CD58C9510
Company: Whole Tomato Software
Installed Packages: GdbConsole - 1.0
GdbConsole
Version: 1.0
Package GUID: d616f47a-811f-4a7e-bcb8-8fe696222d92
Company: Atmel
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list