Hi all,

I'm attempting to write a USB stack for a super simple low power
device using a PIC16F1454 (pic14) and SDCC (from svn trunk).

I'm defining these two structures

__at(0x2000) volatile BDT_t ep0Bo;
__at(0x2070) volatile setup_package_t setupPacket;

... and then doing "ep0Bo.ADDR = (uint16_t) &setupPacket;" but this
resets my device. I assume I'm using the BDT address in the wrong way,
but there doesn't seem to be many understandable pic14 USB examples
that can compile with SDCC. Breaking on the offending line shows that
&setupPacket does indeed equal 0x2070. I'm trying to use the 0x2070
buffer to receive the setup packet.

I've attached a minimal reproducer to show the problem. Any advice
very welcome, thanks!

Richard
#include <pic14regs.h>
#include <stdint.h>

unsigned int __at(_CONFIG1) configWord1 =
	_FOSC_INTOSC &
	_WDTE_OFF &
	_PWRTE_OFF &
	_MCLRE_OFF &
	_CP_OFF &
	_BOREN_ON &
	_CLKOUTEN_OFF &
	_IESO_OFF &
	_FCMEN_ON;
unsigned int __at(_CONFIG2) configWord2 =
	_LVP_ON &
	_DEBUG_OFF &
	_LPBOR_OFF &
	_BORV_LO &
	_STVREN_ON &
	_PLLEN_ENABLED &
	_PLLMULT_3x &
	_USBLSCLK_48MHz &
	_CPUDIV_NOCLKDIV &
	_WRT_OFF;

#define AddrToPhysical(a) ((uint16_t)(a))

typedef struct {
	uint8_t Stat;
	uint8_t Cnt;
	uint16_t ADDR;
} BDT_t;

typedef struct {
	uint8_t bmRequestType;
	uint8_t bRequest;
	uint8_t wValue0;
	uint8_t wValue1;
	uint8_t wIndex0;
	uint8_t wIndex1;
	uint16_t wLength;
} setup_package_t;

__at(0x2000) volatile BDT_t ep0Bo;

__at(0x2070) volatile setup_package_t setupPacket;

void main(void) {
	TRISC = 0xc7;
	PORTCbits.RC5 = 0;

	/* switch to 16Mhz operation */
	OSCCONbits.SCS = 0x0;
	OSCCONbits.IRCF = 0xf;
	while (!OSCSTATbits.PLLRDY);

	ep0Bo.ADDR = AddrToPhysical(&setupPacket);
	/* ...and we never get here... */
	PORTCbits.RC5 = 1;
}
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to