完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,最近我正在研究我们的产品上的Bootloader特性。我使用MCC生成的Bootloader源代码,Bootloader源代码通过UART接口发送和接收来自主机应用程序的命令。我的目标是使用I2C接口将此代码导入到Bootloader中。我做了一个演示应用程序,它只是切换一个LED,我连接的照片与树莓PI。我编写了一个Python脚本来尝试Bootloader特性,一切都很好。但是当我把这个引导加载到我们的生产中,并且这个应用程序比演示更大的时候,我发现有一些错误,这可能是因为我把PIC变为轮询I2C从设备的错误方式。我遇到的问题是,如果主机使用I2C块读取将导致I2C接口CRAS。H.在通过Bootloader更新应用程序后,如果我使用读闪存来比较十六进制数据和Apple Access文件,我总是会发现一些数据不匹配。Bootloader I2C接口中的代码如下:当需要引导程序时,这个程序将运行到while循环中,并且继续检查SSP2STATBES.BF2,检查I2C BUFF是否满。如果它满了,我将转到与I2C2BLYX PORCESSE()相同的I2C2BLYPROCESSUSER(),与I2C ISR从MICROCHIP相同。I2C2YSTATUS回调与原来的回调几乎相同,但我用它来处理引导加载程序缓冲区。我把它变为轮询I2C从设备有意义吗?
以上来自于百度翻译 以下为原文 Hi all, Recently I am working on the bootloader feature on our production. I use the bootloader source code generated by mcc, the bootloader source code transmit and receive the command from the host application through the uart interface. My goal is to port this code to a bootloader using i2c interface. I made a demo app which is just toggle a led , and I connect the pic with a raspberry pi. I wrote a python script to try the bootloader feature and everything is fine. But when I put this bootloader on our production and the application is bigger than the demo, I found there is something wrong and this may be caused by the wrong way I chang the pic to a polling I2c slave device. The issue I met is
When the bootloader is required, this program will run into a while loop, and keep to check to see the SSP2STATbits.BF2 to check the i2c buff full or not. If it is full , i will go to the I2C2_BL_porcess() which is the same as the original with the i2c isr from the microchip. the I2C2_StatusCallback is almost the same with the original callback which but I use it to process the Bootloader command buffer. does the way I change it to polling i2c slave device make sense? void Run_Bootloader() { while (1) { Check_Device_Reset(); if(1 == SSP2STATbits.BF2){ I2C2_BL_porcess(); } } } void I2C2_BL_porcess(void){ uint8_t i2c_data = 0x55; // NOTE: The slave driver will always acknowledge // any address match. i2c_data = SSP2BUF; // read SSPBUF to clear BF if(1 == SSP2STATbits.R_nW) { if((1 == SSP2STATbits.D_nA) && (1 == SSP2CON2bits.ACKSTAT)) { // callback routine can perform any post-read processing I2C2_StatusCallback(I2C2_SLAVE_READ_COMPLETED); } else { // callback routine should write data into SSPBUF I2C2_StatusCallback(I2C2_SLAVE_READ_REQUEST); } } else if(0 == SSP2STATbits.D_nA) { // this is an I2C address // callback routine should prepare to receive data from the master I2C2_StatusCallback(I2C2_SLAVE_WRITE_REQUEST); } else { I2C2_slaveWriteData = i2c_data; // callback routine should process I2C2_slaveWriteData from the master I2C2_StatusCallback(I2C2_SLAVE_WRITE_COMPLETED); } SSP2CON1bits.CKP = 1; // release SCL } |
|
相关推荐
6个回答
|
|
MCC Bootloader与I2C驱动程序不兼容。这主要是因为I2C驱动程序使用的中断使ISR复杂化并增加了延迟:ISR需要解决的第一个问题是“此中断是针对BL还是针对应用程序?”任意地制定一个规则“引导加载程序将不使用中断”更简单更快,因此中断总是发送到应用程序。当MCC支持没有中断的I2C驱动程序时,我们将使它兼容。I2C_BL_Process将需要将字节累积到命令中,然后传递当读取下降时,返回到内存接口并返回结果。(也许这就是回调中发生的事情,但是我们在那里没有可见性)。
以上来自于百度翻译 以下为原文 The MCC bootloader is not compatible with the I2C driver. This is mostly because the I2C driver uses interrupts which complicates the ISR and adds latency: The first question the ISR needs to figure out "is this interrupt for the BL or for the application?". It's simpler and faster to arbitrarily make a rule "the bootloader will not use interrupts", hence the interrupt is always sent to the application. When MCC supports an I2C driver without interrupts, we'll make it compatible. The I2C_BL_Process will need to accumulate bytes into commands, then pass that to the memory interface and return the results when the read comes down. (Maybe that's what's happening in the callbacks, but we have no visibility there). |
|
|
|
也就是说,很有可能做一个引导加载程序I2C从机。(我假设引导加载程序是从属)。例如:http://WW1.Microchip .com /…EN/AppNOTE/01302A.PDF
以上来自于百度翻译 以下为原文 That said it is very possible to make a Bootloader I2C slave. ( I am assuming the Bootloader is the slave). Example: http://ww1.microchip.com/...en/AppNotes/01302A.pdf |
|
|
|
嗨,我认为在消息#1中提出的想法是可行的,测试任一个:SSP2STATbit.BF2或PIR3bit.SSP2IF都可以工作,只要PIE3bits.SSP2IE或GIE/PEIE被清除,这样中断处理程序就不会被激活。与重置的连接,或者激活I2C从属程序和引导加载程序的其他操作。不过,在I2C从属程序响应不够快,并且从主程序溢出的情况下,可能有一些带有定时的娱乐。当引导加载程序正在擦除块或在闪存中写入时,CPU将停止处理指令几毫秒。在消息#1中,您报告已经做了一些实验,并且遇到某种问题。没有足够的信息来理解问题或解决方案m。对。据我所知,在十六进制文件中,每行都包含一个内存地址、内存数据和校验和。这些数据行不必排序。如果在编程后从PIC读回Flash,则所得到的.hex文件的排序可能与原来的不同。文件的纯文本差异不会说明文件是否包含相同的程序。通过创建单独的I2C从代码实例,甚至可以在应用程序代码中使用与普通I2C从代码相同的MSSP模块。原版海报,问候,Mysil
以上来自于百度翻译 以下为原文 Hi, I think the idea presented in message #1 is doable, testing either: SSP2STATbits.BF2 or PIR3bits.SSP2IF may both work, as long as PIE3bits.SSP2IE or GIE/PEIE are cleared, such that interrupt handler isn't activated. I assume this is intended for running the polled I2C Slave for a limited time in connection with Reset, or some other action to activate the I2C Slave and Bootloader. Still, there may be some entertainment with timing, in case the I2C slave code do not respond fast enough, and get overrun from the master. When a Bootloader is erasing blocks, or writing in Flash memory, the CPU will stop processing instructions for several milliseconds. In message #1 you report to have done some experiments, and experience some kind of problem. There is not enough information to understand what the problem or solution might be. As far as I know, in a hexfile, each line contain a memory address, memory data, and a checksum. These data lines do not have to be ordered. If you read Flash back from the PIC after programming, the resulting .hex file may be ordered differently than the original. A plain textual diff of the files will not tell if the files contain the same program. By creating a separate instance of I2C Slave code, it may even be possible to use the same MSSP module as ordinary I2C Slave in application code. Danno in message #2 seem to misunderstand the suggestion made by the original poster. Regards, Mysil |
|
|
|
Bootloader从机除了汇集标志别无他法。如果数据太快,主机可以根据需要降低波特率或增加延迟。Bootloader从机不能使用中断驱动I2C,也不需要。PIC18有两个中断,一个可能用于引导加载。R,另一个为主程序。但那是非常笨拙的。
以上来自于百度翻译 以下为原文 The Bootloader slave has nothing to do but pool the flags. If the Data is too fast, the Host can drop the Baud rate or add in delays as needed. The Bootloader slave can not use interrupt driven I2C, nor does it needed too. Well not exactly true The PIC18 has 2 interrupts, One could be for the Bootloader , and the other for the main program. But that is very Hacky. |
|
|
|
大家好,很抱歉没有注意到您的回复。我已经找到了我在这篇文章中提到的所有问题的解决方案。我没有像最初那样在引导加载程序中启用中断(像MCC一样)。现在Run_bootloader()是I2C2_BL_process()是应用程序十六进制文件更新,i2c wirte读取一切正常吗?是引导引导程序到I2C接口的好方法吗?我还有一个关于从引导加载程序跳到应用程序的问题。如果您对这个主题感兴趣,可以查看url.http://www..hip.com/for./m972572.aspx。
以上来自于百度翻译 以下为原文 Hi all, Sorry for not noticing your reply. I have find the solution on all the issues I mentioned in this post. I did not enable the interrupt in the bootloader like what I originally did(like the MCC did). Now the Run_bootloader() is void Run_Bootloader() { while (1) { Check_Device_Reset(); if(PIR3bits.SSP2IF == 1){ I2C2_BL_porcess(); } } } the I2C2_BL_process() is void I2C2_BL_porcess(void){ i2c_data = SSP2BUF; // read SSPBUF to clear BF if(1 == SSP2STATbits.R_nW) { if((1 == SSP2STATbits.D_nA) && (1 == SSP2CON2bits.ACKSTAT)) { // callback routine can perform any post-read processing I2C2_StatusCallback(I2C2_SLAVE_READ_COMPLETED); } else { // callback routine should write data into SSPBUF I2C2_StatusCallback(I2C2_SLAVE_READ_REQUEST); } } else if(0 == SSP2STATbits.D_nA) { // this is an I2C address // callback routine should prepare to receive data from the master I2C2_StatusCallback(I2C2_SLAVE_WRITE_REQUEST); } else { I2C2_slaveWriteData = i2c_data; // callback routine should process I2C2_slaveWriteData from the master I2C2_StatusCallback(I2C2_SLAVE_WRITE_COMPLETED); } SSP2CON1bits.CKP = 1; // release SCL PIR3bits.SSP2IF = 0; // clear the slave interrupt flag } the application hex file update and the i2c wirte read all work fine. Do you think this is a good way to port the bootloader to I2C interface? I have another question on jump form bootloader to the application. If your are interested on the topic, you can check the url. http://www.microchip.com/forums/m972572.aspx |
|
|
|
如果可能的话,你能与社区共享完整的代码吗?/问候
以上来自于百度翻译 以下为原文 Can you share complete code with community if possible? /regards |
|
|
|
只有小组成员才能发言,加入小组>>
5171 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
531浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 00:11 , Processed in 1.417933 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号