From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89924 invoked by alias); 23 Feb 2019 15:34:28 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 89904 invoked by uid 89); 23 Feb 2019 15:34:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL autolearn=no version=3.3.2 spammy=Hx-languages-length:1334, H*f:sk:AA53195, H*i:sk:AA53195, device X-HELO: asav22.altibox.net Received: from asav22.altibox.net (HELO asav22.altibox.net) (109.247.116.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 23 Feb 2019 15:34:25 +0000 Received: from mail.jansenbrown.no (unknown [51.174.108.167]) by asav22.altibox.net (Postfix) with ESMTP id 723B820035; Sat, 23 Feb 2019 16:34:22 +0100 (CET) Received: from [192.168.4.243] (unicorn.lan [192.168.4.243]) by mail.jansenbrown.no (Postfix) with ESMTPSA id 8E12119772F; Sat, 23 Feb 2019 16:34:21 +0100 (CET) Subject: Re: AVR __progmem__ variable reading To: =?UTF-8?Q?=c5=81ukasz_Kostka?= , gcc@gcc.gnu.org References: From: David Brown Message-ID: Date: Sat, 23 Feb 2019 15:34:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=ecATgYMH c=1 sm=1 tr=0 a=U0L3DYRvxOwaPRbtiaGbog==:117 a=U0L3DYRvxOwaPRbtiaGbog==:17 a=IkcTkHD0fZMA:10 a=CFTnQlWoA9kA:10 a=69wJf7TsAAAA:8 a=mDV3o1hIAAAA:8 a=-oZ11aZ6xEGzdqzH3hgA:9 a=viVcjeRui9TiSmCL:21 a=fKW49oOKGw54Ownp:21 a=QEXdDO2ut3YA:10 a=ROF3mqmjF2kA:10 a=QRrLnKzKUdwA:10 a=SEt3Qbb3IwYA:10 a=Fg1AiH1G6rFz08G2ETeA:22 a=_FVE-zBwftR9WsbkzFJk:22 X-SW-Source: 2019-02/txt/msg00128.txt.bz2 On 22/02/2019 23:34, Łukasz Kostka wrote: > Hi > > I am using for a while now gcc and especially __progmem__ attribute. I’d like to report a feature request for gcc to handle reading from flash memory variables. Compiler has all the knowledge (target device, availability of LPM, ELPM instructions etc.) in order to properly interpret variable is accessed (eg. by array subscription). > > This would remove need for any assembly code written to do this. > Make user code much cleaner. > GCC having all this knowledge can optimize end assembly code. > Simple attribute addition will switch from array in memory to array in flash. > Can serve as future implementations for other platforms. > > What do you think ? > > You don't need to write assembly to read flash data with AVR gcc - you have never needed it. To use the "progmem" attribute, include the header and use the macros and functions from there, such as "pgm_read_byte". Newer versions of AVR gcc have named address spaces, making the process simpler. I must admit I haven't written any AVR code since these were added to the compiler, but I assume they work fine: