Skip to content

Commit

Permalink
DEBUG output to MCU
Browse files Browse the repository at this point in the history
  • Loading branch information
tpunix committed Apr 19, 2023
1 parent 7ee3544 commit f38e48b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 24 deletions.
11 changes: 11 additions & 0 deletions Firm_Saturn/cdblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ int my_bios_loadcd_read(void)
return 0;
}

extern int to_stm32;
extern int gets_from_stm32;

int read_1st(void)
{
printk("Read main ...\n");
Expand All @@ -882,6 +885,14 @@ int read_1st(void)
go();

patch_game((char*)0x06002020);

if(game_break_pc){
set_break_pc(game_break_pc, 0);
install_ubr_isr();
to_stm32 = 1;
gets_from_stm32 = 1;
*(u32*)(0x22820000) = 0;
}
}


Expand Down
13 changes: 5 additions & 8 deletions Firm_Saturn/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,22 @@ int smpc_cmd(int cmd)

/**********************************************************/


void stm32_puts(char *str)
{
u32 stm32_base = 0x22820000;
int i, len;

//len = strlen(str);
//len += 1;
len = 32;
*(u16*)(stm32_base+0x00) = len;
len = strlen(str);
LE32W((void*)(stm32_base+0), len);

for(i=0; i<len; i+=2)
*(u16*)(stm32_base+0x10+i) = *(u16*)(str+i);
memcpy((void*)stm32_base+0x10, str, len+1);

SS_CMD = 0x0001;
//while(SS_CMD);
while(SS_CMD);
}



/**********************************************************/

const int HZ = 1000000;
Expand Down
2 changes: 2 additions & 0 deletions Firm_Saturn/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ void install_ubr_isr(void);
void set_break_pc(u32 addr, u32 mask);
void set_break_rw(u32 addr, u32 mask, int rw);

extern int game_break_pc;

#define BRK_READ 0x04
#define BRK_WRITE 0x08
#define BRK_RW 0x0c
Expand Down
17 changes: 9 additions & 8 deletions Firm_Saturn/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ int vsnprintf(char *buf, int size, char *fmt, va_list args)

void (*printk_putc)(int ch) = NULL;
void stm32_puts(char *str);
int to_stm32 = 0;


int printk(char *fmt, ...)
Expand All @@ -275,20 +276,20 @@ int printk(char *fmt, ...)
printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
va_end(args);


if(to_stm32){
stm32_puts(printk_buf);
}else{
#if 1
for (p = printk_buf; *p; p++) {
printk_putc(*p);
}
#endif

#if 0
stm32_puts(printk_buf);
for (p = printk_buf; *p; p++) {
printk_putc(*p);
}
#endif
}

return printed_len;
}


int snprintf(char *buf, int size, char *fmt, ...)
{
va_list args;
Expand Down
17 changes: 15 additions & 2 deletions Firm_Saturn/sci_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/**********************************************************/

int gets_from_stm32 = 0;

static char hbuf[128];
static int hblen = 0;
#define PROMPT "SS"
Expand All @@ -12,6 +14,18 @@ int gets(char *buf, int len)
{
int n, ch, esc;

if(gets_from_stm32){
while(1){
n = *(volatile u8*)0x22820000;
if(n)
break;
}

strcpy(buf, (u8*)0x22820010);
buf[n] = 0;
return n;
}

printk(PROMPT "> ");
n = 0;
esc = 0;
Expand Down Expand Up @@ -309,8 +323,7 @@ void sci_shell(void)
u32 addr = 0;
if(argc>0) addr = arg[0];
if(addr){
skip_patch = 1;
break_in_game(addr, NULL);
game_break_pc = addr;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Firm_Saturn/ubr_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void debug_shell(void *arg);


static int auto_break;
static int game_break_pc;
static void (*game_break_handle)(REGS *reg);
int game_break_pc;
void (*game_break_handle)(REGS *reg);


/**********************************************************/
Expand Down
7 changes: 7 additions & 0 deletions Firm_v12_STM32H750/Main/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ void simple_shell(void)

while(1){
gets(cmd, 128);
if(strncmp(cmd, "ss ", 3)==0){
int len = strlen(cmd+3);
strcpy((u8*)0x61820010, cmd+3);
*(u8*)0x61820000 = len;
continue;
}

char *sp = strchr(cmd, ' ');
if(sp){
*sp = 0;
Expand Down
4 changes: 2 additions & 2 deletions Firm_v12_STM32H750/Main/uart4.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ void uart4_init(void)
UART4->CR2 = 0;
UART4->CR3 = 0x64000000;
UART4->BRR = 0x0; // Reset
UART4->BRR = 0x0364; // 设置波特比率寄存器为115200(100M/115200)
// UART4->BRR = 0x0064; // 设置波特比率寄存器为1M(100M/1M)
// UART4->BRR = 0x0364; // 设置波特比率寄存器为115200(100M/115200)
UART4->BRR = 0x0064; // 设置波特比率寄存器为1M(100M/1M)
UART4->RQR = 0x0018;
UART4->CR1 |= 0x0001; // Enable UART4

Expand Down
2 changes: 1 addition & 1 deletion Firm_v12_STM32H750/Saturn/saturn_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ int get_subcode(void)
}

type = cdb.cr1&0xff;
SSLOG(_INFO, "get_subcode: type=%d\n", type);
//SSLOG(_INFO, "get_subcode: type=%d\n", type);

if(type==0){
// Get Q Channel
Expand Down
2 changes: 1 addition & 1 deletion Firm_v12_STM32H750/Saturn/saturn_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void ss_cmd_handle(void)
int retv;
u32 cmd = SS_CMD;

SSLOG(_INFO, "scmd_task: %04x\n", SS_CMD);
//SSLOG(_INFO, "scmd_task: %04x\n", SS_CMD);

switch(cmd){
case SSCMD_PRINTF:
Expand Down

0 comments on commit f38e48b

Please sign in to comment.