gpt4 book ai didi

c - 通过单个 GPIO 引脚转储闪存

转载 作者:太空狗 更新时间:2023-10-29 15:26:37 24 4
gpt4 key购买 nike

我正在使用 Infineon 的 XMC4500 Relax Kit,我正在尝试通过单个 GPIO 引脚提取固件。

我非常天真的想法是通过 GPIO 引脚一次转储一位,然后用逻辑分析仪以某种方式“嗅探”数据。

伪代码:

while(word by word memory copy hasn't finished)
...
register = value;
temp_value = value AND 0x1;
pin = temp_value;
value = value >> 1;
...

我走在正确的轨道上吗?有人有更好/更好的想法如何存档吗?

### 编辑###

实际上,我的(shell)代码的一个要求是它需要非常小。我找到了 this关于如何做的绝妙技巧通过闪烁 LED 转储固件。

但是,我很难通过 Saleae Logic Analyzer 接收正确的值。

基本上我正在做的是:

  1. 将 GPIO 引脚方向设置为输出
  2. 使用时钟(SPI 串行时钟)使 LED1(引脚 1.1)闪烁
  3. 使用数据位 (SPI MOSI) 闪烁 LED2(引脚 1.0)
  4. 使用逻辑分析仪嗅探引脚

这是我的 C 代码:

#include "XMC4500.h"

#define DEL 1260

void init()
{
// P1.0 output, push pull
PORT1->IOCR0 = 0x80UL << 0;
// P1.1 output, push pull
PORT1->IOCR0 |= 0x80UL << 8;
}

void delay(int i) {
while(--i) {
asm("nop\n");
asm("nop\n");
}
}

// Sets a pin to high
// P1.0 = SPI MOSI
// P1.1 = SPI CLOCK
void output_high(int i) {
// P1.0 high
if(i == 0) {
PORT1->OUT |= 0x1UL;
}

// P1.1 high
if(i == 1) {
PORT1->OUT |= 0x2UL;
}
}

// Sets a pin to low
// P1.0 = SPI MOSI
// P1.1 = SPI CLOCK
void output_low(int i) {
// P1.0 low
if(i == 0) {
PORT1->OUT &= (~0x1UL);
}

// P1.1 low
if(i == 1) {
PORT1->OUT &= (~0x2UL);
}
}

// SPI bit banging
void spi_send_byte(unsigned char data)
{
int i;

// Send bits 7..0
for (i = 0; i < 8; i++)
{
// Sets P1.1 to low (serial clock)
output_low(1);

// Consider leftmost bit
// Set line high if bit is 1, low if bit is 0
if (data & 0x80)
// Sets P1.0 to high (MOSI)
output_high(0);
else
// Sets P1.0 to low (MOSI)
output_low(0);

delay(DEL);

// Sets P1.1 to high (Serial Clock)
output_high(1);

// Shift byte left so next bit will be leftmost
data <<= 1;
}
}

int main() {
init();

while(1) {
spi_send_byte('t');
spi_send_byte('e');
spi_send_byte('s');
spi_send_byte('t');
}

return 0;
}

### 第二次编辑###

使用以下代码转储闪存工作正常:

#include "XMC4500.h"

// SPI bit banging
void spi_send_word(uint32_t data)
{
int i;

// LSB first, 32 bits per transfer
for (i = 0; i < 32; i++)
{
// set pin 1.1 to low (SPI clock)
PORT1->OUT &= (~0x2UL);

// set line high if bit is 1, low if bit is 0
if (data & 0x1) {
// set pin 1.0 to high (SPI MOSI)
PORT1->OUT |= 0x1UL;
}
else {
// set pin 1.0 to low (SPI MOSI)
PORT1->OUT &= (~0x1UL);
}

// set pin 1.1 to high (SPI clock)
PORT1->OUT |= 0x2UL;

data >>= 1;
}
}

int main() {
// start dumping at memory address 0x08000000
unsigned int *p;
p = (uint32_t *)(0x08000000u);

// configure pin 1.0 and pin 1.1 as output (push-pull)
PORT1->IOCR0 = 0x8080UL;

while(1) {
spi_send_word(*p);
p++;
}
}

最佳答案

您的解决方案的最大问题是恢复时间信息 - 知道一个词从哪里开始,另一个词从哪里结束。在 UART tx 引脚上输出数据会更简单 - UART 添加起始位和停止位并为您管理时序,并且可以通过常规 PC 串行端口直接读取输出。

如果您不能使用 UART,通过使用 UART 时序对 GPIO 进行位碰撞来模拟 UART 仍然允许使用传统的串行端口直接接收数据。

可以找到软件 UART 实现示例 here .在您的情况下,您当然只需要传输能力。

关于c - 通过单个 GPIO 引脚转储闪存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23978691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com