blob: e08fdd02f1b25c1ae8c84903fc642b4b71e4e6d8 [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"
Roman Okhrimenko0c7aebc2020-09-02 13:37:51 +030030#include "watchdog.h"
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020031
32/* Define pins for UART debug output */
33
34#define CY_DEBUG_UART_TX (P5_1)
35#define CY_DEBUG_UART_RX (P5_0)
36
37#if defined(PSOC_062_2M)
38#warning "Check if User LED is correct for your target board."
39#define LED_PORT GPIO_PRT13
40#define LED_PIN 7U
41#endif
42
43#define LED_NUM 5U
44#define LED_DRIVEMODE CY_GPIO_DM_STRONG_IN_OFF
45#define LED_INIT_DRIVESTATE 1
46
47const cy_stc_gpio_pin_config_t LED_config =
48{
49 .outVal = 1,
50 .driveMode = CY_GPIO_DM_STRONG_IN_OFF,
51 .hsiom = HSIOM_SEL_GPIO,
52 .intEdge = CY_GPIO_INTR_DISABLE,
53 .intMask = 0UL,
54 .vtrip = CY_GPIO_VTRIP_CMOS,
55 .slewRate = CY_GPIO_SLEW_FAST,
56 .driveSel = CY_GPIO_DRIVE_FULL,
57 .vregEn = 0UL,
58 .ibufMode = 0UL,
59 .vtripSel = 0UL,
60 .vrefSel = 0UL,
61 .vohSel = 0UL,
62};
63
Roman Okhrimenko0c7aebc2020-09-02 13:37:51 +030064#define WATCHDOG_UPD_MESSAGE "[BlinkyApp] Update watchdog timer started in MCUBootApp to mark successful start of user app\r\n"
65#define WATCHDOG_FREE_MESSAGE "[BlinkyApp] Turn off watchdog timer\r\n"
66
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020067#ifdef BOOT_IMG
68 #define BLINK_PERIOD (1000u)
69 #define GREETING_MESSAGE_VER "[BlinkyApp] BlinkyApp v1.0 [CM4]\r\n"
70 #define GREETING_MESSAGE_INFO "[BlinkyApp] Red led blinks with 1 sec period\r\n"
Roman Okhrimenko0c7aebc2020-09-02 13:37:51 +030071#elif defined(UPGRADE_IMG)
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020072 #define BLINK_PERIOD (250u)
73 #define GREETING_MESSAGE_VER "[BlinkyApp] BlinkyApp v2.0 [+]\r\n"
74 #define GREETING_MESSAGE_INFO "[BlinkyApp] Red led blinks with 0.25 sec period\r\n"
75#else
76 #error "[BlinkyApp] Please specify type of image: -DBOOT_IMG or -DUPGRADE_IMG\r\n"
77#endif
78
79void check_result(int res)
80{
Roman Okhrimenko0c7aebc2020-09-02 13:37:51 +030081 if (res != CY_RSLT_SUCCESS) {
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020082 CY_ASSERT(0);
83 }
84}
85
86void test_app_init_hardware(void)
87{
88 /* enable interrupts */
89 __enable_irq();
90
91 /* Disabling watchdog so it will not interrupt normal flow later */
92 Cy_GPIO_Pin_Init(LED_PORT, LED_PIN, &LED_config);
93 /* Initialize retarget-io to use the debug UART port */
94 check_result(cy_retarget_io_init(CY_DEBUG_UART_TX, CY_DEBUG_UART_RX,
95 CY_RETARGET_IO_BAUDRATE));
96
97 printf("\n===========================\r\n");
98 printf(GREETING_MESSAGE_VER);
99 printf("===========================\r\n");
100
101 printf("[BlinkyApp] GPIO initialized \r\n");
102 printf("[BlinkyApp] UART initialized \r\n");
103 printf("[BlinkyApp] Retarget I/O set to 115200 baudrate \r\n");
104
105}
106
107int main(void)
108{
109 uint32_t blinky_period = BLINK_PERIOD;
110
111 test_app_init_hardware();
112
113 printf(GREETING_MESSAGE_INFO);
114
Roman Okhrimenko0c7aebc2020-09-02 13:37:51 +0300115 /* Update watchdog timer to mark successful start up of application */
116 printf(WATCHDOG_UPD_MESSAGE);
117 cy_wdg_kick();
118 printf(WATCHDOG_FREE_MESSAGE);
119 cy_wdg_free();
120
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +0200121 for (;;)
122 {
123 /* Toggle the user LED periodically */
124 Cy_SysLib_Delay(blinky_period/2);
125
126 /* Invert the USER LED state */
127 Cy_GPIO_Inv(LED_PORT, LED_PIN);
128 }
129 return 0;
130}