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 10:18:53 -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 06UHBJ1P018620; Thu, 30 Jul 2020 13:11:31 -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 06UHBIjE018615 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 13:11:18 -0400 Received: from oc11exedge1.exchange.mit.edu (OC11EXEDGE1.EXCHANGE.MIT.EDU [18.9.3.17]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 06UH9sCq015591 for ; Thu, 30 Jul 2020 13:09:56 -0400 Received: from oc11expo16.exchange.mit.edu (18.9.4.47) by oc11exedge1.exchange.mit.edu (18.9.3.17) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 13:10:30 -0400 Received: from oc11exhyb5.exchange.mit.edu (18.9.1.110) by oc11expo16.exchange.mit.edu (18.9.4.47) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 30 Jul 2020 13:10:57 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.102) by oc11exhyb5.exchange.mit.edu (18.9.1.110) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Thu, 30 Jul 2020 13:10:57 -0400 Received: from DM6PR11CA0013.namprd11.prod.outlook.com (2603:10b6:5:190::26) by CH2PR01MB5717.prod.exchangelabs.com (2603:10b6:610:40::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 17:10:56 +0000 Received: from DM3NAM03FT026.eop-NAM03.prod.protection.outlook.com (2603:10b6:5:190:cafe::9b) by DM6PR11CA0013.outlook.office365.com (2603:10b6:5:190::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 17:10:56 +0000 Received: from premium47-4.web-hosting.com (68.65.123.244) by DM3NAM03FT026.mail.protection.outlook.com (10.152.82.185) 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 17:10:55 +0000 Received: from 107-145-246-199.res.spectrum.com ([107.145.246.199]:52198 helo=[192.168.10.105]) by premium47.web-hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1k1C4w-002fS9-0Y; Thu, 30 Jul 2020 13:10:55 -0400 From: Neil To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 10:10:46 -0700 Subject: Re: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AdZmlYBj/rnDUUK0RzW4efIenXwcFw== Message-ID: <5F22FF16.9030607@narwani.org> 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: None (protection.outlook.com: narwani.org does not designate permitted sender hosts) dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=narwani.org ; s=default; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:Reply-To:To:References:Subject:Sender:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=eMuEcdnMXYY6lqxpIZdVQDJWvv0WonHjlccgIOGJ0FI=; b=Zrr8jchYOM8Q5cJ4vxJKFI9qRb AEho89VWbMGbL811EwTx6zyPI3UifwZylvbHofZiqAy7xVkrtLANLQ6Jdrer8YnnTb9cby/YwXi5B E97Nn5bvB50riuKpX5pvs0DO5PkKpaoP68LkrK0vo+G+OH3BrqZ10hgCr1eRXrtvY4/VtUm+gg2JY mKnHeUlhilUOURazYxtjGP5ISrO4fi2vb98H9RYrJJ56P81eyqgwiXvt8iIiB0xw47O0+zlJviYSj h3jSi3bdaW6dBEjbxg8aVoodJHM4X5/SJiZ9OXzVPAJz0eYi63dWd1ktdiX2+0jERidE/lJ5AKoWU iS038RDQ==; authentication-results: spf=none (sender IP is 68.65.123.244) smtp.mailfrom=narwani.org; mit.edu; dkim=pass (signature was verified) header.d=narwani.org;mit.edu; dmarc=bestguesspass action=none header.from=narwani.org; user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 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-source-args: x-source-dir: x-antiabuse: Sender Address Domain - narwani.org x-source: x-authenticated-sender: premium47.web-hosting.com: ca4@narwani.org x-topics: [PIC] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Bob, Strange way to do this IMO... I would keep ports & pins together in a=20 struct for each GPIO, then group those together for your call to=20 lcd_create(). Either way, I'm not sure why gcc thinks your port and pin definitions=20 aren't constants. Aren't you using CMSIS for those definitions? In HAL (which ultimately uses CMSIS), ports and pins are defined in the=20 mail header file like this... #define LED_Pin GPIO_PIN_13 #define LED_GPIO_Port GPIOC Then these are further defined in a deeper file as: #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13=20 selected */ and... #define GPIOC ((GPIO_TypeDef *)GPIOC_BASE) and then... #define GPIOC_BASE (APB2PERIPH_BASE + 0x00001000UL) and also... /*!< Peripheral memory map */ #define APB1PERIPH_BASE PERIPH_BASE #define APB2PERIPH_BASE (PERIPH_BASE + 0x00010000UL) #define AHBPERIPH_BASE (PERIPH_BASE + 0x00020000UL) ....which are constants. How/where do you have your ports and pins defined? Cheers, -Neil. On 7/30/2020 12:50 PM, Bob Blick wrote: > Hi Sean, > > Here it is: > > https://github.com/4ilo/HD44780-Stm32HAL > > Thanks, Bob > > ________________________________________ > From: piclist-bounces@mit.edu on behalf of Sean= Breheny > Sent: Thursday, July 30, 2020 9:38 AM > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] Simple GCC question > > 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 work= s >> great but I'm stuck with a variable scope problem that I can only seem t= o >> 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_Pi= n}; >> 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 wo= uld >> 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 > --=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 .