-
Notifications
You must be signed in to change notification settings - Fork 39
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
Boot Reset vector #25
Comments
Guys, Just to give you an update, I was able to compile the codebase with UART debug messages and can confirmed that the bootloader is calling every time at the system reboot. So there's no issues with the Boot Reset Vector or anything, bootloader kicks in very well. As indicated earlier, initial firmware loading from the SD card has no issues and neither SD card read/write using arduino SD example has any issues, all working good - this will eliminate any concerns about the SD card wiring to the system ATMega1284p. However at subsequent reboots causing disk_initialize() to return STA_NOINIT which resulting firmware download process to stop working. I have no idea why this STA_NOINIT returns. Any thoughts? |
Hi all, Regards! |
Mine was due to a 'bad' SD card although the first time working. I've debug
the bootloader code and found it's failing to initialize at the second run.
I changed the SD card and all working smoothly.
I suggest you to try the same if you haven't yet.
…On Wed, Mar 14, 2018, 7:33 AM livius147 ***@***.***> wrote:
Hi all,
I have the same problem: only at first boot the bootloader flashes the
FIRMWARE.BIN.
Have you any news about this topic?
Regards!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#25 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/Ag4Y24m6R-olviqpEHzRFsOY3gFiG-Y2ks5teC0rgaJpZM4Q-5Nh>
.
|
Thanks a lot! I will try it. |
I found a workaround; I modified the main.c as follows:
With this patch the bootloader reads and writes the FIRMWARE.BIN file at every startup. P.S.: this workaround must be modified to avoid infinite loop. |
I suggest something like this:
|
did you test this?
…On Thu, Mar 15, 2018 at 9:25 AM, livius147 ***@***.***> wrote:
I suggest something like this:
`diff --git a/Arduino/avr_boot/main.c b/Arduino/avr_boot/main.c
index 8beeb86..fdedd79 100644
--- a/Arduino/avr_boot/main.c
+++ b/Arduino/avr_boot/main.c
@@ -147,8 +147,14 @@ void doFlash() {
void checkFile() {
uint8_t fresult;
-
uint8_t cnt = 0;
-
fresult = pf_mount(&Fatfs); /* Initialize file system */
-
/* Initialize file system */
-
while ((fresult = pf_mount(&Fatfs)) != FR_OK && cnt<10)
-
{
-
_delay_ms(100);
-
cnt++;
-
}
if (fresult != FR_OK) { /* File System could not be mounted */
#if USE_UART
`
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#25 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AMPrDYCzA_wWfKryCPraU6LYPrdQGnloks5teZjJgaJpZM4Q-5Nh>
.
|
Yes, I tested it and it works. The maximum "wait time" in that loop is 100ms x 10, that is 1s. |
@zevero may you consider to add this patch to the official code? This patch retries mounting the sdcard fat filesystem: with my configuration (above described), pf_mount is unable to mount the sdcard at first call. So I added 10 retries with 100ms sleep. |
Though I said this was due to a 'bad' SD card, I've started to experience this again and this time I've checked with 4 different microSD cards and they all come up with the same issue, this time not even the first time bootloading works, it just stay there with AVR_BOOT and stuck in the disk_initialize() always returns STA_NOINIT and retry. I even tried with 100 ms delay loop with a count of 10, no luck! Any idea what could go wrong here? In a separate test, with these 4 microSD cards with the same hardware (custom board with commercial grade PCB/SMDs) for basic read/write and they all works fine. So I can assume the hardware is working fine. Then it seems the problem is with the FatFs disk_initialize(), I don't know what causing this issue returning always STA_NOINIT. All of these microSD cards were 1GB and formatted before use. Highly appreciate your feedback. |
I'm just wondering whether SPI speed could be the issue here? I can see my SD read/write functions successfully using Arduino SdFat library with 50MHz. What speed this AVR_BOOT SPI is working? I wonder lowering the speed may be helpful? @zevero could you please help? |
Did you test accessing the sdcard, with the same wiring scheme, with a test code? Did you check if the circuit has a voltage drop? If the voltage is not stable the burnout circuit of atmega shuts down the microcontroller. The burnout thresholds can be changed. I suggest you to put a large capacitor in the main power line (200-500uF) and test again with the patch I suggested. I am using it without problem. |
Just another thought, do I need to use any pull up resistors for any of the SS, CLK, MISO or MOSI pins? Also how do I change the SPI speed? I checked currently bootloader SPI is running at 8 MHz between micro and SD card, can I lower the speed? P.S. there's no brownout indication as I am printing the reset cause as well, also I checked the wiring seems okay. |
No pull up resistors are needed for SPI, only for i2c. |
May I know what is your board? A custom made one or a standard shield? Voltage shouldn't be a problem as exactly the same setup perfectly works with sdFat/SD library in another arduino test code. My board is a custom made PCB with copper tracks between micro and SD card which goes through a TXB0104 to the SD adapter. When I use my vero board version with wires to a SD card module (something like this.. https://www.ebay.com.au/i/382813690302?chn=ps), bootloader works pretty well. Would you be able to share your bootloader HEX file, just to give another try. Below are my configuration: |
Thanks for sharing, I can confirm mine also have a smoothing cap near SD card, but my system runs on 5V and therefore I use level translators. Just a question, how do you compile the bootloader? I am using WINAVR in Windows environment, hope that shouldn't be an issue. Also did you ever try to use SDHC cards? (Say FAT32 8/16/32GB versions) with this bootloader? |
If I am not wrong, I am using a 8G sdcard formatted in fat16; but I am not sure of this config. I will check this afternoon. In order to enable/disable fat16/32 you have to change the configuration in the pff/src directory. |
Thanks, how do you compile the bootloader? I am using WINAVR in Windows environment, hope that shouldn't be an issue. |
I develop all my codes under linux. |
Okay thanks, do you ever test the SPI speed between micro and SD card? I am seeing an 8 MHz clock frequency. |
I put a digital probe on the pin PB5/CLK and I read ~530kHz during boot and 250kHz when the arduino library reads the sdcard. My atmega328 runs with an internal clock @ 8MHz. |
That's strange, wondering why I am seeing a 8MHz CLK on the SPI between micro and SD card, I'm using 16MHz external low power. I wonder whether there's any difference between building in Windows (using WINAVR) vs building in Linux of AVR_BOOT project. I am going to build the project now in a Linux box, will see how it goes. |
I've compile the bootloader in Ubuntu environment, glad this worked. I've tested with a small code (~1K Bin) with test LED blink and I can reload it over and over again using the bootloader. The bootload process seems taking less than 5 seconds. However if I compile a code with 11K Bin file, this just does not work, I can see bootloader is keep writing to the flash as it's SS LED is blinks, but I've waited for more than 2 min, nothing happened. Any idea what would be the issue? |
Hello Falks,
I was trying to use this with my ATMega1284P, however first run going smoothly which loads the bin file in my SD card, for some reason subsequent resets does not kick start the bootloader and therefore does not load any more bin files from the SD card.
Is this something to do with the Boot Reset Vector?
Any idea how can I continue to use the bootloader so that any time a FIRMWARE.BIN on SD card will get loaded upon reset (and from the program I can delete the BIN file)
To note, I was using the boards manager installation on Arduino 1.8.1
Cheers,
Las
The text was updated successfully, but these errors were encountered: