Skip to content

Commit

Permalink
a couple of handy changes
Browse files Browse the repository at this point in the history
- binaries now show "Fixed Pin Information" in picotool
- removed unused wozmon header file
MCP:
- added flash size detection
- fixed problems in CPU detection
- "cpu" command renamed to "sys", since output is expanded
- command line interface now has (short) history and line editing
- "reboot" command fixed and renamed to "cold"

Signed-off-by: Sven Oliver Moll <svolli@svolli.de>
  • Loading branch information
Sven Oliver Moll committed Aug 11, 2023
1 parent 59d3cd2 commit 1c16328
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 108 deletions.
1 change: 1 addition & 0 deletions src/rp2040/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_executable(mcp
payload_mcp.h
system_mcp.c
getaline.c
fake_eeprom.c
)
target_link_libraries(mcp
pico_stdlib
Expand Down
2 changes: 1 addition & 1 deletion src/rp2040/bus_rp2040_purple.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include "bus.h"
#include "pico/binary_info.h"
#include <pico/binary_info.h>

const bus_config_t bus_config = {
.mask_address = 0x0000FFFF, // input: 16 contiguous bits
Expand Down
46 changes: 42 additions & 4 deletions src/rp2040/cpu_detect.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
/**
* Copyright (c) 2023 SvOlli
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include "cpu_detect.h"
#include "bus.h"
#include <string.h>

#ifndef DEBUG_CPU_DETECT
#define DEBUG_CPU_DETECT (0)
#endif

#if DEBUG_CPU_DETECT
#include <stdio.h>
#endif

static uint32_t state;
static uint32_t address;

#include "cpudetect_mcp.h"

static uint8_t cpu_detect_result = 0xFF;


uint8_t cpu_detect_raw()
{
return cpu_detect_result;
}


cputype_t cpu_detect()
{
uint32_t cycles_left_reset = 8;
uint32_t cycles_left_run = 100000;
uint8_t memory[0x10];
memcpy( &memory[0], &cpudetect_mcp[0], sizeof(memory) );

while(0xFF == memory[0xF])
// set lines to required state
gpio_set_mask( bus_config.mask_rdy | bus_config.mask_irq | bus_config.mask_nmi );
#if DEBUG_CPU_DETECT
printf( "cpu_detect start\n" );
#endif
while( (0xFF == memory[0xF]) && (--cycles_left_run > 0) )
{
if( cycles_left_reset )
{
Expand All @@ -27,8 +55,10 @@ cputype_t cpu_detect()
}

// done: wait for things to settle and set clock to high
sleep_us(1);
sleep_us( 10 );
gpio_set_mask( bus_config.mask_clock );
// another delay before reading the bus, without it worked _most_ of the times
sleep_us( 1 );

// bus should be still valid from clock low
state = gpio_get_all();
Expand Down Expand Up @@ -60,12 +90,20 @@ cputype_t cpu_detect()
}

// done: wait for things to settle and set clock to low
sleep_us(1);
sleep_us( 9 );
#if DEBUG_CPU_DETECT
printf( "%08x\n", gpio_get_all() );
#endif
gpio_clr_mask( bus_config.mask_clock );
}

#if DEBUG_CPU_DETECT
printf( "cpu_detect done\n" );
#endif

cpu_detect_result = memory[0xF];
// run complete, evaluate detected code
switch( memory[0xF] )
switch( cpu_detect_result )
{
case 0x00:
return CPU_6502;
Expand Down
6 changes: 6 additions & 0 deletions src/rp2040/cpu_detect.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Copyright (c) 2023 SvOlli
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef CPUDETECT_H
#define CPUDETECT_H CPUDETECT_H
Expand All @@ -8,6 +13,7 @@ typedef enum {

cputype_t cpu_detect();
const char *cputype_name( cputype_t cputype );
unsigned char cpu_detect_raw();

#endif

54 changes: 54 additions & 0 deletions src/rp2040/fake_eeprom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2023 SvOlli
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <pico/stdlib.h>
#include <hardware/flash.h>

#include "fake_eeprom.h"

static const uint8_t *flash_target_base = (const uint8_t *)XIP_BASE;

uint32_t flash_size_detect()
{
uint32_t size;
/* sizes: 1MB 64MB */
for( size = (1 << 20); size < (1 << 27); size <<= 1 )
{
if( !memcmp( flash_target_base, flash_target_base + size, FLASH_PAGE_SIZE ) )
{
break;
}
}

return size;
}

static uint32_t last_flash_block_start()
{
static uint32_t last_block = 0;
if( !last_block )
{
last_block = flash_size_detect() - FLASH_PAGE_SIZE;
}
return last_block;
}

void settings_write( void* memory, uint32_t size )
{
assert( size <= FLASH_PAGE_SIZE );
flash_range_erase(last_flash_block_start(), FLASH_SECTOR_SIZE);
flash_range_program(last_flash_block_start(), memory, FLASH_PAGE_SIZE);
}

void settings_read( void* memory, uint32_t size )
{
assert( size <= FLASH_PAGE_SIZE );
memcpy( memory, flash_target_base + last_flash_block_start(), size );
}

14 changes: 14 additions & 0 deletions src/rp2040/fake_eeprom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2023 SvOlli
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef FAKE_EEPROM_H
#define FAKE_EEPROM_H FAKE_EEPROM_H

uint32_t flash_size_detect();
void settings_write( void* memory, uint32_t size );
void settings_read( void* memory, uint32_t size );

#endif

0 comments on commit 1c16328

Please sign in to comment.