blob: d2da5825afef45d010da6691d7e83bf06e38987b [file] [log] [blame] [view]
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -05001### External Memory support for Secondary Slot
2
3**Description**
4
5Given document describes the use of external memory module as a secondary (upgrade) slot with Cypress' PSoC6 devices.
6
7The demonstration device is CY8CPROTO-062-4343W board which is PSoC6 device with 2M of Flash available.
8The memory module present on board is S25FL512SAGMFI010 512-Mbit external Quad SPI NOR Flash.
9
10Using external memory for secondary slot allows to nearly double the size of Boot Image.
11
12**Operation Design and Flow**
13
14The design is based on using SFDP command's auto-discovery functionality of memory module IC and Cypress' SMIF PDL driver.
15
16It is assumed that user's design meets following:
17* The memory-module used is SFDP-compliant;
18* There only one module is being used for secondary slot;
19* Only "OWERWRITE" bootloading scheme is used;
20* The address for secondary slot should start from 0x18000000.
21This corresponds to PSoC6's SMIF (Serial Memory InterFace) IP block mapping.
22* The slot size for upgrade slot is even (or smaller) to erase size (0x40000) of given memory module.
23This requirement is accepted for code simplicity.
24
25The default flash map implemented is the following:
26* [0x10000000, 0x10018000] - MCUBootApp (bootloader) area;
27* [0x10018000, 0x10028000] - primary slot for BlinkyApp;
28* [0x18000000, 0x18010000] - secondary slot for BlinkyApp;
29* [0x10038000, 0x10039000] - scratch area (not used);
30
31Size of slots `0x10000` - 64kB
32
33**Note 1**: make sure primary, secondary slot and bootloader app sizes are appropriate and correspond to flash area size defined in Applications' linker files.
34
35**Note 2**: make sure secondary slot start address is aligned (or smaller) to erase size (0x40000 - 256kB).
36
37MCUBootApp's `main.c` contains the call to Init-SFDP API which performs required GPIO configurations, SMIF IP block configurations, SFDP protocol read and memory-config structure initialization.
38
39After that MCUBootApp is ready to accept upgrade image from external memory module.
40
41Once valid upgrade image was accepted the image in external memory will be erased.
42
43**How to enable external memory support:**
44
451. Seek for `CY_BOOT_USE_EXTERNAL_FLASH` in sources and define it in any: MCUBootApp.mk or any suitable header file.
462. Navigate to `cy_flash_map.c` and check if secondary slot start address and size meet the application's needs.
473. Define which slave select is used for external memory on a board by setting `smif_id` value in `main.c`.
484. Build MCUBootApp as described in `Readme.md`.
49
50**How to build upgrade image for external memory:**
51
52 make app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE HEADER_OFFSET=0x7FE8000 ERASED_VALUE=0xff
53
54`HEADER_OFFSET` defines the offset from original boot image address. This one in line above suggests secondary slot will start from `0x18000000`.
55
56`ERASED_VALUE` defines the memory cell contents in erased state. It is `0x00` for PSoC6's internal Flash and `0xff` for S25FL512S.
57
58**Programming to external memory**
59
60The MCUBootApp programming can be done similarly to described in `Readme.md`:
61
62 export OPENOCD=/Applications/ModusToolbox/tools_2.1/openocd
63
64 ${OPENOCD}/bin/openocd -s ${OPENOCD}/scripts \
65 -f ${OPENOCD}/scripts/interface/kitprog3.cfg \
66 -f ${OPENOCD}/scripts/target/psoc6_2m.cfg \
67 -c "init; psoc6 sflash_restrictions 1" \
68 -c "init; reset init; program PATH_TO_APPLICATION.hex" \
69 -c "resume; reset; exit"
70
71There is a NULL-pointer placed for SMIF configuration pointer in TOC2 (Table Of Contents, `cy_serial_flash_prog.c`).
72This is done to force CY8PROTO-062-4343W DAP Link firmware to program external memory with hardcoded values.
73
741. Press SW3 Mode button on a board to switch the board into DAP Link mode.
752. Once DAP Link removable disk appeared drop (copy) the upgrade image HEX file to it.
76This will invoke firmware to program external memory.
77
78**Note 3:** the programming of external memory is limited to S25FL512S p/n only at this moment.