Unable to upload sketch to A-Star 32U4 Prime SV

Hardware: A-Star 32U4 Prime SV microSD with LCD (https://www.pololu.com/product/3115)
Software: Arduino IDE 1.8.3, AStar32U4 —>BlinkLEDs
Problem: Unable to upload sketch

Sequence of events:

  1. Uploaded BlinkLEDs successfully.
  2. Uploaded the following modified/new blink LEDs successfully

the modified/new sketch:

#include <avr/io.h>
#include <util/delay.h>

int main (void)
{
    DDRC |= (1<<DDC7);
   while (1)
   {   
    for (int i = 0; i<20; i++)
     {
        PORTC |= (1<<PORTC7);// led on, high
        _delay_ms(50); 
       PORTC &= ~(1<<PORTC7); // led off, low
       _delay_ms(50);
     }
  _delay_ms(500);
  }
}
  1. Uploading the AStar32U4 – BlinkLEDs failed. No COM port for the board.
  2. Reinstalled A-star driver and library (https://www.pololu.com/docs/0J61/6.1)
  3. Still failing, same as #3
  4. Used the reviving procedure “The uploading-before-bootloader method” (https://www.pololu.com/docs/0J61/10.1)
  5. Uploaded the AStar32U4 – BlinkLEDs successfully. COM12 in Device Manager and Arduino IDE (Tools)
  6. Uploaded the AStar32U4 – LCDBasics successfully.
  7. Uploading the AStar32U4 – BlinkLEDs failed
  8. Repeated #6, worked again.
  9. Uploading the AStar32U4 – BlinkLEDs failed again.
  10. Repeated #6, still failing, didn’t work. Tried the reviving procedure “The bootloader-before-uploading method” (https://www.pololu.com/docs/0J61/10.1). still failing.
    Also tried to use different usb ports, powered on/off my computer (Windows 10), but all failed.

Last few lines of Arduino IDE message:

...
Using library AStar32U4 at version 1.0.5 in folder: C:\Users\AnotherPCuser\Documents\Arduino\libraries\AStar32U4 
Sketch uses 5792 bytes (20%) of program storage space. Maximum is 28672 bytes.
Global variables use 192 bytes (7%) of dynamic memory, leaving 2368 bytes for local variables. Maximum is 2560 bytes.
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.

What did I do wrong? Any help would be appreciated.

(Note: the sequence of events number were from 1 to 12 in my post. But the actual post display separated the numbers, resulting in 1 to 2, then 1 to 10)

Hello.

I am sorry you are having trouble uploading programs to the A-Star 32U4 Prime. Arduino sketches normally do not define a main function: you are supposed to instead define a setup function and a loop function. Please see the BlinkLEDs sketch from our AStar32U4 library for an example of how to structure your sketch.

If you really want to define your own main in the Arduino IDE, you will need to call init() and initialize the USB interface. (See the code inside hardware\arduino\avr\cores\arduino\main.cpp, which defines the main loop for Arduino sketches.) Since your sketch does not initialize a USB interface, after uploading your sketch, your computer no longer recognizes the A-Star’s Programming Port, meaning whenever you try to upload another sketch to the A-Star 32U4, it fails because the COM port does not exist.

- Amanda

Thanks for the information.

Update: I tried a different usb cable, and the uploading is working now. The COM port in Arduino IDE shows up as COM12(Pololu A-Start 32U4). I don’t understand why. This is the 3rd usb cable I’ve used. The other two usb cables worked too before the problem started.

Follow-up questions:

  1. What could be done to fix this type of problem, assuming the usb cable didn’t fix the issue?
  2. Did the reviving procedure and my subsequent uploading “restored” the COM port or “reloaded” the init()?
  3. I have successfully uploaded the “int main(void)” type of sketches and the “void setup() , void loop()” sketches to Arduino UNO without any problem. Is this A-Star board different from the Arduino UNO in this aspect?

Thanks.

Just to clarify, in your description of the issue, were you trying to upload the original BlinkLED sketch or your modified version and calling it BlinkLED? It seemed that the issue started after uploading your code.

Regarding your USB cable problem, I suspect that something in your physical setup is causing the issue but am not sure what exactly. Have you tried using the previous USB cables with other devices to see if they are still functional? Do you have anything else connected to your A-Star? Can you post pictures of your setup clearly showing all your connections from your computer and other devices to your A-Star?

Typically, if there is a connectivity issue between the computer and device, it is best to simplify your setup and make sure the physical connections (e.g. USB cable and port) are working before troubleshooting the software side (e.g. drivers, operating system, and code). If that does not answer your question, can you please elaborate?

Subsequently reviving and uploading your C code (without calling init() to initialize the USB interface) did not restore the A-Star’s virtual COM port. You can try testing both versions of your C code to see which works.

The A-Star 32U4 boards use the ATmega32U4 chip, which has built-in USB communication unlike the ATmega328 used on the Arduino Uno. The ATmega32U4’s USB controller needs to be running in order to communicate.

- Amanda

  1. I initially loaded the original “BlinkLEDs” code without any problem. I then loaded my modified code (i.e. the “int main(void)” blink LED code, not the original “BlinkLEDs”) without any problem.
  2. You are correct: this issue started after loading my modified code. However, the reviving procedure fixed the issue for a couple of times. Then, after that, it had not been working until I tried the 3rd USB cable.
  3. I have no other external connection to the A-Star board other than a USB cable from the board to my computer.
  4. For the USB cables: I tried using the previous USB cables with the same A-Star board and another microcontroller board, and two of the three cables work on both boards, one of the three doesn’t work on either board (though the same cable worked on the A-Star board before).
  5. Ref. to your last comment — “The ATmega32U4’s USB controller needs to be running in order to communicate.” — Who makes the USB controller running first? Is the A-Star bootloader?

Thanks for answering all my questions.

I still do not think that reviving the A-Star 32U4 and changing the USB cable fixed the problem; I think the USB cable is a separate issue and that the main issue is caused by your C code. Essentially, your program is causing the A-Star to become unresponsive via USB, because the USB device is not initialized, meaning there is no USB interface, which is why you need to use one of the methods described in the “Reviving using the Arduino IDE” section of the A-Star 32U4 user’s guide to force the A-Star into bootloader mode in order to program it.

With regards to your last question, it sounds like you didn’t look at the source code in Arduino’s main.cpp file that I linked to in my first post. You should look at the code for Arduino’s int main(void) to understand how the Arduino IDE’s build process works and to see how the USB interface is initialized.

I added the following lines of code to your program and was still able to see the A-Star’s COM port after testing it:

#include <Arduino.h>
// ... other libraries

int main (void)
{
   init();
#if defined(USBCON)
   USBDevice.attach();	// initialize USB controller
#endif
   // ... rest of code
}

- Amanda

I tried your code with a known working USB cable, and it works.
Thank you very much again for the detailed explanation and the code.