the availability of "go to definition" of your IDE. It is a life saver.
loop: ldr r1, [r0, #GPIO_ODR] /* read DATA reg */
eor r1, r2 /* complement bit */
str r1, [r0, #GPIO_ODR] /* write */
b.n loop
(NOT the shortest possible loop, BTW.) And I implemented some symbolic indirection to make it easier to change the values (code attached.) The no-wait-state code looks like it's taking about 9 clocks for the 4-instruction loop, which is not as good as I thought it would be (although I wouldn't find 6 surprising - 1 extra for the 32bit instruction and one extra for the branch.) Maybe I've left something out? ------------(MHz)--------
PLLMULT F(cpu) F(0WS) F(1WS) F(2WS)
- 8 0.444 0.400 0.364
3 24 1.330 1.200 1.091
4 32 1.779
5 40 2.225* 1.818
6 48 2.669*
7 56 3.115*
8 64 fail 3.200* 2.91
9 72 3.600* 3.27
10 80** 4.000*
11 88** 4.400*
12 96** 4.800*
13 104** 5.200* 4.73
14 112** 5.600*
15 120** 6.000*
16 128** 6.400* 5.8
* exceeds documented memory speed
** exceeds documented cpu max freq
ldr r1, [r0, #GPIO_ODR] /* read DATA reg */
eor r1, r2, #(1<<mybit)
loop:
str r1, [r0, #GPIO_ODR] /* 1 write */
str r2, [r0, #GPIO_ODR] /* write */
str r1, [r0, #GPIO_ODR] /* 2 write */
str r2, [r0, #GPIO_ODR] /* write */
str r1, [r0, #GPIO_ODR] /* 3 write */
str r2, [r0, #GPIO_ODR] /* write */
Two weeks later, one of two "experienced programmers" eventually succeeded in blinking an led. The other one is still trying.
Phew! Talk about steep learning curves,
I wonder if you can explain what changed.
.equ DODELAY, 0 /* if 0, just toggle at max loop speed. */
/* if 1, blink at human-like speeds */
.equ WAITSTATES, FLASH_ACR_LATENCY_1
.equ PLLMULT, RCC_CFGR_PLLMULL9
@ .equ PLLMULT, 0 /* If 0, don't use the PLL */
/* Note that xxx PLLMULL2 is 0, so this structure */
/* doesn't support x2 clock configurations */
then the ClockInit code uses the new symbols (PLLMULT, WAITSTATES) instead of the symbols direct from the .asmh files.What actually caused the 4x speedup to become 9x?
#include <device.h>
int main()
{
/* Start the Clock and PWM components. Clock can be started automatically
after reset by enabling “Start on Reset” in the Clocks tab of
Blinking LED.cydwr. We are doing this manually for instructive purpose. */
Clock_Start();
PWM_Start();
for(;;)
{
}
}
/* [PSOC Blink main loop] */
for(;;)
{
}
#include <project.h>
int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
/* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
for(;;)
{
/* Place your application code here. */
Pin_Blue_Write(~Pin_Blue_Read());
CyDelay(500);
}
}
BTW I can do my own component with my own support code (even in assembly if so inclined)
(at least uVision
Using the CY8C42xx Example Project
1. Install Keil µVision MDK-ARM Standard Version 4.54 (or later).
2. Copy the CY8C42xx.FLM file to C:\Keil\ARM\Flash. This file will be selected during µVision
startup.
3. Connect ULINKPro to the USB port and then connect it to the target board. In the example, the
10-pin ARM connector is used, although only five pins (VCC, GND, XRES, SCLK, and DATA) are
required
...
11 more steps all defined in that document.
but still some disappointments:
NO BOOTLOADER. This is a huge drawback IMO. Serial upload is what made STM32 chips so cheap and easy. "Free" as dannyf calls it. I'm guessing you have to blow another $30-$50 for Pioneer or Miniprog3. Not great at 10x the cost of STM. You can probably buy a few STM ICE setups for that too.
I find out now the chip on the 049-42xx card is not one of the $1 (soon to be $3) dealies. In fact it's very hard to determine just what chip is actually on there. Lots of mentions for their USB/serial device but not for the target in ads and docs. They seem to have actually erased the numbers off the top. WTF. It took a while but finally figured it out. Not too hard to locate the menu entry in Creator but far from minimum having to depend on that and generally annoying.
To download Creator you must register with their exclusive club which involves providing email and personal info. I do not need spam to double like last time so back on the "museum of interesting chips" shelf for now.
If there's anyway around these issues it might be somewhat more attractive and competitive with other options in the ARM world. However because of flashing hardware difficulties don't look like it's possible for guys like me who just want to poke a stick at new chips without spending more than couple bucks. You know, like we can with 8051, AVR, STM etc..
int WriteIO (unsigned int addr, unsigned int data)
{
unsigned int *address = (unsigned int*)addr;
*address = (unsigned int)data;
return (0);
}
int ReadIO (unsigned int addr, unsigned int *data)
{
unsigned int *address = (unsigned int*)addr;
*data = *address;
return (0);
}
//----------------------------------------------------------------------------------
// Custom functions
//----------------------------------------------------------------------------------
void Delay(int ms)
{
int i , j;
for(i = 0; i < ms; i++) {
for(j = 0; j < 3333; j++); //Delay = 1ms, mesured by scope for CY8C41xx (CPU = 48MHz)
}
}
void LED_Write(char value)
{
WriteIO(0x40040000, value); //GPIO2.GPIO2_PRT.DR
}
//----------------------------------------------------------------------------------
// main() function
//----------------------------------------------------------------------------------
int main (void)
{
char leds = 0x01; //Initial state of LEDs: P0[0] - On
WriteIO(0x40040008, 0x06); //Set Strong Drive Mode for P0[0] in GPIO2.GPIO2_PRT.PC register
for (;;)
{
LED_Write(leds); //Invert LED state on P[0] in GPIO2.GPIO2_PRT.DR register
Delay(500);
leds ^= 0x01;
}
}
µVision Build Log
Project:
D:\Keil\ARM\Examples\Template_Project\Template_Project.uvproj
Project File Date: 12/14/2013
Output:
Build target 'Template_Project'
creating preprocessor file for main.c...
compiling main.c...
assembling startup_CM0.s...
linking...
Program Size: Code=212 RO-data=208 RW-data=0 ZI-data=512
FromELF: creating hex file...
After Build - User command #1: .\Hex_Converter\HexConverter.exe .\\Hex_Converter\\Configuration.ini
".\Hex\Template_Project_uVision.axf" - 0 Error(s), 0 Warning(s).
Empty PSoC4 template
Add digital output pin and name it Pin_Blue
Select GPIO p0[3]
Pin_Blue_Write(~Pin_Blue_Read());
CyDelay(500);
is pin 47-48 marked wrong on the board?