blob: 936511d53f4cd2170b13b0816c00dcfbf089234b [file] [log] [blame]
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +02001/*
2 * Copyright (c) 2020 Cypress Semiconductor Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 /*
7 * Licensed to the Apache Software Foundation (ASF) under one
8 * or more contributor license agreements. See the NOTICE file
9 * distributed with this work for additional information
10 * regarding copyright ownership. The ASF licenses this file
11 * to you under the Apache License, Version 2.0 (the
12 * "License"); you may not use this file except in compliance
13 * with the License. You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing,
18 * software distributed under the License is distributed on an
19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 * KIND, either express or implied. See the License for the
21 * specific language governing permissions and limitations
22 * under the License.
23 */
24 /*******************************************************************************/
25
26#include "system_psoc6.h"
27#include "cy_pdl.h"
28#include "cyhal.h"
29#include "cy_retarget_io.h"
30
31/* Define pins for UART debug output */
32
33#define CY_DEBUG_UART_TX (P5_1)
34#define CY_DEBUG_UART_RX (P5_0)
35
36#if defined(PSOC_062_2M)
37#warning "Check if User LED is correct for your target board."
38#define LED_PORT GPIO_PRT13
39#define LED_PIN 7U
40#endif
41
42#define LED_NUM 5U
43#define LED_DRIVEMODE CY_GPIO_DM_STRONG_IN_OFF
44#define LED_INIT_DRIVESTATE 1
45
46const cy_stc_gpio_pin_config_t LED_config =
47{
48 .outVal = 1,
49 .driveMode = CY_GPIO_DM_STRONG_IN_OFF,
50 .hsiom = HSIOM_SEL_GPIO,
51 .intEdge = CY_GPIO_INTR_DISABLE,
52 .intMask = 0UL,
53 .vtrip = CY_GPIO_VTRIP_CMOS,
54 .slewRate = CY_GPIO_SLEW_FAST,
55 .driveSel = CY_GPIO_DRIVE_FULL,
56 .vregEn = 0UL,
57 .ibufMode = 0UL,
58 .vtripSel = 0UL,
59 .vrefSel = 0UL,
60 .vohSel = 0UL,
61};
62
63#ifdef BOOT_IMG
64 #define BLINK_PERIOD (1000u)
65 #define GREETING_MESSAGE_VER "[BlinkyApp] BlinkyApp v1.0 [CM4]\r\n"
66 #define GREETING_MESSAGE_INFO "[BlinkyApp] Red led blinks with 1 sec period\r\n"
67#elif UPGRADE_IMG
68 #define BLINK_PERIOD (250u)
69 #define GREETING_MESSAGE_VER "[BlinkyApp] BlinkyApp v2.0 [+]\r\n"
70 #define GREETING_MESSAGE_INFO "[BlinkyApp] Red led blinks with 0.25 sec period\r\n"
71#else
72 #error "[BlinkyApp] Please specify type of image: -DBOOT_IMG or -DUPGRADE_IMG\r\n"
73#endif
74
75void check_result(int res)
76{
77 if (res != CY_RSLT_SUCCESS)
78 {
79 CY_ASSERT(0);
80 }
81}
82
83void test_app_init_hardware(void)
84{
85 /* enable interrupts */
86 __enable_irq();
87
88 /* Disabling watchdog so it will not interrupt normal flow later */
89 Cy_GPIO_Pin_Init(LED_PORT, LED_PIN, &LED_config);
90 /* Initialize retarget-io to use the debug UART port */
91 check_result(cy_retarget_io_init(CY_DEBUG_UART_TX, CY_DEBUG_UART_RX,
92 CY_RETARGET_IO_BAUDRATE));
93
94 printf("\n===========================\r\n");
95 printf(GREETING_MESSAGE_VER);
96 printf("===========================\r\n");
97
98 printf("[BlinkyApp] GPIO initialized \r\n");
99 printf("[BlinkyApp] UART initialized \r\n");
100 printf("[BlinkyApp] Retarget I/O set to 115200 baudrate \r\n");
101
102}
103
104int main(void)
105{
106 uint32_t blinky_period = BLINK_PERIOD;
107
108 test_app_init_hardware();
109
110 printf(GREETING_MESSAGE_INFO);
111
112 for (;;)
113 {
114 /* Toggle the user LED periodically */
115 Cy_SysLib_Delay(blinky_period/2);
116
117 /* Invert the USER LED state */
118 Cy_GPIO_Inv(LED_PORT, LED_PIN);
119 }
120 return 0;
121}