Hi Mark,
I have a tiny bit of improvement, or maybe better clues.
I downloaded the latest remotes/origin/V2.0.0 latest commit 8/24/2023
Recall I am using the KinetisK60, parameters and swap blocks are last 4k of the 512k, no internal filesystem, the SPI flash MSD appears to work completely on the application so no hardware problem.
I've detailed the exact changes I made from the original to get to a point of hardware USB enumeration, incorrect enumeration, and the debug UART 3 spits out:
Debug output when powering the board and reading debug uart 3:
_DISPLAY_SD_CARD_NOT_PRESENT() 1 second delay _DISPLAY_SD_CARD_NOT_PRESENT() 1 second delay _DISPLAY_SD_CARD_NOT_PRESENT() fnDebugMsg("No Application!!\r\n");
Clearly the hardware USB USB_MSD_DEVICE_LOADER components are being pulled in correctly to enumerate the USB MSD, but the SPI_FLASH is not being setup correct, so it is failing this part.
config.h changes
comment line 108 #define TEENSY_3_1
uncomment line 127 #define TWR_K60N512 // MK60DN512VLQ10
Uncomment line 1258 #define SPI_FILE_SYSTEM // we have an external file system via SPI interface
comment line 1259 #define FLASH_FILE_SYSTEM // we have an internal file system in FLASH
*** question regarding line 1270 #define ACTIVE_FILE_SYSTEM This line must be commented out in my application or my FAT32 gets corrupted continuously. Is this a special case directive?
When my application has this defined my flash ships FAT32 is continuously corrupted
*** possible issue **
Between 1275 and 1364 there are different configurations defines for the spi flash, however NONE are set
ADDing 2 lines after this block ***#if (defined FLASH_FILE_SYSTEM && defined SPI_FILE_SYSTEM)*** that runs from 1275 to 1364
1365 #define SPI_FLASH_W25Q // use Winbond W25Q SPI flash rather than ATMEL
1355 #define FILE_GRANULARITY (4 * SPI_FLASH_BLOCK_LENGTH) // defined in app_hw_kinetis.h
uncomment 1715 #define SPI_FLASH_FAT
comment 1775 #define UTFAT16 // not needed
since I am loading from onboard IC's I should be able to comment this out so the debugger will send debug messages?
#define UTFAT_DISABLE_DEBUG_OUT // disable general mass-storage output so that the SREC loader is not disturbed
Loader.h ** not much here to change starting location is 0x9080 in the linker as I have shown in previous comments
change line 203 from 23 to 36 #define UTASKER_APP_START (36 * 1024)
change line 217 from 64 to 476 #define UTASKER_APP_END (unsigned char *)(UTASKER_APP_START + (476 * 1024)) // use entire chip
app_hw_kinetis.h
Clocking Changes for my PCB:
Change line 375 from #define EXTERNAL_CLOCK 50000000 to #define CRYSTAL_FREQUENCY 24000000
Change line 376 to CRYSTAL_FREQUENCY
Change 378 to 12
delete a space at 480 and insert a new line at 376 #define OSC_LOW_GAIN_MODE
change line 804 to be PACKAGE_LQFP
Insert into blank line at 676 #define MASK_5N22D // RJS 9/21/2022
GPIO changes:
edit lines 1809 - 1813 to PORTE_BIT26
edit lines 1821-1825 to PORTE_BIT25
edit lines 1834 watchdog init to use port E
edit 1873 and 1874 to define them to zero #define INIT_WATCHDOG_DISABLE() 0 WATCHDOG_DISABLE() 0
Edit line 1884 to use port E
edit line 1890 to define to 1 always forcing serial loader #define FORCE_BOOT() 1 Always enter serial loader to check
edit line 1900 to define to 0 always leave loader mode #define RETAIN_LOADER_MODE() 0 Never, always proceed
Copy lines 4808 to 4839 outside of the preprocessor define area
begin with line 4841
#else
#define CS0_LINE SPI_PUSHR_PCS0 // CS0 line used when SPI FLASH is enabled
#define CS1_LINE SPI_PUSHR_PCS1 // CS1 line used when extended SPI FLASH is enabled
#define CS2_LINE SPI_PUSHR_PCS2 // CS2 line used when extended SPI FLASH is enabled
#if defined SPI_FLASH_DEVICE_COUNT && (SPI_FLASH_DEVICE_COUNT >= 4)
#define CS3_LINE SPI_PUSHR_PCS3 // CS3 line used when extended SPI FLASH is enabled
#endif
#define SPI_CS0_PORT ~(SPI0_PUSHR) // for simulator
#define SPI_CS1_PORT ~(SPI0_PUSHR) // for simulator
#define SPI_CS2_PORT ~(SPI0_PUSHR) // for simulator
#define SPI_CS3_PORT ~(SPI0_PUSHR) // for simulator
#define SPI_TX_BYTE SPI0_PUSHR // for simulator
#define SPI_RX_BYTE SPI0_POPR // for simulator
#define POWER_UP_SPI_FLASH_INTERFACE() POWER_UP_ATOMIC(6, SPI0)
#define CONFIGURE_SPI_FLASH_INTERFACE() _CONFIG_PERIPHERAL(D, 0, (PD_0_SPI0_PCS0 | PORT_SRE_FAST | PORT_DSE_HIGH));\
_CONFIG_PERIPHERAL(D, 1, (PD_1_SPI0_SCK | PORT_SRE_FAST | PORT_DSE_HIGH));\
_CONFIG_PERIPHERAL(D, 2, (PD_2_SPI0_SOUT | PORT_SRE_FAST | PORT_DSE_HIGH));\
_CONFIG_PERIPHERAL(D, 3, (PD_3_SPI0_SIN));\
SPI0_MCR = (SPI_MCR_MSTR | SPI_MCR_DCONF_SPI | SPI_MCR_CLR_RXF | SPI_MCR_CLR_TXF | SPI_MCR_PCSIS_CS0 | SPI_MCR_PCSIS_CS1 | SPI_MCR_PCSIS_CS2 | SPI_MCR_PCSIS_CS3 | SPI_MCR_PCSIS_CS4 | SPI_MCR_PCSIS_CS5);\
SPI0_CTAR0 = (SPI_CTAR_DBR | SPI_CTAR_FMSZ_8 | SPI_CTAR_PDT_7 | SPI_CTAR_BR_2 | SPI_CTAR_CPHA | SPI_CTAR_CPOL); // for 50MHz bus, 25MHz speed and 140ns min de-select time
#define POWER_DOWN_SPI_FLASH_INTERFACE() POWER_DOWN(6, SIM_SCGC6_SPI0) // power down SPI interface if no SPI Flash detected
#define FLUSH_SPI_FIFO_AND_FLAGS() SPI0_MCR |= SPI_MCR_CLR_RXF; SPI0_SR = (SPI_SR_EOQF | SPI_SR_TFUF | SPI_SR_TFFF | SPI_SR_RFOF | SPI_SR_RFDF);
#define WRITE_SPI_CMD0(byte) SPI0_PUSHR = (byte | SPI_PUSHR_CONT | ulChipSelectLine | SPI_PUSHR_CTAS_CTAR0) // write a single byte to the output FIFO - assert CS line
#define WRITE_SPI_CMD0_LAST(byte) SPI0_PUSHR = (byte | SPI_PUSHR_EOQ | ulChipSelectLine | SPI_PUSHR_CTAS_CTAR0) // write final byte to output FIFO - this will negate the CS line when complete
#define READ_SPI_FLASH_DATA() (unsigned char)SPI0_POPR
#define WAIT_SPI_RECEPTION_END() while ((SPI0_SR & SPI_SR_RFDF) == 0) {}
#define CLEAR_RECEPTION_FLAG() SPI0_SR |= SPI_SR_RFDF
#define SET_SPI_FLASH_MODE() // this can be used to change SPI settings on-the-fly when the SPI is shared with SPI Flash and other devices
#define REMOVE_SPI_FLASH_MODE() // this can be used to change SPI settings on-the-fly when the SPI is shared with SPI Flash and other devices
line 4874 is the new
#endif
With these changes I get 2 failures in KinetisSim.c (uFILE_START) and WinSim.c (FILE_SYSTEM_SIZE) NOT FOUND
I add into app_hw_kinetis.h 4875 and 4876
#define FILE_SYSTEM_SIZE (128*1024)
#define uFILE_START (512 * 1024)