I am very new to C and embedded programming.
I simply want to have my main thread wait until a usb device has been plugged in to my embedded device.
However, no matter how hard I look, I cant find documentation or examples about how to check if the usb has been plugged in.
I am using a ATSAM4S8B.
EDIT:
Actually I think the usb capabilities are built into the chip, I can use Atmel ASF libraries.
I am hoping that there is just a library function I can call to see if the usb has been connected too but I can't find anything like it.
There are two ways of detecting USB connection:
waiting for usb events occure and special USB flags to fire in hardware registers, which will signal if initiating process started. This solution depends on a particular chip you use and firmware burnt into MCU.
use sense IO pin. Attach USB 5V through 1k resistor to a pin of the MCU. High level on the pin will indicate, that USB was connected. Dont forget to use high value (>10k) pull-down resistor, which will pull the input low when USB disconnected.
Related
Context
I have accidentally uploaded some ARM Cortex M0-cmis files (core-cmFunc.h and core_cmInstr.h) to the STM32F407VG discovery board. After I noticed my mistake, I tried to undo it by changing my code and upload it again... but it said it couldn't make connection.
What I already tried
I've tried to get passed the USART interface of the discovery board by uploading the code directly on the ARM Coretex M4 chip via the bootloader. I connected BOOT0 to VDD and PB2(=BOOT1) to GND so the chip starts up in the Pattern1-mode. Then I connected PA9(=Tx) and PA10(=Rx) to an USB to TTL cable (by the use of a RS-232 chip in the cable) and reset the device. I started the "Flash Loader Demonstrator" from ST to make connection with the board (I've done this before and it worked). But that didn't made connection either.
Extra information
The Windows filemanager "sees" the ARM Cortex M4 file when it gets connected to the PC;
Led LD7 emits green light when the board is powered;
Led LD1 emits red light;
Does someone knows how I can factory-reset the flashmemmory of the STM32F4 so it acts at it should again?
After some trial and error I've come to the conclusion that I accidentally activated the OTG_VBUS with my code. I couldn't upload another code because that bus was active on PA9(TX of USART2). It seems that the VBUS was held active, even in bootloader mode.
PA9 connected to VBUS
The solution to this problem was the use of another bootloader interface, I used USART3 on PB10/11, but you could also use PC10/11. After I uploaded a dummy code in that manner, I
was able to upload codes with the Coocox-IDE again.
Other Bootloader interfaces
I don't have much konwledge in electronics. i wanted to turn on/off led connected to usb port using program. usb port consists 4 line (data+,data-,voltage ,ground) if i connect voltage and ground lines to led , it will glow. i've been searching on internet this issue and i find that it is not possible to control led connected to usb using program because supply over datapin is too low which can not be used to tun on off led.
but what if i connect my led to vol and ground pin and control the entire power supply of usb port , i guess it is possible to control led using program. there is a way to disable and enable power supply over usb port.
i also want to know is it bad to follow this approach. does it damage usb controller to frequently enable/disable power supply.
Algo :
a = Get_input_from_user() ;
if(a=="ON")
turn power supply of usb port ON.
else
turn power supply of usb port OFF.
this thing is certainly possible using extra hardwares, i don't want to use any extra hardware.
The power for a computer's USB ports is generally not software controllable. In most cases, the power pins of your USB ports are wired directly to the 5V rail of your power supply (usually through a polyfuse), so there is no way to switch them on and off.
Some powered USB hubs do support switching power to their ports, but you said that you didn't want to use any extra hardware, so you're out of luck.
you can use any basic Arduino board to do this there is a complete IDE free and a LOT of sample code that will do what you want out of the box
you can also use a COOL board.
Arduino Compatible code is available for the Teensy
Software Development Tools HERE
You can use an external power supply (the Vcc and GND pins of the USB port in this case) with a resistor to power the diode and connect a transistor in the middle working as interruptor. Then, yo connect the base and emisor to de data+ and data- of the USB port.
this page doesnt let me upload images.
Sorry for the quality of the drawing but all I have on the computer is paint.
For a more stable performance make sure to make R1 low enough so that transistor is on saturation mode when data pins are ON but not so low that transistor gets burnt (I dont really know what is the voltage level of the data pins on the USB port, sorry).
To choose a proper value of R2, you need to know the current you need to power your diode. It's calculated acording to Ohm law:
Idiode = (Vcc - Vce,sat - Vd) / R2.
Where Vce,sat is potencial diference between colector and emisor when transistor is on saturation mode (it is found on the transistor datasheet on the manufacturer webpage, usually around 0.2V) and Vd is the normalized potencial difference of the diode (the same, but this time around 0.6V).
Note that data- and GND pins are connected. I am 99% sure that this won't harm your USB port, but use it at your own risk.
I would test it out using another external power source first anyways, just to make sure you connected everything properly.
I am using mini2440 arm board, and GPIO to control the hardware connected with the GPIO. I am using BSP that ships with the cd of the board. I have only enabled functionality which I will need for running the hardware.
I have disabled audio, Ethernet and unnecessary stuff in kernel, so that it don;t cause interrupt hence CPU attention. But the problem is sometimes some interrupt occur on the GPIO and hardware do malfunction. I know I can see all interrupt via cat /proc/interrupt, but how should i know which interrupt occur on GPIO from which device?
I am running my application with highest nice priority (-20), but still sometime external interrupt occur.
When i send data on GPIO, only TimerTick of s3c2440 do interrupt, but that's fine, it is require, but not other. Please tell me how to find which interrupt occur (I know I can check it via cat /proc/interrupt) and how to disable (Disable interrupt on ethernet via ifconfig eth0 down) interrupt from kernel? Need some expert solution, I have tried the solution getting help from people but need some expert solution.
Disabling devices in the kernel has no real efect on interrupts (generated by the hardware), it just affects how software handles them. If the device isn't present, no interrupts get generated. And Linux was written by absolute performance freaks, barring misbehaving hardware the interrupt handling is nearly as good/fast as it could be.
What exactly are you trying to do? Are you sure you aren't trying to get performance that your machine just can't deliver?
I have successfully talked to the computer from an Arduino via serial USB port and I had the idea that I could make a keyboard or mouse with the arduino. Say I wanted to translate the computer's mouse 1 pixel to the left. What message would I have to send over the serial line in order to achieve this?
Google is a wonderful thing. "use arduino as mouse" returns 1.7 million hits. The third hit on the list takes you to the Arduino Playground for an example using the new Leonardo board.
Note:
The Leonardo differs from all preceding boards in that the ATmega32u4 has built-in USB communication, eliminating the need for a secondary processor. This allows the Leonardo to appear to a connected computer as a mouse and keyboard, in addition to a virtual (CDC) serial / COM port.
Assuming you don't have that board, here is another site for some other specific boards and yet another that is log for a project including hardware and software for older boards.
Hope this helps (and is a better answer to the question).
You would have to reconfigure the USB interface chip to appear as a USB HID endpoint.
I'am working on a real-time control system that calculates the control signals in a buffered fashion (a user-mode program) and outputs to the usb device the array through isochronous transfers. The usb device them reports the execution progress through interrupt transfer, so that pc software can then calculate and push the next control array.
The software runs based on raw win32 api, C based. (C++ used only on not time sensitive parts of the program, such as interface, 3D models...).
I would like to know if there is a way to register a callback function in response to a interrupt transfer?
From what I understand, although we are talking about interrupt transfers, the USB device still has to be polled using libusb_interrupt_transfer:
Interrupt transfers are typically non-periodic, small device
"initiated" communication requiring bounded latency. An Interrupt
request is queued by the device until the host polls the USB device
asking for data.
Excerpt from https://www.beyondlogic.org/usbnutshell/usb4.shtml#Interrupt