Skip to content

Add RP2040 support #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4b66403
Add PICO SDK
JohnK1987 Mar 3, 2023
8a35132
Add RP2040 HAL implementation
JohnK1987 Mar 3, 2023
f58c6a3
Add target Raspberry Pi Pico and its Upload method
JohnK1987 Mar 3, 2023
3c88d71
Modified PICO SDK-RTC because of conflict in name
JohnK1987 Mar 3, 2023
722ac7b
Use USB from boot, fix USB linking
multiplemonomials Jul 5, 2023
c20ccb6
Try removing redundant init call
multiplemonomials Jul 6, 2023
ce47470
Add SWD upload configuration, copy most init code from Pico SDK
multiplemonomials Jul 6, 2023
b75dce4
Fix RTC linking, fix ram size constant, fix test warning
multiplemonomials Jul 6, 2023
eb2c166
Add upload support for RPi Pico devices using Picotool
multiplemonomials Jul 9, 2023
916a736
Fix implementation of Tx IRQ for serial ports. BufferedSerial works …
multiplemonomials Jul 9, 2023
a4564a6
Make PinNames.h pass pin validation
multiplemonomials Jul 9, 2023
3658b31
Fix us ticker not working when debugging
multiplemonomials Jul 10, 2023
70f668c
Fix us ticker double-init and manual fire interrupt function, us tick…
multiplemonomials Jul 10, 2023
c27fd9e
Fix writing to rtc and rtc double-init, RTC tests now pass (except rt…
multiplemonomials Jul 10, 2023
48862c2
Fix panic() not working from a critical section or ISR
multiplemonomials Jul 10, 2023
4ffdfe7
Fix compile failure due to extra LED1 definition
multiplemonomials Jul 10, 2023
595b6bb
Fix style
multiplemonomials Jul 10, 2023
789bd95
Fix flash_api detection of invalid parameters, fix reset_reason to ad…
multiplemonomials Jul 10, 2023
42e0780
Fix watchdog test warnings, fix broken hal_watchdog_get_reload_value(…
multiplemonomials Jul 10, 2023
8627995
Fix watchdog_reset failing to compile on some devices
multiplemonomials Jul 10, 2023
575c517
Fix us ticker fire_interrupt() not being callable from an ISR
multiplemonomials Jul 12, 2023
d60ecbd
Fix incorrect license header
multiplemonomials Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions hal/include/hal/serial_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
/** The serial interrupt handler registration
*
* @param obj The serial object
* @param handler The interrupt handler which will be invoked when the interrupt fires
* @param id The SerialBase object
* @param handler The interrupt handler function which will be invoked when the interrupt fires. The handler
* function pointer must be common among all serial instances.
* @param id The SerialBase object. This shall be passed to \c handler when it's
* invoked for this serial instance.
*/
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id);

Expand Down
7 changes: 7 additions & 0 deletions hal/include/hal/us_ticker_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ void us_ticker_irq_handler(void);
* clocking and prescaler registers, along with disabling
* the compare interrupt.
*
* Implementations must tolerate this function being called multiple times, and subsequent calls
* after the first one shall clear any configured interrupt.
*
* @note Initialization properties tested by ticker_init_test
*
* Pseudo Code:
Expand Down Expand Up @@ -227,6 +230,7 @@ void us_ticker_free(void);
* }
* @endcode
*/
// note: parenthesis around the function name make sure this isn't replaced by the us_ticker_read() macro version.
uint32_t (us_ticker_read)(void);

/** Set interrupt for specified timestamp
Expand Down Expand Up @@ -282,6 +286,9 @@ void us_ticker_clear_interrupt(void);
*
* The ticker should be initialized prior calling this function.
*
* Note: This function might be called from the ticker ISR, in which case it should
* schedule the ticker ISR to be executed again as soon as it returns.
*
* Pseudo Code:
* @code
* void us_ticker_fire_interrupt(void)
Expand Down
12 changes: 11 additions & 1 deletion hal/tests/TESTS/mbed_hal/rtc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "rtc_api.h"
#include <type_traits>
#include <mstd_atomic>
#include <cinttypes>

using namespace utest::v1;
using namespace std::chrono;
Expand Down Expand Up @@ -135,6 +136,7 @@ void rtc_persist_test()
const bool enabled = RealTimeClock::isenabled();
RealTimeClock::free();

printf("start = %" PRIi64 ", stop = %" PRIi64 "\n", start.time_since_epoch().count(), stop.time_since_epoch().count());
TEST_ASSERT_TRUE(enabled);
TEST_ASSERT_DURATION_WITHIN(WAIT_TOLERANCE, WAIT_TIME, stop - start);
}
Expand Down Expand Up @@ -199,16 +201,24 @@ void rtc_accuracy_test()
void rtc_write_read_test()
{
RealTimeClock::init();
RealTimeClock::write(RealTimeClock::time_point(1s));

/* NB: IAR compilation issue with "auto init_val = RealTimeClock::time_point(100s)" */
for (auto init_val = RealTimeClock::time_point(seconds(100)); init_val < RealTimeClock::time_point(400s); init_val += 100s) {

core_util_critical_section_enter();

// To prevent the RTC from ticking during the read-write operation, busy wait until it ticks.
// That gives us a second in which to execute the test.
auto initialVal = RealTimeClock::now();
while (RealTimeClock::now() == initialVal) {}

RealTimeClock::write(init_val);
const auto read_val = RealTimeClock::now();

core_util_critical_section_exit();

printf("Wrote: %" PRIi64 ", Read: %" PRIi64 "\n", init_val.time_since_epoch().count(), read_val.time_since_epoch().count());

/* No tolerance is provided since we should have 1 second to
* execute this case after the RTC time is set.
*/
Expand Down
4 changes: 2 additions & 2 deletions hal/tests/TESTS/mbed_hal/rtc_time/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void test_mk_time_boundary()
pTestCases = test_mk_time_arr_partial;
}

for (int i = 0; i < (sizeof(test_mk_time_arr_full) / (sizeof(test_mk_time_struct))); i++) {
for (size_t i = 0; i < (sizeof(test_mk_time_arr_full) / (sizeof(test_mk_time_struct))); i++) {
time_t seconds;
bool result = _rtc_maketime(&pTestCases[i].timeinfo, &seconds, rtc_leap_year_support);

Expand Down Expand Up @@ -187,7 +187,7 @@ void test_set_time_twice()
TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME));

/* Wait 2 seconds */
ThisThread::sleep_for(2000);
ThisThread::sleep_for(2s);

/* set the time to NEW_TIME again and check it */
set_time(NEW_TIME);
Expand Down
33 changes: 17 additions & 16 deletions hal/tests/TESTS/mbed_hal/watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#include <stdlib.h>

/* The shortest timeout value, this test suite is able to handle correctly. */
#define WDG_MIN_TIMEOUT_MS 50UL
#define WDG_MIN_TIMEOUT_MS 50ms

// Do not set watchdog timeout shorter than WDG_MIN_TIMEOUT_MS, as it may
// cause the host-test-runner return 'TIMEOUT' instead of 'FAIL' / 'PASS'
// if watchdog performs reset during test suite teardown.
#define WDG_TIMEOUT_MS 100UL
#define WDG_TIMEOUT_MS 100ms

#define MSG_VALUE_DUMMY "0"
#define MSG_VALUE_LEN 24
Expand All @@ -57,7 +57,7 @@
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
* To be on the safe side, set the wait time to 150 ms.
*/
#define SERIAL_FLUSH_TIME_MS 150
#define SERIAL_FLUSH_TIME_MS 150ms

int CASE_INDEX_START;
int CASE_INDEX_CURRENT;
Expand All @@ -67,7 +67,7 @@ using utest::v1::Case;
using utest::v1::Specification;
using utest::v1::Harness;

const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS };
const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS.count() };

void test_max_timeout_is_valid()
{
Expand Down Expand Up @@ -115,12 +115,12 @@ void test_update_config()
}

watchdog_config_t config = WDG_CONFIG_DEFAULT;
uint32_t timeouts[] = {
features.max_timeout / 4,
features.max_timeout / 8,
features.max_timeout / 16
std::chrono::milliseconds timeouts[] = {
std::chrono::milliseconds(features.max_timeout / 4),
std::chrono::milliseconds(features.max_timeout / 8),
std::chrono::milliseconds(features.max_timeout / 16)
};
int num_timeouts = sizeof timeouts / sizeof timeouts[0];
size_t num_timeouts = sizeof timeouts / sizeof timeouts[0];

for (size_t i = 0; i < num_timeouts; i++) {
if (timeouts[i] < WDG_MIN_TIMEOUT_MS) {
Expand All @@ -129,9 +129,10 @@ void test_update_config()
return;
}

config.timeout_ms = timeouts[i];
config.timeout_ms = timeouts[i].count();
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
uint32_t reload_value = hal_watchdog_get_reload_value();

auto reload_value = std::chrono::milliseconds(hal_watchdog_get_reload_value());
// The watchdog should trigger at, or after the timeout value.
TEST_ASSERT(reload_value >= timeouts[i]);
// The watchdog should trigger before twice the timeout value.
Expand All @@ -155,7 +156,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const
// Start kicking the watchdog during teardown.
hal_watchdog_kick();
Ticker wdg_kicking_ticker;
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000);
wdg_kicking_ticker.attach(mbed::callback(hal_watchdog_kick), 20ms);
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
if (failed) {
/* Return immediately and skip the device reset, if the test case failed.
Expand Down Expand Up @@ -193,7 +194,7 @@ utest::v1::status_t case_teardown_wdg_stop_or_reset(const Case *const source, co
template<uint32_t timeout_ms>
void test_init()
{
if (timeout_ms < WDG_MIN_TIMEOUT_MS) {
if (std::chrono::milliseconds(timeout_ms) < WDG_MIN_TIMEOUT_MS) {
CASE_IGNORED = true;
TEST_IGNORE_MESSAGE("Requested timeout value is too short -- ignoring test case.");
return;
Expand All @@ -216,7 +217,7 @@ void test_init_max_timeout()
TEST_ASSERT(hal_watchdog_get_reload_value() >= features.max_timeout);
}

int testsuite_setup_sync_on_reset(const size_t number_of_cases)
utest::v1::status_t testsuite_setup_sync_on_reset(const size_t number_of_cases)
{
GREENTEA_SETUP(45, "sync_on_reset");
utest::v1::status_t status = utest::v1::greentea_test_setup_handler(number_of_cases);
Expand All @@ -243,7 +244,7 @@ int testsuite_setup_sync_on_reset(const size_t number_of_cases)
}

utest_printf("Starting with test case index %i of all %i defined test cases.\n", CASE_INDEX_START, number_of_cases);
return CASE_INDEX_START;
return static_cast<utest::v1::status_t>(CASE_INDEX_START);
}

Case cases[] = {
Expand All @@ -262,7 +263,7 @@ Case cases[] = {
test_init_max_timeout, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
};

Specification specification((utest::v1::test_setup_handler_t) testsuite_setup_sync_on_reset, cases);
Specification specification(testsuite_setup_sync_on_reset, cases);

int main()
{
Expand Down
Loading