You are here

Useful Reset Design for Cypress CY8CKIT-049 Prototyping Kit | Cypress Semiconductor

Useful Reset Design for Cypress CY8CKIT-049 Prototyping Kit

Just over a  month ago, at Embedded World, we gave away about 1500 of the new PSoC 4 Prototyping Kits. These $4 kits are a great way to get to know PSoC 4 and do some speedy proof-of-concept designs. The board can be snapped in two with one part serving as a programmer and the other, with the on-board PSoC device, mounted on your prototype board.
 
If you are one of the guys from the conference who I forced to watch a demo just so you could get a kit... drop me a line in the comments. Ask me a question. Tell us what you've done with it. Or just say hello!
 
I've been using the kit for a while and the first thing I did was figure out a way to re-program the board without having to remove it from the USB port. Here's my design - I think it is quite handy. Give it a try and let me know how you get on.
 
When you plug the board into a USB port it boots into the application. But if you want to re-program the board you hold the SW1 button down as you insert it into the port. That forces the board to run its bootloader and you can re-program the application using the Cypress Bootloader Host tool (below).
 
Language: 
English
 
This all works just fine but if you want to quickly modify your application and re-program it, you need to remove the board from the USB port and re-insert it with the button held down.
 
That got a bit boring. So I figured out a way to reset the board, into the bootloader, from any application.
 
 
My PSoC Creator Bootloadable design (top right) uses a simple Timer that is controlled from the SW1 button (the same one you have to hold down to enter the bootloader normally). I'll break down the image so you can understand what it does.
 
The Timer - which is called ResetTimer - is clocked at 12kHz and the switch is attached to the start, reload and stop inputs (more on that in a while). There is also an interrupt output from the Timer component and that is connected to an ISR. It is this ISR that causes the board to reset into the bootloader.
 
As with many PSoC components the really cool part is the dialog that lets you configure all the parameters (just double-click on the component).
 
Below, you can see how I configured ResetTimer as a one-shot down counter with a period of 24000. That means when it starts it will count down from 24000, stop when it reaches zero, and assert the interrupt (terminal count). The period of 24000 equates to 2 seconds with the 12kHz clock.
 
 
In the above picture I connected SW1 to all the inputs. You'll notice that I set them up as follows; start and reload occur on a falling edge, whereas stop happens on a rising edge. The switch is grounded on the board so when it is pressed the input goes low (falling edge). This reloads the period into the counter (to 24000) and starts the down counter. If the switch remains pressed for 2s then the terminal count is reached and the interrupt fires. If the button is released then a rising edge occurs and the counter is stopped. The interrupt does not fire and the application continues to run. If I press the button again the whole process restarts (from 24000) - so you always have 2 seconds to change your mind.
 
 
You only need a tiny amount of code in your application to make this work.
 
Firstly, you need the write the ISR, which just has to call "Bootloadable_Load()" to re-enter the bootloader (assumes your Bootloadable component is called, simply, "Bootloader").
 
Then, in main() you just start the ResetTimer, install the ISR and enable interrupts. After that you can write your application normally and the reset system will not interrupt or interfere in any way.
 
#include
 
/* Prototype the ISR handler */
CY_ISR_PROTO( ResetISR_Handler );
 
/* Implementation of the ISR handler */
CY_ISR( ResetISR_Handler )
{
    Bootloadable_Load();        /* Force a bootloader restart */
}
 
int main()
{
    /* Start the timer - only runs when SW1 is pressed */
    ResetTimer_Start();
 
    /* Install the ISR handler and make sure none are pending */
    ResetISR_ClearPending();
    ResetISR_StartEx( ResetISR_Handler );
 
    CyGlobalIntEnable;
 
    for(;;)
    {
        /* My actual application does nothing - waits for a reset !!! */
    }
}
 
One last thing to mention. This design does not mean you cannot use the button for other purposes. Here's an example of the switch getting routed straight to the blue LED on P1.6 as well as driving the timer. Because the switch is active low and the LED active high I put an inverter (not-gate) between the two. Now when I press the switch the LED goes on... just don't hold it down for 2 seconds unless you want to reboot!
 
 
 
Add this to your applications and you'll be able to re-start the bootloader in just a couple of seconds. The Bootloader Host reconnects immediately and you can download a new application in no time at all.
 
Happy bootloading!
--Mark Saunders
 
This is a re-post.  This blog was originally posted by Mark Saunders on the Cypress ARM Community blog.

Comments

RA1981's picture

Hi Mark.

Nice approach. I did something similar, but with UART. I picked one of the characters not used in my transmission protocol, which starts the bootloader. So I don't have to wait 2s. This approach works if someone is working with terminal software as well as with dedicated applications. Even if the transmission protocol uses binary format, starting the bootloader can be packed into a command.

Regards,

Ralf

Eree's picture

Really Very Useful Blog .

ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.