1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #define PW_LOG_MODULE_NAME "pw_system"
16
17 #include "FreeRTOS.h"
18 #include "hardware/exception.h"
19 #include "pico/stdlib.h"
20 #include "pw_cpu_exception/entry.h"
21 #include "pw_log/log.h"
22 #include "pw_preprocessor/arch.h"
23 #include "pw_system/init.h"
24 #include "task.h"
25
26 #if !_PW_ARCH_ARM_V6M
27 #include "RP2350.h"
28 #endif // !_PW_ARCH_ARM_V6M
29
main()30 int main() {
31 // PICO_SDK Inits
32 stdio_init_all();
33 setup_default_uart();
34 // stdio_usb_init();
35
36 // Install the CPU exception handler.
37 exception_set_exclusive_handler(HARDFAULT_EXCEPTION, pw_cpu_exception_Entry);
38 // On RP2040 (arm6m), only HardFault is supported
39 #if !_PW_ARCH_ARM_V6M
40 // TODO: b/373723963 - The pico sdk exception_number enum doesn't currently
41 // have values for MemManage, BusFault or UsageFault, so cast the values for
42 // now until pico sdk has been updated. Enable the MemManage handler
43 SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
44 exception_set_exclusive_handler(static_cast<exception_number>(4),
45 pw_cpu_exception_Entry);
46 // Enable the BusFault handler
47 SCB->SHCSR |= SCB_SHCSR_BUSFAULTENA_Msk;
48 exception_set_exclusive_handler(static_cast<exception_number>(5),
49 pw_cpu_exception_Entry);
50 // Enable the UsageFault handler
51 SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk;
52 exception_set_exclusive_handler(static_cast<exception_number>(6),
53 pw_cpu_exception_Entry);
54 #endif // !_PW_ARCH_ARM_V6M
55
56 PW_LOG_INFO("pw_system main");
57
58 pw::system::Init();
59 vTaskStartScheduler();
60 PW_UNREACHABLE;
61 }
62