Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 52 additions & 49 deletions prawnblaster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
set(overclocks 0;1)

foreach (overclock IN LISTS overclocks)
# Compute firmware name
set(firmware_name prawnblaster)
if(PICO_PLATFORM MATCHES "^rp2350")
set(firmware_name "${firmware_name}_rp2350")
else()
set(firmware_name "${firmware_name}_${PICO_PLATFORM}")
endif()
if(overclock)
set(firmware_name "${firmware_name}_overclock")
endif()

add_executable(${firmware_name} prawnblaster.cpp fast_serial.c)

pico_generate_pio_header(${firmware_name} ${CMAKE_CURRENT_LIST_DIR}/pseudoclock.pio)

# Pass in number of instructions to firmware as a compiler definition
set(num_instructions 30000)
if(PICO_PLATFORM MATCHES "^rp2350")
set(num_instructions 60000)
endif()
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_NUM_INSTRUCTIONS=${num_instructions}")

# Pass in board type to firmware as a compiler definition. Note that PICO_BOARD is passed in by the SDK, but it's passed in a string which isn't valid and so I can't use it...
# This is also, to some extent, a duplicate of the above PRAWNBLASTER_NUM_INSTRUCTIONS but I think it makes sense to keep these seperate.
if (PICO_BOARD STREQUAL "pico")
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=1")
elseif (PICO_BOARD STREQUAL "pico2")
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=2")
else ()
message(FATAL_ERROR "Unsupported PICO_BOARD")
endif()


# Pass in overclock state to firmware as a compiler definition
if(overclock)
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_OVERCLOCK=1")
endif()

# Pull in our pico_stdlib which aggregates commonly used features
target_link_libraries(${firmware_name} pico_stdlib hardware_pio pico_multicore pico_unique_id hardware_clocks hardware_dma hardware_vreg tinyusb_device tinyusb_board)
target_include_directories(${firmware_name} PRIVATE .)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${firmware_name})

endforeach()
# Compute firmware name
set(firmware_name prawnblaster)
if(PICO_PLATFORM MATCHES "^rp2350")
set(firmware_name "${firmware_name}_rp2350")
else()
set(firmware_name "${firmware_name}_${PICO_PLATFORM}")
endif()
# if(overclock)
# set(firmware_name "${firmware_name}_overclock")
# endif()

add_executable(${firmware_name} prawnblaster.cpp fast_serial.c)

pico_generate_pio_header(${firmware_name} ${CMAKE_CURRENT_LIST_DIR}/pseudoclock.pio)

# Pass in number of instructions to firmware as a compiler definition
set(num_instructions 30000)

# Pass in freq limits to firmware in MHz
set(normal_freq_limit 133)
set(overclock_freq_limit 200)

if(PICO_PLATFORM MATCHES "^rp2350")
set(num_instructions 60000)
set(normal_freq_limit 150)
endif()
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_NUM_INSTRUCTIONS=${num_instructions}")
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_NORMAL_FREQ_LIMIT=${normal_freq_limit}")
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_OVERCLOCK_FREQ_LIMIT=${overclock_freq_limit}")

# Pass in board type to firmware as a compiler definition. Note that PICO_BOARD is passed in by the SDK, but it's passed in a string which isn't valid and so I can't use it...
# This is also, to some extent, a duplicate of the above PRAWNBLASTER_NUM_INSTRUCTIONS but I think it makes sense to keep these seperate.
if (PICO_BOARD STREQUAL "pico")
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=1")
elseif (PICO_BOARD STREQUAL "pico2")
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=2")
else ()
message(FATAL_ERROR "Unsupported PICO_BOARD")
endif()


# Pass in overclock state to firmware as a compiler definition
if(overclock)
target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_OVERCLOCK=1")
endif()

# Pull in our pico_stdlib which aggregates commonly used features
target_link_libraries(${firmware_name} pico_stdlib hardware_pio pico_multicore pico_unique_id hardware_clocks hardware_dma hardware_vreg tinyusb_device tinyusb_board)
target_include_directories(${firmware_name} PRIVATE .)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${firmware_name})
35 changes: 14 additions & 21 deletions prawnblaster/prawnblaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const char VERSION[16] = "1.2.0-overclock";

int DEBUG;

// Freq limits in MHz
constexpr unsigned int normal_freq_limit = PRAWNBLASTER_NORMAL_FREQ_LIMIT;
constexpr unsigned int overclock_freq_limit = PRAWNBLASTER_OVERCLOCK_FREQ_LIMIT;

// Can't seem to have this be used to define array size even though it's a constant
constexpr unsigned int max_instructions = PRAWNBLASTER_NUM_INSTRUCTIONS;
constexpr unsigned int instruction_array_size = 2 * max_instructions + 8;
Expand Down Expand Up @@ -1038,13 +1042,17 @@ void loop()
}
else
{
if (freq >= 150 * MHZ)
if (freq > overclock_freq_limit * MHZ)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a small concern about this logic tree. If we go from an overclock state to a normal state, the Vreg will be set down before the frequency change, potentially leading to instability.

We should test that hypothesis thoroughly to see if it is a problem before actually changing code though.

{
vreg_set_voltage(VREG_VOLTAGE_1_30);
}
if (freq < 150 * MHZ)
{
vreg_set_voltage(VREG_VOLTAGE_1_10);
fast_serial_printf("WARNING: Requested freq > normal bounds, setting voltage = 1.3 V\n");
vreg_set_voltage(VREG_VOLTAGE_1_30);
}
else if (freq > normal_freq_limit * MHZ && freq <= overclock_freq_limit * MHZ)
{
vreg_set_voltage(VREG_VOLTAGE_1_20);
}
else {
vreg_set_voltage(VREG_VOLTAGE_1_10);
}
if (DEBUG)
{
Expand All @@ -1057,21 +1065,6 @@ void loop()
else
{

#ifndef PRAWNBLASTER_OVERCLOCK
# if PRAWNBLASTER_PICO_BOARD == 1
if (freq > 200 * MHZ)
# elif PRAWNBLASTER_PICO_BOARD == 2
if (freq > 150 * MHZ)
# else
# error "Unsupported PICO_BOARD"
# endif // PICO_BOARD
// Do validation checking on values provided
{
fast_serial_printf("Invalid clock frequency specified\r\n");
return;
}
#endif //PRAWNBLASTER_OVERCLOCK

// Set new clock frequency
if (src == 0)
{
Expand Down