1 /***********************************************************************************************//**
2  * \file cy_serial_flash_prog.c
3  *
4  * \brief
5  * Provides variables necessary to inform programming tools how to program the
6  * attached serial flash memory. The variables used here must be placed at
7  * specific locations in order to be detected and used by programming tools
8  * to know that there is an attached memory and its characteristics. Uses the
9  * configuration provided as part of BSP.
10  *
11  ***************************************************************************************************
12  * \copyright
13  * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
14  * an affiliate of Cypress Semiconductor Corporation
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License");
19  * you may not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  *     http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS,
26  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  **************************************************************************************************/
30 
31 /**
32  * \addtogroup group_board_libs
33  * \{
34  * In addition to the APIs for reading and writting to memory at runtime, this library also
35  * provides support for informing programming tools about the external memory so it can be
36  * be written at the same time as internal flash. This support can be enabled by defining
37  * CY_ENABLE_XIP_PROGRAM while building the application. With this define in place, code
38  * will be generated in the .cy_sflash_user_data & .cy_toc_part2 sections. These sections
39  * must be provided by the linker script for the application. One the application has been
40  * built, these locations can be read by programming tools (eg: Cypress Programmer, OpenOCD,
41  * pyOCD) to know that there is a memory device attached and how to program it.
42  * \note This support is not compatible with the PSoC™ 64 series of devices.
43  * \} group_board_libs
44  */
45 
46 #include <stdint.h>
47 
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51 
52 #if defined(CY_ENABLE_XIP_PROGRAM)
53 
54 #include "cycfg_qspi_memslot.h"
55 
56 typedef struct
57 {
58     const cy_stc_smif_block_config_t* smifCfg;  // Pointer to SMIF top-level configuration
59     const uint32_t                    null_t;   // NULL termination
60 } stc_smif_ipblocks_arr_t;
61 
62 // This data can be placed anywhere in the internal memory, but it must be at a location that
63 // can be determined and used for the calculation of the CRC16 checksum in the cyToc below. There
64 // are multiple ways this can be accomplished including:
65 // 1) Placing it in a dedicated memory block with a known address. (as done here)
66 // 2) Placing it at an absolute location via a the linker script
67 // 3) Using 'cymcuelftool -S' to recompute the checksum and patch the elf file after linking
68 CY_SECTION(".cy_sflash_user_data") __attribute__((used))
69 const stc_smif_ipblocks_arr_t smifIpBlocksArr = { &smifBlockConfig, 0x00000000 };
70 
71 // This data is used to populate the table of contents part 2. When present, it is used by the boot
72 // process and programming tools to determine key characteristics about the memory usage including
73 // where the boot process should start the application from and what external memories are connected
74 // (if any). This must consume a full row of flash memory row. The last entry is a checksum of the
75 // other values in the ToC which must be updated if any other value changes. This can be done
76 // manually or by running 'cymcuelftool -S' to recompute the checksum.
77 CY_SECTION(".cy_toc_part2") __attribute__((used))
78 const uint32_t cyToc[128] =
79 {
80     0x200-4,               // Offset=0x0000: Object Size, bytes
81     0x01211220,            // Offset=0x0004: Magic Number (TOC Part 2, ID)
82     0,                     // Offset=0x0008: Key Storage Address
83     (int)&smifIpBlocksArr, // Offset=0x000C: This points to a null terminated array of SMIF
84                            //                structures.
85     0x10000000u,           // Offset=0x0010: App image start address
86                            // Offset=0x0014-0x01F7: Reserved
87     [126] =  0x000002C2,   // Offset=0x01
88                            //     Bits[ 1: 0] CLOCK_CONFIG (0=8MHz, 1=25MHz, 2=50MHz, 3=100MHz)
89                            //     Bits[ 4: 2] LISTEN_WINDOW (0=20ms, 1=10ms, 2=1ms, 3=0ms, 4=100ms)
90                            //     Bits[ 6: 5] SWJ_PINS_CTL (0/1/3=Disable SWJ, 2=Enable SWJ)
91                            //     Bits[ 8: 7] APP_AUTHENTICATION (0/2/3=Enable, 1=Disable)
92                            //     Bits[10: 9] FB_BOOTLOADER_CTL: UNUSED
93     [127] =  0x3BB30000    // Offset=0x01FC: CRC16-CCITT
94                            //     (the upper 2 bytes contain the CRC and the lower 2 bytes are 0)
95 };
96 
97 #endif // defined(CY_ENABLE_XIP_PROGRAM)
98 
99 #if defined(__cplusplus)
100 }
101 #endif
102