Received: from PCH.mit.edu (18.7.21.50) by mail.efplus.com (192.168.0.8) with Microsoft SMTP Server (TLS) id 8.3.485.1; Thu, 30 Jul 2020 09:46:29 -0700 Received: from PCH.MIT.EDU (localhost.localdomain [127.0.0.1]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UGd2KW013749; Thu, 30 Jul 2020 12:39:14 -0400 Received: from outgoing-exchange-1.mit.edu (OUTGOING-EXCHANGE-1.MIT.EDU [18.9.28.15]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UGd0k1013745 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 12:39:00 -0400 Received: from oc11exedge2.exchange.mit.edu (OC11EXEDGE2.EXCHANGE.MIT.EDU [18.9.3.18]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 06UGbU63013709 for ; Thu, 30 Jul 2020 12:37:38 -0400 Received: from oc11expo19.exchange.mit.edu (18.9.4.50) by oc11exedge2.exchange.mit.edu (18.9.3.18) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 12:38:28 -0400 Received: from oc11exhyb8.exchange.mit.edu (18.9.1.113) by oc11expo19.exchange.mit.edu (18.9.4.50) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 30 Jul 2020 12:38:42 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.170) by oc11exhyb8.exchange.mit.edu (18.9.1.113) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Thu, 30 Jul 2020 12:38:42 -0400 Received: from CO1PR15CA0063.namprd15.prod.outlook.com (2603:10b6:101:1f::31) by DM6PR01MB5003.prod.exchangelabs.com (2603:10b6:5:5a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 16:38:40 +0000 Received: from CO1NAM03FT054.eop-NAM03.prod.protection.outlook.com (2603:10b6:101:1f:cafe::d) by CO1PR15CA0063.outlook.office365.com (2603:10b6:101:1f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 16:38:40 +0000 Received: from mail-ej1-f41.google.com (209.85.218.41) by CO1NAM03FT054.mail.protection.outlook.com (10.152.81.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.10 via Frontend Transport; Thu, 30 Jul 2020 16:38:39 +0000 Received: by mail-ej1-f41.google.com with SMTP id kq25so15666108ejb.3 for ; Thu, 30 Jul 2020 09:38:39 -0700 (PDT) From: Sean Breheny To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 09:38:26 -0700 Subject: Re: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AdZmkPmAKXbxatfAROycabwC12DOjQ== Message-ID: References: List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: Reply-To: Microcontroller discussion list - Public. Accept-Language: en-US X-MS-Exchange-Organization-AuthAs: Anonymous X-MS-Exchange-Organization-AuthSource: TS500.efplus4.local X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-Exchange-Organization-SenderIdResult: Pass X-MS-Exchange-Organization-PRD: mit.edu X-MS-TNEF-Correlator: received-spf: Pass (protection.outlook.com: domain of gmail.com designates 209.85.218.41 as permitted sender) receiver=protection.outlook.com; client-ip=209.85.218.41; helo=mail-ej1-f41.google.com; dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornell.edu; s=g.20171207; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=uVO/iYfWPV0ZmGqegj2SbuL+GjpSE6dIxv0AD3yyPP8=; b=ERMT9zg7aSPXi0ixIrDQEnQzLjlHkbBmpcHQvk6RFU8iI/L+grOfqmNUTJidxcf9Wg wlfB4uF5yNPSB1GF442pqp5BsZsFtALh1BNGWvPhqheg5r9SE2+qJCF8mPiQxcClco1a ljOGT9acr+lstmxVdLZ/OIU1HqN6vYothq5YJKFHsq+LXYC7I1FKa5VsUHZ1dxN9RhIy t1+xxwv55iswjqMDgcX+gw8za0OnCYO+GNCk+yL4JOsMJsNMVTnlXAZq3fspIXzMobdp YTm8sKOZllyAfA3uU7Fr/ueRJhgkD2j3XhJsJUiCJst5DTchGNhbLmjfwbIBWd5nqeK8 2x7w== authentication-results: spf=pass (sender IP is 209.85.218.41) smtp.mailfrom=gmail.com; mit.edu; dkim=pass (signature was verified) header.d=cornell.edu; mit.edu; dmarc=pass action=none header.from=cornell.edu; errors-to: piclist-bounces@mit.edu list-id: "Microcontroller discussion list - Public." list-post: x-beenthere: piclist@mit.edu x-mailman-version: 2.1.6 x-received: by 2002:a17:906:3685:: with SMTP id a5mr3266039ejc.298.1596127118003; Thu, 30 Jul 2020 09:38:38 -0700 (PDT) x-topics: [PIC] x-content-filtered-by: Mailman/MimeDel 2.1.6 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Hi Bob, Do you have a link to the library you are using? I don't understand what the type of LCD_D4_GPIO_Port, etc. is. Sean On Thu, Jul 30, 2020 at 12:27 PM Bob Blick wrote: > I'm using a nice little HD44780 LCD library in an STM32 project, it works > great but I'm stuck with a variable scope problem that I can only seem to > make worse because GCC is a bit stricter than I want it to be at this > point. Sorry if the code example doesn't wordwrap properly. > > If, somewhere in main() I create an instance of the LCD like this: > Lcd_PortType ports[] =3D {LCD_D4_GPIO_Port, LCD_D5_GPIO_Port, > LCD_D6_GPIO_Port, LCD_D7_GPIO_Port}; > Lcd_PinType pins[] =3D {LCD_D4_Pin, LCD_D5_Pin, LCD_D6_Pin, LCD_D7_Pin}= ; > Lcd_HandleTypeDef lcd =3D Lcd_create(ports, pins, LCD_RS_GPIO_Port, > LCD_RS_Pin, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE); > > then I can use it like this: > Lcd_cursor(&lcd, 1,6); > > but of course I can't do that from within another function since "lcd" > only exists in main() > > If I try to make it all global by creating lcd outside of main(), GCC > doesn't like that because initializer elements must be constants and it > doesn't consider "ports" and "pins" to be constants. > > Not being a real C programmer this has stopped me in my tracks. If I was > stuck on a deserted island I would use this library as a basis for > something with ports and pins hardcoded, but I'm hoping a real expert wou= ld > give me some gentle help, which will certainly educate me about doing > things the correct way and also get me past this little hurdle. > > Thanks, Bob > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .