-
Notifications
You must be signed in to change notification settings - Fork 80
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
rp2040: Added rp2040 support. #45
Conversation
src/generic/armcm_reset.c
Outdated
@@ -9,10 +9,16 @@ | |||
#include "board/irq.h" // irq_disable | |||
#include "board/misc.h" // try_request_canboot | |||
|
|||
#if CONFIG_MACH_RP2040 | |||
#define BOOTLOADER_START (CONFIG_RP2040_BOOTLOADER_START) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User bootloader should be placed just after boot2 block at START_FLASH+256 address. Simple CONFIG_FLASH_START & 0xFF000000 do not work here.
****************************************************************/ | ||
|
||
void | ||
timer_setup(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timer from generic/timer.c do not work on cortex-m0+
_bss_end = .; | ||
} > ram | ||
|
||
_stack_start = CONFIG_RAM_START + CONFIG_RAM_SIZE - CONFIG_STACK_SIZE - 1024; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magical "-1024" is really magical. _stack_start is used to place request key what should be preserved after reset. But rp2040 bootrom uses and of the ram to copy boot2(256 bytes) from flash and boot2 uses some stack on top of what. so ~300 bytes around CONFIG_RAM_START + CONFIG_RAM_SIZE are damaged by the boot process of the rp2040. That is why we shift stack by 1024 bytes.
default 0x10000000 | ||
|
||
config APPLICATION_START | ||
default 0x10004000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
16kb is reserved for the bootloader. The current bootloader size is 5kb for usb, 7 kb for can.
Looks like a good addition to CanBoot. Can you break this up into separate commits? Preferably, there would be separate a commits for:
I can be confident that Klipper's source is solid, so I just need to review the changes. This is much easier when I can review the diffs in each commit. Thanks. |
Thank you. You suggestions make sense. I will split pr into multiple commits. |
Signed-off-by: Alex Malishev <malishev@gmail.com>
(https://github.com/raspberrypi/pico-sdk/tree/master/src/rp2_common/hardware_flash, https://github.com/raspberrypi/pico-sdk/tree/master/src/rp2_common/pico_bootrom) as is. Signed-off-by: Alex Malishev <malishev@gmail.com>
Signed-off-by: Alex Malishev <malishev@gmail.com>
Implemented canboot timer interface. Simplified chipid.c to use common flash interface. Signed-off-by: Alex Malishev <malishev@gmail.com>
Modified linker script and loader to load whole bootloader to the RAM. Removed whatchdog. Fixed gpio.c compilation. Signed-off-by: Alex Malishev <malishev@gmail.com>
Signed-off-by: Alex Malishev <malishev@gmail.com>
I did cleanup of the pr as suggested. Please note what rp2040 flash do not support concurrent read end erase/program. So interrupt handlers are suspended during erase operation. It is not good for the software can driver we use. So I have changed linker script and startup file armcm_canboot.c to load whole bootloader to the RAM. This way we do NOT disable interrupts during flash erase and write. |
} > rom | ||
|
||
. = ALIGN(4); | ||
_data_flash = .; | ||
|
||
.data : AT (_data_flash) | ||
{ | ||
. = ALIGN(4); | ||
. = ALIGN(128); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually ALIGN do not do anything, cause we are at the start of the ram anyway :)
Leaved it for the documentation purpose, cause vector_table should be 128 byte aligned.
_text_vectortable_end = .; | ||
*(.text .text.*) | ||
*(.rodata .rodata*) | ||
KEEP(*(.vector_table_flash)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only VectorTableFlash , ResetHandler and reset_handler_stage_two are executed from flash. reset_handler_stage_two moves everything to the ram.
_data_start = .; | ||
KEEP(*(.vector_table)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We copy vector_table to the RAM and update VTOR, so core could use it.
uint32_t count = (&_data_end - &_data_start); | ||
for(int i = 0; i < count; i++) { | ||
(&_data_start)[i] = (&_data_flash)[i]; | ||
barrier(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point it is not safe to call anything, cause we did not copied code yet. So barrier() here to prevent compiler from use memcpy and memset.
Signed-off-by: Alex Malishev <malishev@gmail.com>
Added global CONFIG_BOOTLOADER_START to avoid idefs in the code. This is the same change as in klipper PR. |
I tried this and I get the following error during make flash:
I do however have the rpi connected:
|
OK, resolved... I just have to flash via root/sudo. SORRY! |
@jtrmal Thanks for testing it. Do it work well after all? What board do you use? |
yeah, it looks like its working. I do have some issues that do not most probably correlate with the canboot but I tried to resolved them by using canboot (unsuccessfully). My board behaves ok after soft restart (i.e. staying on power but being restarted after flashing), but when I unplug and plug again, it is dead. I tried both CAN and USB and it still behaves the same. But I'm sure it's not can boot, was happening even before it. This is all just to explain why I'm not able to confirm with 100% certainty |
Things that were confusing for me:
|
Well, most low level parameters should be ok by default.
|
I will try to play with the flash-nuke
thanks!
…On Fri, Oct 28, 2022 at 3:30 PM Alex ***@***.***> wrote:
Well, most low level parameters should ok by default.
Recommended install procedure is following:
1. Boot into buildin bootloader mode - apply power with mode button
pressed
2. Flash binary flash_nuke.uf2 (
https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython)
via mass storage method or via rp2040_flash
3. Wait a minute or two. Dyring this flash_nuke fb2 will erase all
flash
4. Boot into buildin bootloader mode again
5. Build canboot.uf2 and flash canboot.uf2 by the same method
6. Check usb or can bus - canboot should be up running and connected
7. Now it is possible to flash klipper.bin from my klipper pr.
Bootloader option should be enabled in klipper menuconfig.
This should work given hardware is ok.
—
Reply to this email directly, view it on GitHub
<#45 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUKYX2VZOCT52ELX5UWRD3WFQSVNANCNFSM6AAAAAARKRKOPU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Signed-off-by: Alex Malishev <malishev@gmail.com>
I have added option (enabled by default after |
Hi, I just went through the hoops and updated klipper and the canboot to @sh83's repo. Everything seems to work flawlessly. Update via CAN even without triggering the canboot via button also works. Didn't find smallest issue. |
@jtrmal thank you for your feedback and testing. Really good news. |
Thanks. I have begun my review and overall it looks solid. I do have a few observations:
// Check if flash has already been written
void *fstart = (void*)CONFIG_FLASH_START;
uint32_t cbsize = deployer_canboot_binary_size;
if (memcmp(fstart, deployer_canboot_binary, cbsize) == 0) {
try_request_canboot();
halt();
}
I'm going to try to test this on real hardware today to see how the deployer works. Hopefully it something we can get working but it isn't a huge issue if we can't, we just need to disable it and document it. |
Deployer work fine in my setup as is . No fixup is required afaik. |
- moved external files to lib folder - fixed typos - added optional "sudo" to flash command - fixed redundant file close in script - fixed compilation warning
Added misc fixes:
|
@Arksine, thanks for review. Answers to your notes:
|
Thanks for the explanation, makes sense. Everything looks good and tests well on my end, so I merged. |
hey guys, i have a question. |
once canboot is flashed, you need to flash klipper from sh83s klipper fork, at least until his pull request is merged. |
Hi guys, Thank you for your work for integrating RP2040 to canboot. I'm also trying to install the SB2040 with the Octopus board. But I'm not able to complete :
Then I got the klipper error mcu "'SB2040': Unable to connect" and when I restart the printer, the SB2040's blue light for "flash successfull" turn off. The wiring seems fine as I flashed Klipper throught CanBoot CAN command. I think that I missed something in the canboot's menuconfig. Please, can anyone explain me simply which option did I missed ? Thank you |
@Flob74 The klipper pull request is not merged yet. I expect it will be done in a few days. For now you could use klipper from pull request branch https://github.com/Klipper3d/klipper/tree/work-rp2040canboot-20221103 , or just wait a bit until klipper is ready. Also in klipper menuconfig bootloader support(16kib) should be enabled. |
Yea, I'll admit.. I had a total brain dump when I realized I STILL had to flash klipper after canboot... considering I've done canboot on the btt stuff a few times .. thanks for the response.. |
This is a led indicator on the side of the board to basically let you know if it flashed or not.. or status?? I'm not sure.. but I used my gpio24 enabling and disabling to make sure canboot flashed ok |
Hi, gpio24 is a status led -- Mellow does not explain in their docs what
does it do, so people just keep copying it from their example config
(https://mellow.klipper.cn/#/board/fly_sb2040/flash)
But generally I've found it's better to treat it as a status led in the
canboot, so that I can distinguish between canboot active (blinking) and
klipper active (solid)
y.
…On Sun, Nov 6, 2022 at 10:45 AM tnap1979 ***@***.***> wrote:
hey guys, i have a question. im running the mellow SB2040 v1 canbus
printhead... on manta m4p/cb1 combo running the latest btt cb1 full image
with klipperscreen and a UtoC-3 im able to get a succesful UUID from the
sb2040 but klipper still seems unable to connect to the sb2040 mcu via can
the can network is obviously up and running if im able to get the uuid no ?
what gives ? why wont klipper connect to the mcu? i have a proper .cfg
setup with mcu id and cnabus uuid
Well, most low level parameters should be ok by default. Recommended
install procedure is following:
1. Boot into buildin bootloader mode - apply power with mode button
pressed
2. Flash binary flash_nuke.uf2 (
https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython)
via mass storage method or via rp2040_flash
3. Wait a minute or two. Dyring this flash_nuke.uf2 will erase all
flash
4. Boot into buildin bootloader mode again
5. Build canboot.uf2 and flash canboot.uf2 by the same method
6. Check usb or can bus - canboot should be up running and connected
*7. Now it is possible to flash klipper.bin from my klipper pr.
Bootloader option should be enabled in klipper menuconfig.*
This should work given hardware is ok.
once canboot is flashed, you need to flash klipper from sh83s klipper
fork, at least until his pull request is merged.
Yea, I'll admit.. I had a total brain dump when I realized I STILL had to
flash klipper after canboot... considering I've done canboot on the btt
stuff a few times .. thanks for the response..
After all said and done, the system IS running very stable and so far
hasn't presented any issues.. and has now made about 5 consecutive prints
in a row
—
Reply to this email directly, view it on GitHub
<#45 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUKYX3TF6MOPAKG5CEKPOLWG7ACLANCNFSM6AAAAAARKRKOPU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Nice.. did not know it could be used for status... |
[image: Screenshot 2022-11-06 at 10.53.41 AM.png]
this is my "suggested" config for SB-2040.... it should enable you to enter
canboot also by shorting the two-pin endstop pins
(there are three slots for endstops on SB-2040, so I'm using the one I'm
not using for endstop)
y.
…On Sun, Nov 6, 2022 at 10:52 AM tnap1979 ***@***.***> wrote:
Hi, gpio24 is a status led -- Mellow does not explain in their docs what
does it do, so people just keep copying it from their example config (
https://mellow.klipper.cn/#/board/fly_sb2040/flash) But generally I've
found it's better to treat it as a status led in the canboot, so that I can
distinguish between canboot active (blinking) and klipper active (solid) y.
… <#m_2375375500144913956_>
On Sun, Nov 6, 2022 at 10:45 AM tnap1979 *@*.*> wrote: hey guys, i have a
question. im running the mellow SB2040 v1 canbus printhead... on manta
m4p/cb1 combo running the latest btt cb1 full image with klipperscreen and
a UtoC-3 im able to get a succesful UUID from the sb2040 but klipper still
seems unable to connect to the sb2040 mcu via can the can network is
obviously up and running if im able to get the uuid no ? what gives ? why
wont klipper connect to the mcu? i have a proper .cfg setup with mcu id and
cnabus uuid Well, most low level parameters should be ok by default.
Recommended install procedure is following: 1. Boot into buildin bootloader
mode - apply power with mode button pressed 2. Flash binary flash_nuke.uf2
(
https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython
<https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython>)
via mass storage method or via rp2040_flash 3. Wait a minute or two. Dyring
this flash_nuke.uf2 will erase all flash 4. Boot into buildin bootloader
mode again 5. Build canboot.uf2 and flash canboot.uf2 by the same method 6.
Check usb or can bus - canboot should be up running and connected 7. Now it
is possible to flash klipper.bin from my klipper pr. Bootloader option
should be enabled in klipper menuconfig. This should work given hardware is
ok. once canboot is flashed, you need to flash klipper from sh83s klipper
fork, at least until his pull request is merged. Yea, I'll admit.. I had a
total brain dump when I realized I STILL had to flash klipper after
canboot... considering I've done canboot on the btt stuff a few times ..
thanks for the response.. After all said and done, the system IS running
very stable and so far hasn't presented any issues.. and has now made about
5 consecutive prints in a row — Reply to this email directly, view it on
GitHub <#45 (comment)
<#45 (comment)>>, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ACUKYX3TF6MOPAKG5CEKPOLWG7ACLANCNFSM6AAAAAARKRKOPU
<https://github.com/notifications/unsubscribe-auth/ACUKYX3TF6MOPAKG5CEKPOLWG7ACLANCNFSM6AAAAAARKRKOPU>
. You are receiving this because you were mentioned.Message ID: @.*>
Nice.. did not know it could be used for status...
Ya.. mellow docs aren't the best... they need work.
Well now I know I'll be setting up status led on my voron tridex build
—
Reply to this email directly, view it on GitHub
<#45 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUKYX3TVAZSH555F64KGS3WG7A2NANCNFSM6AAAAAARKRKOPU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thank you for your quick answers. I think that I will wait a couple of days that klipper merge the branch. For the GPIO24, jtrmal was true, I just copied it from the Mellow Fly documentation.
Also, please jtrmal, as the message was posted from an email my navigators can't launch the image : [image: Screenshot 2022-11-06 at 10.53.41 AM.png]. It seems very interesting. |
ok, I uploaded it again, didn't know that github won't add the pic. I actually didn't figure out if the "doublick" option does something for SB-2040, as it does have only boot button. Also, it's not super-important to have the endstop as "button" enabled, as flash_can can trigger canboot on its own. |
@Flob74 if you use the latest Kiauh klipper helper.. you can install @sh83 version of klipper directly thru kiauh, that's how I did mine |
This PR add support for the rp2040 mcu. All of USB, CAN and UART communication interfaces are supported, but only USB was tested well. The most of the code was taken from klipper, pico sdk and canboot. The folder lib/ was taken from klipper as is, without modifications.
The existing code mostly was not unchanged, so no regress on other mcu is expected.
The companion PR Klipper3d/klipper#5844
I have added online comments to the non-trivial places.
Signed-off-by: Alex Malishev malishev@gmail.com