Contents
1、Blhost : 2
1、Get-property 3
2、Excute 3
3、Exception 4
2、BCA 4
1、TAG 5
2、Enable and disable peripherals 5
3、I2C slave address 6
4、USB pidvid 6
5、Timeout 6
6、Directly jump to app 7
7、CAN configure1 configure2 7
8、CAN TX/RX ID 8
3、BUS 9
1、Different band rate 9
2、Fill memory to a big block 12
3、Write memory with high speed 12
4、CRC 15
1、Kibble_CRC_01 checkinvalid 15
2、Kibble_CRC_01 checkinactive 16
3、Kibble_CRC_02 OutOfRange 16
4、Kibble_CRC_02 CheckFailed 17
5、Kibble_CRC_04 pass 17
5、Flash 19
1、Flash_Security_0001 19
2、Flash_Fill_Memory_01 21
3、Flash_Write_Memory_01 21
4、Flash_Read_01 IFR 22
5、Flash_Read_02 23
6、FLash Call Command 01 24
7、flash PFSize 01 25
6、RAM 26
1、RAM_Fill_Memory_01 26
2、RAM_Write_Memory_01 27
3、RAM_abnormal_read_write 27
1、Blhost :
Blhost是PC跟板子进行通信的软件,查看RD提供的文件中是否有blhost ,路径\Kinetis_Bootloader_2_0_0_d1\bin
Blhost的使用手册路径
Desktop\Kinetis_Bootloader_2_0_0_d1\doc\Kinetis_blhost_User-s_Guide_review
1、Get-property
1、Get-property命令可以查看板子的属性值,属性值可以在datasheet中找到,查看是否跟datasheet中一样
2、set-property可以配置板子可写的属性值,命令格式如下
Blhost -p COM*/-u -- set-property 10/13/22 0/1
2、Excute
立即跳转到app
Demo写到指定 地址
blhost -u -- write-memory 0x8000 app_led_demo.bin
读取写入内容
blhost -u -- read-memory 0x8000 10
The first word is the address of , but with Little endian ,The second word is the address of
例如读出来的前八byte值如下
0000a411 1fffe230
Stack pointer
地址单位是字,四个字节。(MCU是32位)
使用excute命令调到app
blhost -u -- execute sencond_word_address 0 first_word_address
使用错误的地址,看是否跳不到app。如上两个红色参数分别设置错误
PC错误,不可跳到app。Stack错误,能跳到
Blhost -p com43 -- excute 0x1fffe230 0 0x0000a411
Blhost -p com43 -- excute 0x1fffe230 0 错误stack
3、Exception
Blhost -p com43 -- flash-erase-region 0x0 100 // 返回kStatusMemoryRangeInvalid
Blhost -p com43 -- write-memory 0x0 100 //写值到reserved区域,kStatusMemoryRangeInvalid
Blhost -p com43 -- read-memory 0x0 1000000 //按住ctrl+c看是否中断读取
2、BCA
BCA (bootloade rconfiguration area)是可以配置bootloader的一段区域。它位于应用程序起始地址+0x3c0处。
Bootloader启动的时候会使用默认的配置,当启动完成后。可以在如上的地址处修改bootloader的配置
BCA开始四个字节称为tag,必须设置为'kcfg'。
详细描述请参考\Kinetis_Bootloader_2_0_0_d1\doc\reference_manual中chapter 2
Kcfg in hex are 6B 63 66 67
Flash –resident 中offset为0x3c0
ROM中offset 为0x3c0
A、在offset处写入tag为kcfg,同时关闭外设(置00),重启。发现UART 、I2C等外设都不能使用。
此时要想使外设能够使用,唯一的方法就是用j-link中的unlock kinetis命令擦除
Blhost -u -- write-memory $BCA_OFFSET "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 00}}"
B、在offset处写入错误的tag(kcxg),同时关闭外设,重启。发现所有外设还能正常工作
Blhost -u -- write-memory $BCA_OFFSET "{ {6B 63 78 67 FF FF FF FF FF FF FF FF FF FF FF FF 00}}"
1、TAG
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 78 67 FF FF FF FF FF FF FF FF FF FF FF FF 00}}"
//all the peripherals can work
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 00}}"
//correct TAG all the peripherals can not work ,need to use jlink unlock the device
2、Enable and disable peripherals
如下截图在用户手册中截取,bit位置1表示使能,置0表示禁用
Enable UART only
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 01}}"
Blhost -p com43 -- reset
Disable uart only
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF FE}}"
I2C
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 02}}"
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF FD}}"
SPI
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 04}}"
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF FB}}"
USB
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 10}}"
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF EF}}"
CAN
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF 08}}"
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF F7}}"
3、I2C slave address
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 FF FF FF FF FF FF FF FF FF FF FF FF FF 35}}"
Blhost -p com43 -- reset
// it doesn't work
Blhost -p com42 -b i2c -- get-property 1
//it works normally
Blhost -p com42 -b i2c,0x35 -- get-property 1
4、USB pidvid
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 }}"
// { {usbVidLByte usbVidHByte usbPidLByte usbPidHByte}}"
Blhost -p com43 -- write-memory 0x10003d0 "{ {ff ff ff ff a2 15 75 00 }}"
Blhost -p com43 -- reset
blhost -u usbVid,usbPid
Blhost -u 0x15a2,0x0075 -- get-property 1//it works normally
4.2、USB usbStringsPointer
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67 }}"
// stings pointer
Blhost -p com43 -- write-memory 0x10003d8 "{ {65 66 67 68 }}"
Blhost -p com43 -- reset
Blhost -u -- get-property 1
5、Timeout
先下载led_demo到板子中,然后执行如下的命令,看灯是否10s后闪烁
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67}}"
Blhost -p com43 -- write-memory 0x10003d0 "{ {FF FF 10 27}}" //0x2710ms=10s
6、Directly jump to app
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67}}"
Blhost -p com43 -- write-memory 0x10003d0 "{ {FF //代码效果参考:http://www.zidongmutanji.com/zsjx/552677.html
FF 10 27}}" //设置app启动延时Blhost -p com43 -- write-memory 0x10003d8 "{ {ff ff ff ff ff ff 00 ff}}" //直接跳转flag
//after led blink directl
CAN
写死速率为0,若只是配置tag,则速率都可以使用,且不需要复位
125K 250K 500K 1M
0 1 2 4
3e9 :can-config1
3ea-3eb : can-config2
CAN RX/TX ID
Default :canTxId=0xffff ,txId=0x123;Else : txId= canTxId 0x7ff.//cantxid 跟TXID不是一回事,blhost使用的是txid,同理rx也是这个情况
Default :canRxId=0xffff ,rxId=0x321;Else : rxId= canRxId 0x7ff.
3ec-3ed canTxId
3ee-3ef canRxId
函数:flexcan_peripheral_init
Canconfig1 0x08,若为真,也就是canconfig1 bit【3】 = 1的情况下,则根据canconfig2配置speed
若为假,则根据canconfig1 bit【0:2】的值计算速率
从下面的代码中可以看出,bit【0:2】的值>=3就默认使用default,也就是1M
计算方式如下:
switch (s_flexcanInfo.baudrate)
{
case 0:
config.baudRate = 125000;
break;
case 1:
config.baudRate = 256000;
break;
case 2: //代码效果参考:http://www.zidongmutanji.com/bxxx/113000.html
config.baudRate = 500000;
break;
case 3:
case 4:
default:
config.baudRate = 1000000;
break;
}
7、CAN configure1 configure2
1、配置BCAtag,不设置速率,则0,1,2,4速率都可以使用
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67}}"
Blhost -p com13 -b can,1 -- get-property 1
2、配置3e9处速率,测试只能在该速率下通信
Blhost -p com43 -- write-memory 0xa3e0 "{ { ff ff ff ff ff ff ff ff ff f0 ff ff ff ff ff ff }}"
Blhost -p com13 -b can,0 -- get-property 1
3、配置config2内容
(Clock is based on 24Mhz.Baud rate 1M ,propseg = 4,pseg1 = 2, pseg2 = 2,pre_divider = 1,rjw = 2)
3e9 :can-config1
3ea-3eb : can-config2
Blhost -p com43 -- get-property 1
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ { 6b 63 66 67 }}"
Blhost -p com43 -- write-memory 0xa3e8 "{ { ff c8 4a 00 }}"
Blhost -p com13 -b can,4 -- get-property 1 //代码效果参考:http://www.zidongmutanji.com/zsjx/283629.html
//只用速率4pass8、CAN TX/RX ID
1、测试默认状态rxidtxid
Blhost -p com13 -b can,4,0x321,0x123 -- get-property 1 //pass
Blhost -p com13 -b can,4,0x321,0x133 -- get-property 1
Blhost -p com13 -b can,4,0x123,0x321 -- get-property 1
2、不设置速率,设置id
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67}}"
Blhost -p com43 -- write-memory 0xa3e0 "{ { ff ff ff ff ff ff ff ff ff ff ff ff ff 03 6f 66 }}"//txid = 0x03ff0x7fff = 0x03ff rxid = 0x666f0x7fff = 0x6ff
Rx tx
Blhost -p com43 -- reset
Blhost -p com13 -b can,2,0x66f,0x3ff -- get-property 1 //pass
Blhost -p com13 -b can,2,0x66f,0x123 -- get-property 1
Blhost -p com13 -b can,2,0x321,0x3ff -- get-property 1
Blhost -p com13 -b can,2,0x321,0x123 -- get-property 1
3、配置速率跟ID
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67}}"
Blhost -p com43 -- write-memory 0xa3e0 "{ { ff ff ff ff ff ff ff ff ff f1 ff ff ff 03 6f 66 }}"
Blhost -p com43 -- reset
Blhost -p com13 -b can,1,0x66f,0x3ff -- get-property 1 //pass
Blhost -p com13 -b can,0,0x66f,0x3ff -- get-property 1
Blhost -p com13 -b can,4,0x66f,0x3ff -- get-property 1
Blhost -p com13 -b can,2,0x66f,0x3ff -- get-property 1
9、Clock
Configure BCA clockDivider, also disable the peripheral of USB and set in high-speed mode
然后查看bootloader是否能正常工作
简单来说就是usb使能的话就一定是工作在high speed mode,所以必须是48M,要想配置24M这种必须将usb关掉。
1、Configure core clock to 24MHz.
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67 ff ff ff ff ff ff ff ff ff ff ff ff 07 ff ff ff ff ff ff ff ff ff ff ff fe fe ff ff}}"
Blhost -p com43 -- get-property 1
2、Configure core clock to 8MHz.
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67 ff ff ff ff ff ff ff ff ff ff ff ff 07 ff ff ff ff ff ff ff ff ff ff ff fe fa ff ff}}"
3、Configure core clock to 4MHz.
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67 ff ff ff ff ff ff ff ff ff ff ff ff 07 ff ff ff ff ff ff ff ff ff ff ff fe f4 ff ff}}"
3、BUS
Bus就是总线,是连接各个部件的一组信号线。我们测试的总线有如下几种:UART、I2C、SPI、USB、CAN
测试不同速率下的总线是否能正常工作
1、Different band rate
UART:
Blhost -p com43 -- reset
Blhost -p com43,4800 -- get-property 1
Blhost -p com43,9600 -- get-property 1
Blhost -p com43,19200 -- get-property 1
Blhost -p com43,25600 -- get-property 1
Blhost -p com43,38400 -- get-property 1
Blhost -p com43,57600 -- get-property 1
Blhost -p com43,115200 -- get-property 1
USB:
blhost -u -- get-property 1
SPI:
Blhost -p com42 -b spi,5 -- get-property 1
Blhost -p com42 -b spi,10 -- get-property 1
Blhost -p com42 -b spi,20 -- get-property 1
Blhost -p com42 -b spi,50 -- get-property 1
Blhost -p com42 -b spi,100 -- get-property 1
Blhost -p com42 -b spi,200 -- get-property 1
Blhost -p com42 -b spi,500 -- get-property 1
Blhost -p com42 -b spi,1000 -- get-property 1
Blhost -p com42 -b spi,2000 -- get-property 1
I2C:
blhost -p com42 -b i2c -- get-property 1
blhost -p com42 -b i2c,0x10,5 -- get-property 1
blhost -p com42 -b i2c,0x10,50 -- get-property 1
blhost -p com42 -b i2c,0x10,100 -- get-property 1
blhost -p com42 -b i2c,0x10,400 -- get-property 1
CAN:
125K
Blhost -p com13 -b can -- flash-erase-all
Blhost -p com13 -b can -- write-memory 0x3c0 "{ { 6b 63 66 67 }}"
Blhost -p com13 -b can -- write-memory 0x3e0 "{ { ff ff ff ff ff ff ff ff ff f0 ff ff ff ff ff ff }}"
Blhost -p com13 -b can -- reset
Blhost -p com13 -b can,0 -- fill-memory 0x0 0x1000 0xfe byte
Blhost -p com13 -b can,0 -- read-memory 0x0 0x1000
250k:
Blhost -p com13 -b can -- flash-erase-all
Blhost -p com13 -b can -- write-memory 0x3c0 "{ { 6b 63 66 67 }}"
Blhost -p com13 -b can -- write-memory 0x3e0 "{ { ff ff ff ff ff ff ff ff ff f1 ff ff ff ff ff ff }}"
Blhost -p com13 -b can -- reset
Blhost -p com13 -b can,1 -- fill-memory 0x0 0x1000 0xfe byte
Blhost -p com13 -b can,1 -- read-memory 0x0 0x1000
500k:
Blhost -p com13 -b can -- flash-erase-all
Blhost -p com13 -b can -- write-memory 0x3c0 "{ { 6b 63 66 67 }}"
Blhost -p com13 -b can -- write-memory 0x3e0 "{ { ff ff ff ff ff ff ff ff ff f2 ff ff ff ff ff ff }}"
Blhost -p com13 -b can -- reset
Blhost -p com13 -b can,2 -- fill-memory 0x0 0x1000 0xfe byte
Blhost -p com13 -b can,2 -- read-memory 0x0 0x1000
1M:
Blhost -p com13 -b can -- flash-erase-all
Blhost -p com13 -b can -- write-memory 0x3c0 "{ { 6b 63 66 67 }}"
Blhost -p com13 -b can -- write-memory 0x3e0 "{ { ff ff ff ff ff ff ff ff ff f4 ff ff ff ff ff ff }}"
Blhost -p com13 -b can -- reset
Blhost -p com13 -b can,4 -- fill-memory 0x0 0x1000 0xfe byte
Blhost -p com13 -b can,4 -- read-memory 0x0 0x1000
2、Fill memory to a big block
To check all the bus driver
向内存写入大量数据后读出来比对是否正确,来判断驱动是否正常
UART:
Blhost -p com43 -- flash-erase-all
blhost -t 100000 -p com43,115200 -- fill-memory 0x0 20000 0x10
blhost -t 100000 -p com43,115200 -- read-memory 0x0 20000
SPI:
blhost -t 10000 -p com42 -b spi,2000,1,1,msb -- fill-memory 0xb000 0x10000 0xfe
blhost -t 10000 -p com42 -b spi,2000,1,1,msb -- read-memory 0xb000 0x10000
I2C:
blhost -t 10000 -p com42 -b i2c,0x10,400 -- fill-memory 0xb000 0x10000 0xfe
blhost -t 10000 -p com42 -b i2c,0x10,400 -- read-memory 0xb000 0x10000
CAN:
blhost -t 10000 -p com42 -b can -- fill-memory 0xb000 0x10000 0xfe
blhost -t 10000 -p com42 -b can -- read-memory 0xb000 0x10000
3、Write memory with high speed
配置peripheral高速模式下写入大量数据
UART:
blhost -t 10000 -p com43 -- flash-erase-all
blhost -t 10000 -p com43,115200 -- get-property 1
blhost -t 10000 -p com43,115200 -- write-memory 0x0 文件
blhost -t 10000 -p com43,115200 -- read-memory 0x0 0x10000
I2C:
blhost -t 10000 -p com42 -b i2c,0x10,400 -- flash-erase-all
blhost -t 10000 -p com42 -b i2c,0x10,400 -- write-memory 0xb000 0x10000
blhost -t 10000 -p com42 -b i2c,0x10,400 -- read-memory 0xb000 0x10000
SPI:
blhost -t 10000 -p com42 -b spi,2000,1,1,msb -- write-memory 0xb000 0x10000
blhost -t 10000 -p com42 -b spi,2000,1,1,msb -- read-memory 0xb000 0x10000
CAN :
blhost -t 10000 -p com13 - b can -- write-memory 0x3c0 "{ { 6b 63 66 67 }}"
blhost -t 10000 -p com13 - b can -- write-memory 0x3e0 "{ { ff ff ff ff ff ff ff ff ff f4 ff ff ff ff ff ff }}"
blhost -t 10000 -p com13 -b can,4 -- write-memory 0xb000 0x10000
blhost -t 10000 -p com13 -b can,4 -- read-memory 0xb000 0x10000
4、spurious data test
测试拔除通信线的情况下是否能通信或者不能通信的情况下占用通信通道
UART:
拔除uart RX线:
blhost -t 10000 -p com43 -- get-property 1 //fail
blhost -t 10000 -p com13 -b spi -- get-property 1 //pass
reset
blhost -t 10000 -p com43 -- get-property 1 //fail
插线
blhost -t 10000 -p com43 -- get-property 1 //pass
I2C:
拔除I2C SDA线
blhost -t 10000 -p com13 - b i2c -- get-property 1 //fail
blhost -t 10000 -p com13 - b spi -- get-property 1 //pass
reset
blhost -t 10000 -p com13 - b i2c -- get-property 1 //fail
插线
blhost -t 10000 -p com13 - b i2c -- get-property 1 //pass
SPI:
拔除SPI sin线
blhost -t 10000 -p com13 - b spi -- get-property 1 //fail
blhost -t 10000 -p com13 - b i2c -- get-property 1 //pass
reset
blhost -t 10000 -p com13 - b spi -- get-property 1 //fail
插线
blhost -t 10000 -p com13 - b spi -- get-property 1 //pass
CAN:
拔除CAN 任意一根线
blhost -t 10000 -p com13 - b can -- get-property 1 //fail
blhost -t 10000 -p com13 - b i2c -- get-property 1 //pass
reset
blhost -t 10000 -p com13 - b can -- get-property 1 //fail
插线
blhost -t 10000 -p com13 - b can -- get-property 1 //pass
4、CRC
BCA起始地址0x0(start address of user application)+0x3c0(offset)
3c4-3c7 : crcStartaddress 都是4byte
3c8-3cb : crcByteCount
3cc-3cf : crcExpectedValue
1、Kibble_CRC_01 checkinvalid
直接使用command
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- get-property 8
配置BCA,但是crc相关字节全部设置为ff
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67 ff ff ff ff ff ff ff ff ff ff ff ff }}"
Blhost -p com43 -- reset
Blhost -p com43 -- get-property 8
2、Kibble_CRC_01 checkinactive
设置tag,不设置PC值,但是非全部ff
Blhost -p com43 -- write-memory 0x3c0 "{ {6B 63 66 67}}"
//BCA is valid and and crc parameters are set (not all 0xff bytes).
//开启Tag,但是其余值全部设为0
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67 00 00 00 00 00 00 00 00 00 00 00 00}}"
//BCA中CRC相关值写为0
Blhost -p com43 -- reset
Blhost -p com43 -- get-property 8 //返回值应该为kStatus_AppCrcCheckInactive
3、Kibble_CRC_02 OutOfRange
必须设置PC值
BCA is valid and and crc byte count is equal to zero.
A、
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ {6b 63 66 67 00 00 00 00 00 00 00 00 ff ff ff ff}}"
Blhost -p com43 -- write-memory 0x0 "{ {ff ff ff ff 01 00 00 00}}"
// set a PC pointer which is used for the bootloader check process。。a000处开始的四个字节是stack
Blhost -p com43 -- reset
Blhost -p com43 -- get-property 8
//except return value shoul be kStatus_AppCrcCheckOutOfRange
BCA is valid and and crc start address + count > END address
B、
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ { 6b 63 66 67 ff ff ff ff 00 00 00 02 ff ff ff ff}}"
//Blhost -p com43 -- write-memory 0x3c0 "{ { 6b 63 66 67 ff ff ff ff 00 00 00 00 00 00 00 00}}"
Blhost -p com43 -- write-memory 0x0 "{ {ff ff ff ff 01 00 00 00}}"
// set a PC pointer which is used for the bootloader check process
Blhost -p com43 -- reset
Blhost -p com43 -- get-property 8
//except return value shoul be kStatus_AppCrcCheckOutOfRange
BCA is valid and and crc end address exceeds 4G address space
C、
Blhost -p com43 -- flash-erase-all
Blhost -p com43 -- write-memory 0x3c0 "{ { 6b 63 66 67 00 00 08 00 00 00 00 02 ff ff ff ff }}"
Blhost -p com43 -- write-memory 0x0 "{ {ff ff ff ff 01 00 00 00}}"
// set a PC pointer which is