工具与软件:
您好!
Im 尝试通过 SPI 刷写微控制器(从连接的外部存储器)。
使用提供的应用手册:
适用于 Hercules TMS570LS31X MCU 的 SPI 引导加载程序(TI.com)
我演示了此函数、通过外部存储器中的数据存储器进行刷写、而不是通过 SPI 接收的数据包。
但是我有一个问题的功能 Fapi_Block。
该程序在这条线被卡住了
"while (FAPI_GET_FSM_STATUS!= Fapi_Status_Success);"
如果您愿意、我可以提供所有代码。
bl_spi.c
//***************************************************************************** // // bl_spi.c - Functions used to transfer data via the SPI port. // Author : QJ Wang. qjwang@ti.com // Date : 9-19-2012 // // Copyright (c) 2006-2011 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // //***************************************************************************** #include "bl_config.h" #include "bl_commands.h" #include "bl_spi_packet.h" #include "bl_spi.h" #include "Registers_FMC_LE.h" #include "system.h" #include "bl_flash.h" #include "hw_spi.h" #include "sci_common.h" #include "bl_led_demo.h" uint8_t g_ucStatus; extern uint32_t transferAddress; extern uint32_t transferSize; extern uint32_t g_ulUpdateStatusAddr; extern uint32_t g_ulUpdateBufferSize; //32 bytes or 8 32-bit words extern uint32_t g_pulUpdateSuccess[8]; #include "fram.h" #include "general_def.h" #define PAGE_LENGTH 16 void readPageFromExtMem(uint8_t FRAM, uint32_t packetNr, uint32_t dataDir, uint8_t *returnDir); uint16_t rExtMem(uint32_t address, uint8_t cs, bool delay); void cast8to32(uint8_t *dataIn, uint32_t *dataOut){ uint8_t littleEndian = 0; if (littleEndian) *dataOut = ((uint32_t)dataIn[3] << 24) | ((uint32_t)dataIn[2] << 16) | ((uint32_t)dataIn[1] << 8) | ((uint32_t)dataIn[0]); else *dataOut = ((uint32_t)dataIn[0] << 24) | ((uint32_t)dataIn[1] << 16) | ((uint32_t)dataIn[2] << 8) | ((uint32_t)dataIn[3]); } #define UPD_STATUS_BANK 0 #define UPD_BANK 1 enum STATUS { Success = 1, Fail = 0 }; void UpdaterSPI(spiBASE_t *node) { uint32_t dataDir = APP_BANK_B; uint32_t dataInMem_32[PAGE_LENGTH*2]; uint8_t dataInMem_8[PAGE_LENGTH*8]; uint16_t NrPages, statusOk; uint32_t FLASH_FIRST_SECTOR_SIZE; uint8_t i; uint8_t ulSize = PAGE_LENGTH*2; transferAddress = APP_START_ADDRESS; uExtMem(FRAM1); NrPages = rExtMem(APP_BANK_B_LEN, FRAM1, true); sExtMem(FRAM1); transferSize = ulSize*NrPages; FLASH_FIRST_SECTOR_SIZE = BLInternalFlashFirstSectorSizeGet(); if(transferSize > FLASH_FIRST_SECTOR_SIZE) { sciSend(scilinREG, 22, "\n\rProgram Flash failed"); sciSend(scilinREG, 18, "\n\r\tFile to large\n\r"); return; } sciSend(scilinREG, 17, "\n\rNr of pages: 0x"); sciDisplayData(scilinREG, (uint8 *) &NrPages, 2); sciSend(scilinREG, 2, "\n\r"); while(transferSize) { sciSend(scilinREG, 18, "\n\rPackets left: 0x"); sciDisplayData(scilinREG, (uint8 *) &transferSize, 4); readPageFromExtMem(FRAM1, PAGE_LENGTH, dataDir, dataInMem_8); for(i = 0; i < PAGE_LENGTH*2; i++){ cast8to32(dataInMem_8+(i*4), dataInMem_32+i); } statusOk = !Fapi_BlockProgram(UPD_BANK, transferAddress, (uint32_t)dataInMem_32, ulSize); //the program does not move beyond this point if (!statusOk) { sciSend(scilinREG, 22, "\n\rProgram Flash failed"); return; } dataDir += ulSize*4; transferAddress += ulSize; transferSize -= ulSize; } sciSend(scilinREG, 36, "\n\r\n\rApplication load was successful!"); statusOk = !Fapi_UpdateStatusProgram(UPD_STATUS_BANK, g_ulUpdateStatusAddr, (uint32_t)&g_pulUpdateSuccess[0], g_ulUpdateBufferSize); if (statusOk) { sciSend(scilinREG, 17, "\n\r\n\rReseting...\n\r"); systemREG1->SYSECR = (0x10) << 14; // The microcontroller should have reset, so this should never be reached. while(1){} } } ...............