Skip to content

Commit a9f8e09

Browse files
Jamie SmithJohnK1987
Jamie Smith
andauthored
Add RP2040 support (ARMmbed#168)
* Add PICO SDK * Add RP2040 HAL implementation * Add target Raspberry Pi Pico and its Upload method * Modified PICO SDK-RTC because of conflict in name * Use USB from boot, fix USB linking * Try removing redundant init call * Add SWD upload configuration, copy most init code from Pico SDK * Fix RTC linking, fix ram size constant, fix test warning * Add upload support for RPi Pico devices using Picotool * Fix implementation of Tx IRQ for serial ports. BufferedSerial works now! * Make PinNames.h pass pin validation * Fix us ticker not working when debugging * Fix us ticker double-init and manual fire interrupt function, us ticker tests now pass! * Fix writing to rtc and rtc double-init, RTC tests now pass (except rtc-reset) * Fix panic() not working from a critical section or ISR * Fix compile failure due to extra LED1 definition * Fix style * Fix flash_api detection of invalid parameters, fix reset_reason to advertise the correct capabilities and implement them correctly * Fix watchdog test warnings, fix broken hal_watchdog_get_reload_value(), fix missing frequency field in watchdog features * Fix watchdog_reset failing to compile on some devices * Fix us ticker fire_interrupt() not being callable from an ISR * Fix incorrect license header --------- Co-authored-by: Johnk1987 <odiin@seznam.cz>
1 parent 785e3fb commit a9f8e09

File tree

380 files changed

+123131
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

380 files changed

+123131
-61
lines changed

hal/include/hal/serial_api.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
255255
/** The serial interrupt handler registration
256256
*
257257
* @param obj The serial object
258-
* @param handler The interrupt handler which will be invoked when the interrupt fires
259-
* @param id The SerialBase object
258+
* @param handler The interrupt handler function which will be invoked when the interrupt fires. The handler
259+
* function pointer must be common among all serial instances.
260+
* @param id The SerialBase object. This shall be passed to \c handler when it's
261+
* invoked for this serial instance.
260262
*/
261263
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id);
262264

hal/include/hal/us_ticker_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ void us_ticker_irq_handler(void);
155155
* clocking and prescaler registers, along with disabling
156156
* the compare interrupt.
157157
*
158+
* Implementations must tolerate this function being called multiple times, and subsequent calls
159+
* after the first one shall clear any configured interrupt.
160+
*
158161
* @note Initialization properties tested by ticker_init_test
159162
*
160163
* Pseudo Code:
@@ -227,6 +230,7 @@ void us_ticker_free(void);
227230
* }
228231
* @endcode
229232
*/
233+
// note: parenthesis around the function name make sure this isn't replaced by the us_ticker_read() macro version.
230234
uint32_t (us_ticker_read)(void);
231235

232236
/** Set interrupt for specified timestamp
@@ -282,6 +286,9 @@ void us_ticker_clear_interrupt(void);
282286
*
283287
* The ticker should be initialized prior calling this function.
284288
*
289+
* Note: This function might be called from the ticker ISR, in which case it should
290+
* schedule the ticker ISR to be executed again as soon as it returns.
291+
*
285292
* Pseudo Code:
286293
* @code
287294
* void us_ticker_fire_interrupt(void)

hal/tests/TESTS/mbed_hal/rtc/main.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "rtc_api.h"
3030
#include <type_traits>
3131
#include <mstd_atomic>
32+
#include <cinttypes>
3233

3334
using namespace utest::v1;
3435
using namespace std::chrono;
@@ -135,6 +136,7 @@ void rtc_persist_test()
135136
const bool enabled = RealTimeClock::isenabled();
136137
RealTimeClock::free();
137138

139+
printf("start = %" PRIi64 ", stop = %" PRIi64 "\n", start.time_since_epoch().count(), stop.time_since_epoch().count());
138140
TEST_ASSERT_TRUE(enabled);
139141
TEST_ASSERT_DURATION_WITHIN(WAIT_TOLERANCE, WAIT_TIME, stop - start);
140142
}
@@ -199,16 +201,24 @@ void rtc_accuracy_test()
199201
void rtc_write_read_test()
200202
{
201203
RealTimeClock::init();
204+
RealTimeClock::write(RealTimeClock::time_point(1s));
202205

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

211+
// To prevent the RTC from ticking during the read-write operation, busy wait until it ticks.
212+
// That gives us a second in which to execute the test.
213+
auto initialVal = RealTimeClock::now();
214+
while (RealTimeClock::now() == initialVal) {}
215+
207216
RealTimeClock::write(init_val);
208217
const auto read_val = RealTimeClock::now();
209-
210218
core_util_critical_section_exit();
211219

220+
printf("Wrote: %" PRIi64 ", Read: %" PRIi64 "\n", init_val.time_since_epoch().count(), read_val.time_since_epoch().count());
221+
212222
/* No tolerance is provided since we should have 1 second to
213223
* execute this case after the RTC time is set.
214224
*/

hal/tests/TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void test_mk_time_boundary()
128128
pTestCases = test_mk_time_arr_partial;
129129
}
130130

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

@@ -187,7 +187,7 @@ void test_set_time_twice()
187187
TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME));
188188

189189
/* Wait 2 seconds */
190-
ThisThread::sleep_for(2000);
190+
ThisThread::sleep_for(2s);
191191

192192
/* set the time to NEW_TIME again and check it */
193193
set_time(NEW_TIME);

hal/tests/TESTS/mbed_hal/watchdog/main.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
#include <stdlib.h>
3030

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

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

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

6262
int CASE_INDEX_START;
6363
int CASE_INDEX_CURRENT;
@@ -67,7 +67,7 @@ using utest::v1::Case;
6767
using utest::v1::Specification;
6868
using utest::v1::Harness;
6969

70-
const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS };
70+
const watchdog_config_t WDG_CONFIG_DEFAULT = { .timeout_ms = WDG_TIMEOUT_MS.count() };
7171

7272
void test_max_timeout_is_valid()
7373
{
@@ -115,12 +115,12 @@ void test_update_config()
115115
}
116116

117117
watchdog_config_t config = WDG_CONFIG_DEFAULT;
118-
uint32_t timeouts[] = {
119-
features.max_timeout / 4,
120-
features.max_timeout / 8,
121-
features.max_timeout / 16
118+
std::chrono::milliseconds timeouts[] = {
119+
std::chrono::milliseconds(features.max_timeout / 4),
120+
std::chrono::milliseconds(features.max_timeout / 8),
121+
std::chrono::milliseconds(features.max_timeout / 16)
122122
};
123-
int num_timeouts = sizeof timeouts / sizeof timeouts[0];
123+
size_t num_timeouts = sizeof timeouts / sizeof timeouts[0];
124124

125125
for (size_t i = 0; i < num_timeouts; i++) {
126126
if (timeouts[i] < WDG_MIN_TIMEOUT_MS) {
@@ -129,9 +129,10 @@ void test_update_config()
129129
return;
130130
}
131131

132-
config.timeout_ms = timeouts[i];
132+
config.timeout_ms = timeouts[i].count();
133133
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
134-
uint32_t reload_value = hal_watchdog_get_reload_value();
134+
135+
auto reload_value = std::chrono::milliseconds(hal_watchdog_get_reload_value());
135136
// The watchdog should trigger at, or after the timeout value.
136137
TEST_ASSERT(reload_value >= timeouts[i]);
137138
// The watchdog should trigger before twice the timeout value.
@@ -155,7 +156,7 @@ utest::v1::status_t case_teardown_sync_on_reset(const Case *const source, const
155156
// Start kicking the watchdog during teardown.
156157
hal_watchdog_kick();
157158
Ticker wdg_kicking_ticker;
158-
wdg_kicking_ticker.attach_us(mbed::callback(hal_watchdog_kick), 20000);
159+
wdg_kicking_ticker.attach(mbed::callback(hal_watchdog_kick), 20ms);
159160
utest::v1::status_t status = utest::v1::greentea_case_teardown_handler(source, passed, failed, failure);
160161
if (failed) {
161162
/* Return immediately and skip the device reset, if the test case failed.
@@ -193,7 +194,7 @@ utest::v1::status_t case_teardown_wdg_stop_or_reset(const Case *const source, co
193194
template<uint32_t timeout_ms>
194195
void test_init()
195196
{
196-
if (timeout_ms < WDG_MIN_TIMEOUT_MS) {
197+
if (std::chrono::milliseconds(timeout_ms) < WDG_MIN_TIMEOUT_MS) {
197198
CASE_IGNORED = true;
198199
TEST_IGNORE_MESSAGE("Requested timeout value is too short -- ignoring test case.");
199200
return;
@@ -216,7 +217,7 @@ void test_init_max_timeout()
216217
TEST_ASSERT(hal_watchdog_get_reload_value() >= features.max_timeout);
217218
}
218219

219-
int testsuite_setup_sync_on_reset(const size_t number_of_cases)
220+
utest::v1::status_t testsuite_setup_sync_on_reset(const size_t number_of_cases)
220221
{
221222
GREENTEA_SETUP(45, "sync_on_reset");
222223
utest::v1::status_t status = utest::v1::greentea_test_setup_handler(number_of_cases);
@@ -243,7 +244,7 @@ int testsuite_setup_sync_on_reset(const size_t number_of_cases)
243244
}
244245

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

249250
Case cases[] = {
@@ -262,7 +263,7 @@ Case cases[] = {
262263
test_init_max_timeout, (utest::v1::case_teardown_handler_t) case_teardown_sync_on_reset),
263264
};
264265

265-
Specification specification((utest::v1::test_setup_handler_t) testsuite_setup_sync_on_reset, cases);
266+
Specification specification(testsuite_setup_sync_on_reset, cases);
266267

267268
int main()
268269
{

0 commit comments

Comments
 (0)