GPIO Raspberry Type B with MainLine Kernel - module

I have compiled uboot and a mainline kernel downloaded from kernel.org to run on a Raspberry Type B Module. I have a problem using the GPIO Interface. I am writing a module to manage two I/O's one of them should generate irq. When I call gpio_to_irq() or any other gpio related kernel api, the call always fail (return code -517 or -22). The same code, running on the raspberry kernel downloaded from the github RPI repository works. The mainline kernel, however, support BCM2835 that is the Soc used on RPI. Where is my approch wrong ? How does the gpio_api calls fail ? If I manually find the GPIO number (Virq) and I requests it with request_irq() everything works fine even with the mainline kernel from kernel.org.
The mainline kernel version is 4.11 while the rpi kernel version from github is 4.9.26. Here is the init function of the module:
I apologize for this. I will try to be more in toych now. Linux version (mainline) is 4.11 while the rpi linux version is 4.9.26. This is the init function of the module:
static int __init hello_init(void)
{
int result;
int temp;
printk(KERN_INFO "Hello world!\n");
printk(KERN_INFO "%s\n",Version);
/* Registering device */
result = register_chrdev(memory_major, "Bisio", &memory_fops);
if (result < 0)
{
printk(KERN_INFO "Memory Driver: Cannot Obtain Major Number %d\n", memory_major);
return -1;
}
/* Allocating memory for the buffer */
memory_buffer = kmalloc(MEMSIZE, GFP_KERNEL);
if (!memory_buffer) {
return -ENOMEM;
}
memset(memory_buffer, 0, MEMSIZE);
result = gpio_request(23,"MyIO");
printk(KERN_INFO "gpio_request: %d\n",result);
result = gpio_direction_input(23);
printk(KERN_INFO "gpio_direction_input: %d\n",result);
result = gpio_to_irq(23);
printk(KERN_INFO "gpio_to_irq: %d\n",result);
return 0; // Non-zero return means that the module couldn't be loaded.
}
Doing a insmod for this module I get:
[ 109.792257] nothing: loading out-of-tree module taints kernel.
[ 109.820350] Hello world!
[ 109.829341] Driver Version 1.27 - 10/09/2015 - 10:20
[ 109.841344] gpio_request: -517
[ 109.850737] gpio_direction_input: 0
[ 109.860187] gpio_to_irq: -22
while, doing the same with the rpi kernel (compiled with the same gcc crosscompiler version (5.20 soft float) works correctly and here is the output of the same init function:
[ 47.927565] nothing: loading out-of-tree module taints kernel.
[ 47.939771] Hello world!
[ 47.942333] Driver Version 1.27 - 10/09/2015 - 10:20
[ 47.947411] gpio_request: 0
[ 47.952798] gpio_direction_input: 0
[ 47.956314] gpio_to_irq: 183
what I am missing ?
Any help will be appreciated.
Regards
Marco Bisio

Related

Running an C++ exetuable with embedded python

I am on Windows 10, having installed WinPython 64 3.8.5 and Mingw w64.
I want to call python code from C++ and started using the following example code:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
int main(int argc, char *argv[])
{
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(program);
return 0;
}
Compilation runs through smoothly (g++ myfile.cpp -Ipath/to/Python.h -Lpath/to/python38.lib -lpython38)
However, when running the exe in cmd (after running C:\Users\liebschs\Programs\WinPython64-3.8.5\WPy64-3850\scripts\env.batch in that cmd), I obtain the following error:
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'embed.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Users\\liebschs\\MyFiles\\playground\\VSprojects\\EmbedPython\\embed.exe'
sys.base_prefix = 'C:\\Users\\liebschs\\Programs\\WinPython64-3.8.5\\WPy64-3850\\python-3.8.5.amd64'
sys.base_exec_prefix = 'C:\\Users\\liebschs\\Programs\\WinPython64-3.8.5\\WPy64-3850\\python-3.8.5.amd64'
sys.executable = 'C:\\Users\\liebschs\\MyFiles\\playground\\VSprojects\\EmbedPython\\embed.exe'
sys.prefix = 'C:\\Users\\liebschs\\Programs\\WinPython64-3.8.5\\WPy64-3850\\python-3.8.5.amd64'
sys.exec_prefix = 'C:\\Users\\liebschs\\Programs\\WinPython64-3.8.5\\WPy64-3850\\python-3.8.5.amd64'
sys.path = [
'C:\\Users\\liebschs\\Programs\\WinPython64-3.8.5\\WPy64-3850\\python-3.8.5.amd64\\python38.zip',
'.\\DLLs',
'.\\lib',
'C:\\Users\\liebschs\\MyFiles\\playground\\VSprojects\\EmbedPython',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000021c8 (most recent call first):
<no Python frame>
Any help is appreciated!
Btw:
Running python scripts directly (i.e. doing "python helloworld.py" in cmd) or using pip does not cause an error and runs as expected.
switching to a virtual environment, does not change anything
Contrary to what I read elsewhere, the problem is resolved when I set PYTHONPATH and PYTHONHOME to the python.exe, in my case C:\Users\liebschs\Programs\WinPython64-3.8.5\WPy64-3850\python-3.8.5.amd64

USB CDC: STM32F103RBT6 Cant get USB Device to show up

I got an Olimexino-STM32 with an STM32F103RBT6. I used STM32 Workbench 2.6 on Windows 10 x64 and STMCubeXM 4.27.0.
I choosed in CubeMX
STM32F103RBT6
RCC HSE
USB
USB Device Communication Device Class
Debug Line: JTAG 4 pin
Fix clock speeds
Add LED1 on PA5 as GPIO Out
Add LED2 on PA1 as GPIO Out
Toolchain SW4STM
Stack size
In main.c in the while loop
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
HAL_Delay(500);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
HAL_Delay(500);
uint8_t HiMsg[] = "hello\r\n";
CDC_Transmit_FS(HiMsg, strlen(HiMsg));
}
/* USER CODE END 3 */
in usb_cdc_if.c
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
if (Buf[0]=='1')
{
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
}
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
/* USER CODE END 6 */
}
Generate, compile and flash to Board. I can see the LED blinking in the main loop. The speed seems also correct but i just cant get a device registered on windows. I can flash the board with an example hex file from the distributor with the bootloader active. There i can get the COM port registered. So i can see the USB Port is ok but somehow the generated code doesnt register the COM port.
Any Ideas?
https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32/
Here is the test1.ioc file
#MicroXplorer Configuration settings - do not modify
File.Version=6
KeepUserPlacement=false
Mcu.Family=STM32F1
Mcu.IP0=NVIC
Mcu.IP1=RCC
Mcu.IP2=SYS
Mcu.IP3=USB
Mcu.IP4=USB_DEVICE
Mcu.IPNb=5
Mcu.Name=STM32F103R(8-B)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PD0-OSC_IN
Mcu.Pin1=PD1-OSC_OUT
Mcu.Pin2=PA5
Mcu.Pin3=PA11
Mcu.Pin4=PA12
Mcu.Pin5=VP_SYS_VS_ND
Mcu.Pin6=VP_SYS_VS_Systick
Mcu.Pin7=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
Mcu.PinsNb=8
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F103RBTx
MxCube.Version=4.27.0
MxDb.Version=DB.4.0.270
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.USB_LP_CAN1_RX0_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false
PA11.Mode=Device
PA11.Signal=USB_DM
PA12.Mode=Device
PA12.Signal=USB_DP
PA5.GPIOParameters=GPIO_Label
PA5.GPIO_Label=LED1
PA5.Locked=true
PA5.Signal=GPIO_Output
PCC.Checker=false
PCC.Line=STM32F103
PCC.MCU=STM32F103R(8-B)Tx
PCC.PartNumber=STM32F103RBTx
PCC.Seq0=0
PCC.Series=STM32F1
PCC.Temperature=25
PCC.Vdd=3.3
PD0-OSC_IN.Mode=HSE-External-Oscillator
PD0-OSC_IN.Signal=RCC_OSC_IN
PD1-OSC_OUT.Mode=HSE-External-Oscillator
PD1-OSC_OUT.Signal=RCC_OSC_OUT
PinOutPanel.RotationAngle=0
RCC.ADCFreqValue=36000000
RCC.AHBFreq_Value=72000000
RCC.APB1CLKDivider=RCC_HCLK_DIV2
RCC.APB1Freq_Value=36000000
RCC.APB1TimFreq_Value=72000000
RCC.APB2Freq_Value=72000000
RCC.APB2TimFreq_Value=72000000
RCC.FCLKCortexFreq_Value=72000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=72000000
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,USBPrescaler,VCOOutput2Freq_Value
RCC.MCOFreq_Value=72000000
RCC.PLLCLKFreq_Value=72000000
RCC.PLLMCOFreq_Value=36000000
RCC.PLLMUL=RCC_PLL_MUL9
RCC.SYSCLKFreq_VALUE=72000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=72000000
RCC.USBFreq_Value=48000000
RCC.USBPrescaler=RCC_USBCLKSOURCE_PLL_DIV1_5
RCC.VCOOutput2Freq_Value=8000000
USB_DEVICE.CLASS_NAME_FS=CDC
USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS
USB_DEVICE.VirtualMode=Cdc
USB_DEVICE.VirtualModeFS=Cdc_FS
VP_SYS_VS_ND.Mode=No_Debug
VP_SYS_VS_ND.Signal=SYS_VS_ND
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
board=custom
Problem solved: The Olimexino-STM32 has an output to connect and disconnect the USB. I had not configured that output pin.

assembly logical shift left solidity don't work

function shift(int val) returns(int) {
int res;
assembly {
let m := mload(0x40)
mstore(m, shl(2, val))
mstore(0x40, add(m, 0x20))
res := mload(m)
}
return res;
}
Documentation
shl(x, y) //logical shift left y by x bits
Result always 0;
In testrPC it don't work at all.
Geth version: 1.8.10-stable
OS: ubuntu 16.04
Go version: 1.9.2
I receive this warning when I compile your code:
browser/Untitled3.sol:8:23: Warning: The "shl" instruction is only available for
Constantinople-compatible VMs. You are currently compiling for "byzantium", where it will
be interpreted as an invalid instruction.
mstore(m, shl(2, val))
^---------^
It looks like there's a plan to add this instruction in the Constantinople fork, which hasn't happened yet: https://github.com/ethereum/EIPs/issues/145. For now, no such opcode exists.

Minecraft Forge: My armor textures are not showing up on armor

The game works fine, it just won't load the textures.
package theDwainFilms19.SuperSmashBrosMod.item;
import scala.tools.nsc.MainClass;
import theDwainFilms19.SuperSmashBrosMod.SuperSmashBrosMod;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import com.sun.xml.internal.stream.Entity;
public class ItemmarioArmor extends ItemArmor {
public ItemmarioArmor(ArmorMaterial armourMaterial, int id, int placement){
super(armourMaterial, id, placement);
}
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
if (stack.getItem().itemID == SuperSmashBrosMod.marioHelmet.itemID ||stack.getItem().itemID == SuperSmashBrosMod.marioChestplate.itemID || stack.getItem ().itemID == SuperSmashBrosMod.marioBoots.itemID) {
return SuperSmashBrosMod.MODID + ":textures/models/armor/mario_layer_1.png";
}
if (stack.getItem().itemID == SuperSmashBrosMod.marioLeggings.itemID) {
return SuperSmashBrosMod.MODID + ":textures/models/armor/mario_layer_2.png";
} else {
return null;
I don't have a clue how to fix this, since it doesn't give a error thing, it just ignores the code.
Edit: here is a crash report for when I went to add a proxy
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_31, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 687494688 bytes (655 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed
FML{7.10.85.1291} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed
Forge{10.13.2.1291} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed
ssb{1.0} [Super Smash Bros mod] (bin) Unloaded->Errored
[22:56:55] [Client thread/INFO] [STDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:398]: ##!## Game crashed! Crash report saved to: ##!## C:\Users\David\Desktop\SuperSmashBrosMOd\eclipse.\crash-reports\crash-2015-02-07_22.56.55-client.txt
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

Modifying a Kernel Space Function in openSUSE-11.3

I have been working on a K-space USB driver for learning purposes.
As far as I have studied the Kernel Space Source files that are included during the time when the USB driver is performing its routines, I have found announce_devices() is the function which prints the information of the all USB devices connected over the bus.
I plugged in a USB device (a BeagleBoard-xM, in which I have set Product ID and Vendor ID and other descriptors and all of them are verified in User-Space using libusb code), started the computer. When I did a dmesg, I was expecting to see my device. But it didn't show up. Then I ran the libusb code that I have written, it shows the device.
Due to this, I assume that my device is being enumerated normally.
Question #1: If the libusb code is working perfectly alright, that must be going wrong with the module that I have inserted, right? The code is shared below. (This code is taken as an answer in Stack Overflow question Programmatically obtaining the vendor ID, product ID of a USB device on a Linux platform I had written back in January, and it worked fine then). So is my driver working fine? I have rebuild the kernel a number of times (for a number of dynamic modules) after implementing the above code.
Question #2: Can I modify the Kernel-Space function announce_devices() and rebuild the kernel on my machine and verify?
P.S.: Necessary inclusions have been made.
Having gone through almost all the necessary header files, I know that I should be (and I was last time around ) able to access the vendor ID, product ID, and manufacturer details of the USB device through a structure: struct usb_device{} which has a member struct usb_device_descriptor{}. This nested structure has idVendor, idProduct and iManufacturer and some other members.
//*******************************************
struct usb_device udev;
struct usb_bus *bus;
ssize_t ret;
static int __init usb_fun_init (void)
{
int result;
__le16 idVendor = 0;
__le16 idProduct = 0;
__u8 iManufacturer = 0;
__u8 iSerialNumber = 0;
printk(KERN_INFO "\n************************************ in init\n");
list_for_each_entry(bus, &usb_bus_list, bus_list)
{
printk(KERN_INFO "***************** Begins ****************");
printk(KERN_INFO "Vendor ID = %x", bus->root_hub->descriptor.idVendor);
printk(KERN_INFO "Product ID = %x", bus->root_hub->descriptor.idProduct);
printk(KERN_INFO "Serial Number = %x", bus->root_hub->descriptor.iSerialNumber);
//printk(KERN_INFO "Manu = %s", bus->root_hub->descriptor.iManufacturer);
printk(KERN_INFO "Manu = %s", bus->root_hub->manufacturer);
printk(KERN_INFO "Product = %s", bus->root_hub->product);
printk(KERN_INFO "Serial Number = %s", bus->root_hub->serial);
printk(KERN_INFO "\nManufacturer = %s", udev.bus.iManufacturer);
}
return 0;
}
static void __exit usb_fun_exit (void)
{
printk(KERN_INFO "\n************************************ in exit\n");
}
module_init(usb_fun_init);
module_exit(usb_fun_exit);
MODULE_LICENSE("GPL");