}
}
-void cpSetLeds(int fd)
+void cpSetPortConf(int fd, int pullups)
{
int ret;
cp2101_port_config_t config;
exit(1);
}
- /* Set the current port configuration; turn on GPIO_0 and GPIO_1 to get
- * activity LEDs. GPIO_2 and GPIO_3 are set for 'regular' gpio.
+ /* This section assumes the device is currently at factory defaults. If
+ * not, first run 'cpfactory'. The only delta from factory defaults is to
+ * activate the activity pin functions for GPIOs 0 and 1. Some boards may
+ * require weak pull-ups, but not TMI's RWS.
+ *
+ * GPIO mapping:
+ * GPIO_0 -> TX activity, active low
+ * GPIO_1 -> RX activity, active low
+ * GPIO_2 -> MSP430 UC_TCK
+ * GPIO_3 -> MSP430 UC_RST
+ *
*/
- config.reset.mode &= ~0x0300;
- config.suspend.mode &= ~0x0300;
- config.reset.latch |= 0x0300;
- config.enhancedFxn |= 0x03;
- //config.enhancedFxn &= ~0x10; /* turn off weak pullups */
- config.enhancedFxn |= 0x10; /* turn on weak pullups */
+ config.reset.mode |= 0x0800; /* GPIO_3 gets push-pull driver */
+ config.enhancedFxn |= (pullups) ? 0x13 : 0x03;
+
if ((ret = ioctl(fd, IOCTL_PORTCONFSET, &config))) {
fprintf(stderr, "portconfset ioctl failed %d\n", ret);
exit(1);
}
}
+void usage(char* program)
+{
+ fprintf(stderr, "usage: %s [--pullups] <tty> <mfg> <part#> <sn#>\n",
+ program);
+}
+
int main(int argc, char* argv[])
{
/* char newmfg[255]; */
char newprod[255];
char newsn[255];
int fd;
+ int pullups = 0;
+
+ if (argc < 5 || argc > 6) {
+ usage(argv[0]);
+ exit(1);
+ }
- if (argc != 5) {
- fprintf(stderr, "usage: %s <tty> <mfg> <part#> <sn#>\n", argv[0]);
- exit(1);
+ if (argc == 6) {
+ if (strncmp(argv[1], "--p", 3) == 0)
+ pullups = 1;
+ else {
+ usage(argv[0]);
+ exit(1);
+ }
}
- /* strcpy(newmfg, argv[2]);
- * strcpy(newprod, argv[3]);
+ /* strcpy(newmfg, argv[pullups + 2]);
+ * strcpy(newprod, argv[pullups + 3]);
*/
- snprintf(newprod, sizeof(newprod), "%s %s", argv[2], argv[3]);
- strcpy(newsn, argv[4]);
- fd = cpConnect(argv[1]);
+ snprintf(newprod, sizeof(newprod), "%s %s", argv[pullups + 2],
+ argv[pullups + 3]);
+ strcpy(newsn, argv[pullups + 4]);
+ fd = cpConnect(argv[pullups + 1]);
/* SiLabs doesn't allow set of mfg string on cp210x.
* cpSetStr(fd, IOCTL_SETMFG, newmfg, strlen(newmfg));
*/
cpSetStr(fd, IOCTL_SETPRODUCT, newprod, strlen(newprod));
cpSetStr(fd, IOCTL_SETSERIAL, newsn, strlen(newsn));
- cpSetLeds(fd);
+ cpSetPortConf(fd, pullups);
cpReset(fd);
cpDisconnect(fd);
printf("done\n");