1
1
#![ no_std]
2
2
#![ no_main]
3
3
4
- use cortex_m_rt:: { entry, pre_init } ;
4
+ use cortex_m_rt:: entry;
5
5
use panic_halt as _;
6
6
7
7
#[ link_section = ".boot_loader" ]
8
- #[ no_mangle]
9
- pub static BOOT_LOADER : [ u8 ; 512 ] = * include_bytes ! ( "boot2_and_reset.bin" ) ;
10
-
11
- #[ pre_init]
12
- unsafe fn pre_init ( ) {
13
- let sio = & * rp2040_pac:: SIO :: ptr ( ) ;
14
-
15
- // If we are core 1, then stop dead and let core 0 do all the work.
16
- if sio. cpuid . read ( ) . bits ( ) != 0u32 {
17
- loop {
18
- cortex_m:: asm:: nop ( ) ;
19
- }
20
- }
21
- }
8
+ #[ used]
9
+ pub static BOOT_LOADER : [ u8 ; 256 ] = rp2040_boot2:: BOOT_LOADER ;
22
10
11
+ /// Handle peripheral resets so the chip is usable.
23
12
unsafe fn setup_chip ( p : & mut rp2040_pac:: Peripherals ) {
24
13
// Now reset all the peripherals, except QSPI and XIP (we're using those
25
14
// to execute from external flash!)
26
-
27
15
p. RESETS . reset . write ( |w| {
28
16
w. adc ( ) . set_bit ( ) ;
29
17
w. busctrl ( ) . set_bit ( ) ;
@@ -53,16 +41,6 @@ unsafe fn setup_chip(p: &mut rp2040_pac::Peripherals) {
53
41
w
54
42
} ) ;
55
43
56
- // unreset_block_wait(RESETS_RESET_BITS /* 01ff_ffff */ & ~(
57
- // RESETS_RESET_ADC_BITS |
58
- // RESETS_RESET_RTC_BITS |
59
- // RESETS_RESET_SPI0_BITS |
60
- // RESETS_RESET_SPI1_BITS |
61
- // RESETS_RESET_UART0_BITS |
62
- // RESETS_RESET_UART1_BITS |
63
- // RESETS_RESET_USBCTRL_BITS
64
- // ));
65
-
66
44
const RESETS_RESET_BITS : u32 = 0x01ffffff ;
67
45
const RESETS_RESET_USBCTRL_BITS : u32 = 0x01000000 ;
68
46
const RESETS_RESET_UART1_BITS : u32 = 0x00800000 ;
@@ -72,6 +50,17 @@ unsafe fn setup_chip(p: &mut rp2040_pac::Peripherals) {
72
50
const RESETS_RESET_RTC_BITS : u32 = 0x00008000 ;
73
51
const RESETS_RESET_ADC_BITS : u32 = 0x00000001 ;
74
52
53
+ // We want to take everything out of reset, except these peripherals:
54
+ //
55
+ // * ADC
56
+ // * RTC
57
+ // * SPI0
58
+ // * SPI1
59
+ // * UART0
60
+ // * UART1
61
+ // * USBCTRL
62
+ //
63
+ // These must stay in reset until the clocks are sorted out.
75
64
const PERIPHERALS_TO_UNRESET : u32 = RESETS_RESET_BITS
76
65
& !( RESETS_RESET_ADC_BITS
77
66
| RESETS_RESET_RTC_BITS
@@ -81,8 +70,8 @@ unsafe fn setup_chip(p: &mut rp2040_pac::Peripherals) {
81
70
| RESETS_RESET_UART1_BITS
82
71
| RESETS_RESET_USBCTRL_BITS ) ;
83
72
73
+ // Write 0 to the reset field to take it out of reset
84
74
p. RESETS . reset . modify ( |_r, w| {
85
- // w.adc().clear_bit();
86
75
w. busctrl ( ) . clear_bit ( ) ;
87
76
w. dma ( ) . clear_bit ( ) ;
88
77
w. i2c0 ( ) . clear_bit ( ) ;
@@ -97,16 +86,10 @@ unsafe fn setup_chip(p: &mut rp2040_pac::Peripherals) {
97
86
w. pll_sys ( ) . clear_bit ( ) ;
98
87
w. pll_usb ( ) . clear_bit ( ) ;
99
88
w. pwm ( ) . clear_bit ( ) ;
100
- // w.rtc().clear_bit();
101
- // w.spi0().clear_bit();
102
- // w.spi1().clear_bit();
103
89
w. syscfg ( ) . clear_bit ( ) ;
104
90
w. sysinfo ( ) . clear_bit ( ) ;
105
91
w. tbman ( ) . clear_bit ( ) ;
106
92
w. timer ( ) . clear_bit ( ) ;
107
- // w.uart0().clear_bit();
108
- // w.uart1().clear_bit();
109
- // w.usbctrl().clear_bit();
110
93
w
111
94
} ) ;
112
95
@@ -156,7 +139,7 @@ fn main() -> ! {
156
139
} ) ;
157
140
158
141
loop {
159
- for _i in 0 ..1000000 {
142
+ for _i in 0 ..500000 {
160
143
cortex_m:: asm:: nop ( ) ;
161
144
}
162
145
@@ -166,7 +149,7 @@ fn main() -> ! {
166
149
w
167
150
} ) ;
168
151
169
- for _i in 0 ..1000000 {
152
+ for _i in 0 ..500000 {
170
153
cortex_m:: asm:: nop ( ) ;
171
154
}
172
155
0 commit comments