program something;
uses cortexm3, stm32f103fw;
Procedure USB_Init; cdecl; external name'USB_Init';
Procedure USB_Shutdown; cdecl; external name'USB_Shutdown';
Procedure USB_SendData(EndPoint: byte; var data: word; Lenght: word); cdecl; external name'USB_SendData';
Procedure USB_PMA2Buffer(endpoint: byte); cdecl; external name'USB_PMA2Buffer';
Procedure USB_Buffer2PMA(endpoint: byte); cdecl; external name'USB_Buffer2PMA';
Procedure USB_LP_CAN1_RX0_IRQHandler; cdecl; external name 'USB_LP_CAN1_RX0_IRQHandler';
Procedure Pins_Init; cdecl; external name'pins_init';
Procedure Pin13_One; cdecl; external name'pin13_one';
Procedure Pin13_Cero; cdecl; external name'pin13_cero';
Procedure Pin13(status: byte); cdecl; external name'pin13';
Procedure USB_EPHandler(status: word);cdecl; external name'USB_EPHandler';
Procedure USB_Reset; cdecl; external name'USB_Reset';
{$L c:\hidboot\f1\build\usb.o}
{$L c:\hidboot\f1\build\hid.o}
{$L c:\hidboot\f1\build\flash.o}
{$L c:\hidboot\f1\build\led.o}
const
MAX_BUFFER_SIZE = 64;
MAX_EP_NUM = 2;
{$O-}
Type
TLed = bitpacked array[0..15] of boolean;
USB_RxTxBuf_t = record
RXB: array[0..MAX_BUFFER_SIZE div 2] of word;
PTXB: word;
RXL: byte;
TXL: byte;
MaxPacketSize: byte;
end;
var
DeviceConfigured: word; external name 'DeviceConfigured';
DeviceAddress: byte; external name 'DeviceAddress';
DeviceStatus: word; external name 'DeviceStatus';
UploadStarted: boolean; external name 'UploadStarted';
UploadFinished: boolean; external name 'UploadFinished';
RxTxBuffer: array[0..MAX_EP_NUM] of USB_RxTxBuf_t; external;
PuertoA : TLed absolute PortA.ODR;
PuertoB : TLed absolute PortB.ODR;
PuertoC : TLed absolute PortC.ODR;
PuertoD : TLed absolute PortD.ODR;
LedB : TLed absolute PortB.ODR;
LedC : TLed absolute PortC.ODR;
contador: word;
contador2,
contador3: word;
cuenta_max: word = 20;
subiendo: boolean = true;
procedure USB_Low_Priority_or_CAN_RX0_interrupts; public name 'USB_Low_Priority_or_CAN_RX0_interrupts'; interrupt;
begin
USB_LP_CAN1_RX0_IRQHandler;
USB.ISTR:= 0;
end;
begin
//************************************************
//**************** RCC *************************
RCC_HSICmd(Enabled);
RCC_DeInit;
RCC_HSICmd(Enabled);
RCC_HSEConfig(RCC_HSE_On);
RCC_WaitForHSEStartUp;
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6); //48MHz
RCC_PLLCmd(Enabled);
while rcc.cr and RCC_CR_PLLRDY = 0 do
begin
//wait pll ready
end;
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2); //24MHz
RCC_PCLK2Config(RCC_HCLK_Div1); //48MHz
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while RCC_GetSYSCLKSource <> %1000 do //(RCC_SYSCLKSource_PLLCLK shl 2)
begin
//wait pll source
end;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1 or RCC_AHBPeriph_DMA2 or RCC_AHBPeriph_SRAM or RCC_AHBPeriph_FLITF, Enabled);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, Enabled);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, Disabled);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, Enabled);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 or RCC_APB1Periph_I2C2 or RCC_APB1Periph_CAN, Disabled);
RCC_ADCCLKConfig(RCC_PCLK2_Div8); //6 MHz
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div1); //48MHz
RCC_ClockSecuritySystemCmd(Enabled);
RCC_GetClocksFreq(RCC_Clocks);
//***************************************************
//******************** Systick **********************
Systick.LOAD:= 6000; // 1ms main loop
SysTick.CTRL := SysTick.CTRL or CTRL_TICKINT_Set AND (not 4);// interrupt, AHB/8
SysTick.CTRL := SysTick.CTRL or systick_counter_enable ; //enabled
contador:= cuenta_max - 2;
USB_Init;
while true do
begin
If marca then
begin
marca:= False;
Inc(Contador);
Inc(Contador_tick_Segundos);
If Contador_tick_segundos >= 10 then //1seg
begin
Contador_tick_segundos:= 0;
end;
if contador <= contador2 then LedC[13] := not LedC[13] else LedC[13] := true;
if contador >= cuenta_Max then
begin
contador := 0;
if subiendo then contador2 += 2 else contador2 -= 2;
if contador2 > Cuenta_max then subiendo:= false;
if contador2 = 0 then subiendo:= true;
end;
end;
end;
end.